Content-Type header
The Content-Type header specifies the MIME type of the response, ensuring browsers handle content correctly.
22% of the 101 most-visited sites we scan fail this check. See the full data.
Results in 1–3 minutes · Free · No signup required
Want the result for your own site? Free Security Headers Checker — paste your domain, get the report.
Why It Matters
Incorrect or missing Content-Type can lead to MIME confusion attacks where browsers misinterpret content. This is especially important for JSON APIs and file downloads.
How We Check
We verify that responses include appropriate Content-Type headers with correct MIME types and charset specifications.
Good vs Bad Values
| Value | Verdict | Why |
|---|---|---|
text/html; charset=utf-8 | Good | The standard for HTML pages. The encoding is declared by the server, so the browser has no reason to guess. |
text/html;charset=UTF-8 | Good | Same meaning; spacing and case in the charset name do not matter. |
application/json | Good | JSON is defined as UTF-8, so no charset parameter is required. Adding `; charset=utf-8` is harmless. |
text/css; charset=utf-8 | Good | Correct for stylesheets, and compatible with `X-Content-Type-Options: nosniff`. |
text/javascript; charset=utf-8 | Good | The current standard type for scripts. `application/javascript` is also accepted by browsers. |
text/html | Bad | No charset on an HTML response. Browsers fall back to sniffing the encoding, and legacy encodings such as UTF-7 have been used to smuggle script past filters. |
text/html; charset=iso-8859-1 | Weak | Declared, so it passes, but legacy encoding mangles non-Latin text and is rarely intended. Move the site to UTF-8. |
text/plain for an HTML page | Weak | The page shows source text instead of rendering. Usually a misconfigured proxy or a missing extension mapping. |
application/octet-stream for scripts or images | Bad | A generic type forces browsers to guess, and with nosniff enabled the resource is blocked outright. |
Header missing | Bad | The browser has to guess the type from content, which opens the door to MIME confusion. |
How to Fix
Ensure all responses include Content-Type. For HTML: Content-Type: text/html; charset=utf-8. For JSON: Content-Type: application/json.
Nginx — make sure mime.types is included and set a charset for text types:
include mime.types;
default_type application/octet-stream;
charset utf-8;
charset_types text/html text/css text/plain text/xml application/javascript application/json;
Apache:
AddDefaultCharset UTF-8
AddType application/javascript .js .mjs
AddType application/manifest+json .webmanifest
AddType application/wasm .wasm
Express: res.type("html").send(html) and res.json(obj) set the correct header; for static files use express.static, which looks up the type from the file extension. Next.js sets it for pages and route handlers; for a custom Route Handler return Response.json(data) or add { headers: { "Content-Type": "text/html; charset=utf-8" } } to a manual Response.
Cloudflare: the edge passes the origin's Content-Type through, so fix the origin. If you must override it, use a Transform Rule, not a Worker that rewrites bodies.
Verify with curl -sI https://example.com | grep -i content-type for the page, a CSS file, a script, an image and a JSON endpoint. Each should show a specific type, and the HTML response should include charset=utf-8.
Common Mistakes
- Relying only on `<meta charset="utf-8">`. It works as a fallback but only if it appears within the first 1024 bytes, and the server header takes priority anyway; set both.
- Sending JSON as `text/html` from an API route. An error message containing user input can then render as HTML and execute script.
- Serving user-uploaded SVG, HTML or XML with a content type taken from the uploader. Decide the type on the server, and serve untrusted files from a separate origin.
- Forgetting the type on error pages, redirects with bodies and reverse-proxy responses; they are generated by a different component than your normal pages.
- Configuring `default_type text/html` in Nginx, so every unmapped extension (`.mjs`, `.wasm`, `.webmanifest`) is returned as HTML.
- Using different charsets in the header and the document. The header wins, and the page shows garbled characters.
Frequently Asked Questions
What is Content-Type header?
The Content-Type header specifies the MIME type of the response, ensuring browsers handle content correctly.
Why does Content-Type header matter for website security?
Incorrect or missing Content-Type can lead to MIME confusion attacks where browsers misinterpret content. This is especially important for JSON APIs and file downloads.
How do I fix Content-Type header issues?
Ensure all responses include Content-Type. For HTML: Content-Type: text/html; charset=utf-8. For JSON: Content-Type: application/json.
Related Security Checks
Related Tool
Security Headers Checker
Run all 10 related checks with our free security headers checker
Check Your Website Now
Run a free security scan to check for Content-Type header issues and 61 other security checks.
Scan Your Website Free