Document.contentType is a read-only instance property that returns the MIME type the document is being rendered as (often text/html). Learn where that value comes from, how it differs from characterSet, why <meta http-equiv> does not change it, and five examples with try-it labs.
01
Kind
Read-only
02
Returns
MIME string
03
Typical
text/html
04
Source
HTTP / MIME
05
vs
characterSet
06
Status
Baseline widely
Fundamentals
Introduction
Every web resource has a MIME type that tells the browser what kind of content it is: HTML, XML, SVG, PDF, and so on. For a normal web page, that type is usually text/html.
document.contentType exposes the MIME type the browser is using to render the current document. MDN notes that the value may come from HTTP headers or other MIME sources, and that browser or extension conversions can affect it.
💡
Not controlled by meta tags
MDN: contentType is unaffected by <meta> elements. A <meta http-equiv="Content-Type"> tag will not change this property—set the real HTTP Content-Type header instead.
Even with a Content-Type meta tag, contentType stays from MIME sources.
JavaScript
// HTML may include:
// <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
const meta = document.querySelector('meta[http-equiv="Content-Type" i]');
console.log("meta present:", !!meta);
console.log("document.contentType:", document.contentType);
// MDN: contentType is unaffected by <meta> elements
Document.contentType is marked Baseline Widely available on MDN (since April 2018). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
Document.contentType
Read-only MIME type string for the rendered document — usually text/html on websites.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerNot available in legacy IE
No support
Document.contentTypeExcellent
Bottom line: Use document.contentType to read the document MIME type. Configure Content-Type on the server — meta tags do not change this property.
Wrap Up
Conclusion
Document.contentType is the standard read-only way to learn which MIME type the browser is using to render the document. On everyday sites that is almost always text/html. Set media types with HTTP headers—not meta tags or JavaScript assignment.
Serve HTML with Content-Type: text/html; charset=utf-8
Use contentType to detect HTML vs XML/SVG hosts
Log MIME type beside characterSet in diagnostics
Prefer <meta charset="utf-8"> for encoding declarations
Verify server headers when a page is mis-parsed
❌ Don’t
Try to assign document.contentType
Expect <meta http-equiv="Content-Type"> to change it
Confuse MIME type with character encoding
Assume every document is text/html without checking
Use contentType as a substitute for feature detection
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about document.contentType
Read-only MIME type — usually text/html on websites.
5
Core concepts
📄01
Returns
MIME string
API
✓02
Status
baseline
Standard
🔒03
Access
read-only
DOM
⚠️04
Meta
no effect
MDN
🌐05
vs
characterSet
Encoding
❓ Frequently Asked Questions
A read-only string with the MIME type the document is being rendered as — for example text/html for a normal HTML page, or application/xml / image/svg+xml for other document types.
No. MDN marks Document.contentType as Baseline Widely available (since April 2018). It is a standard read-only Document property.
MDN: it may come from HTTP headers or other MIME sources, and can be affected by automatic type conversions from the browser or extensions.
No. MDN notes that Document.contentType is unaffected by <meta> elements, including http-equiv content-type declarations.
contentType is the document MIME type (what kind of document). characterSet is the character encoding label (how bytes map to text), such as UTF-8.
No. It is read-only. Set the correct Content-Type HTTP header (or serve the correct file type) on the server instead.
Did you know?
Opening an .svg file directly in the browser often creates a document whose contentType is image/svg+xml instead of text/html. That is one reason scripts written only for HTML pages can behave differently inside SVG documents.