</> ConvertAtlas Developer Tools
Web

Content-Type Headers: Telling Browsers What You Sent

How MIME types in headers control whether a file renders, downloads or breaks, and the charset detail people miss.

200 301 404 500

When a server sends a response, the bytes alone do not say what they are — a chunk of data could be a web page, a JSON document, an image or a download. The Content-Type header is how the server tells the client how to interpret what it sent, and getting it wrong causes some of the most baffling bugs in web development.

200 301 404 500
The Content-Type header tells the client how to handle the bytes in the response.

What Content-Type does

Content-Type carries a MIME type — like text/html, application/json or image/png — that tells the browser how to handle the response. With text/html the browser renders a page; with application/json a script parses data; with the wrong type, things break in confusing ways. It is the label on the package, and the recipient acts on the label.

Common mistakes

  • Serving JSON as text/plain, so clients refuse to parse it as JSON.
  • Serving a JavaScript file with the wrong type, so the browser declines to execute it.
  • Missing the type entirely, leaving the browser to guess — sometimes wrongly, sometimes dangerously.
  • Forcing a download by setting the type when you meant to display, or vice versa.

The charset parameter

Content-Type can carry an extra parameter that people often overlook: the character set, as in text/html; charset=utf-8. This tells the browser how to decode the bytes into characters. Omit it or set it wrong, and accented letters and symbols turn into gibberish — the classic encoding bug. Declaring UTF-8 here, consistently with your HTML, prevents it.

Try it: MIME Type LookupLook up the MIME type for a file extension and vice versa.

Why it is also a security matter

Letting the browser guess the type can be exploited — a file uploaded as an image but sniffed as HTML could run a script. Setting the correct Content-Type and adding the X-Content-Type-Options: nosniff header tells browsers to trust your label and not guess, closing that hole.

The takeaway

The Content-Type header is a small thing with large consequences. Always send the correct MIME type, include the charset for text, and do not leave the browser guessing. Most "why won’t this render" mysteries trace back to it.