MIME first.contentType says the document kind (text/html).
Encoding second.characterSet says how bytes became text (UTF-8).
Do not mix them. A page can be text/html with many encodings.
Learn more. See the characterSet tutorial for encoding details.
Compatibility
Browser Support
Document.contentType is Baseline Widely available on MDN (since April 2018). It works across modern browsers for reading the rendered document MIME type.
✓ Baseline · Widely available
Document.contentType
Read-only MIME type string for the document currently being rendered — typically text/html.
99%Browser support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
Android WebViewSupported · Modern WebView
Full support
contentTypeExcellent
Bottom line: Safe for modern web apps. Remember: configure MIME types with HTTP headers on the server — <meta> tags do not update this property.
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.