INTERNET FUNDAMENTALSAI-REVIEWED

What does the HTTP Content-Type header mean?

Useful first: HTTP · optional, not a requirement

Choose your depth

Stay with the essentials, or look closer.

Simple explanation
2 min read · estimate

YOUR GOALExplain what Content-Type describes and why neither a filename nor a new label converts the body.

Separate the format label from the content.

A format comes with a way to interpret it

In HTTP, Content-Type tells the recipient what kind of representation the sender is providing. For example, text/html identifies HTML and image/png identifies a PNG image. The label helps the recipient choose how to handle the content.

[3] [6]

The filename is not the HTTP declaration

A URL ending in .png is not a substitute for a correct response header. For a resource retrieved over HTTP, the browser obtains its supplied MIME type from Content-Type, not the filename extension. Check the actual response when a resource is handled unexpectedly.

[2] [6]

Changing the label does not rewrite the bytes

Imagine sending the text Trail open but labeling it image/png. That header does not manufacture an image. The sender must provide content appropriate for the declared format. A wrong label can change processing or cause a failure; it is not a conversion tool.

[3] [6]
THE IDEA TO KEEP

Keep the declared type and the actual content consistent.

ONE THING TO WATCH OUT FOR

Renaming a resource to .png makes its HTTP response a PNG image.

The URL suffix does not supply the browser's HTTP MIME type, and renaming does not create image data.

A QUICK CHECK, NOT A TEST
A server keeps sending the same plain-text bytes but changes Content-Type to image/png. What has changed?
Show the explanation

The declaration has changed; the bytes still need to be valid for the declared format. A type label describes how content is intended to be handled. Replacing it does not encode an image or make the unchanged body valid PNG data.

Progress is saved only in this browser.

KEEP EXPLORINGHTTP content negotiation
Was this explanation clear?
Report a mistake by email
Basic explanation
2 min read · estimate

YOUR GOALParse a Content-Type value, recognize equivalent charset spellings, and avoid duplicate declarations.

Read the type, parameters, and declaration together.

Split the main type from its parameters

Consider this header fragment for an HTML response:

Content-Type: text/html; charset=utf-8

text is the type, html the subtype, and charset=utf-8 a parameter describing the character encoding. The slash joins the type and subtype; the semicolon introduces a parameter. Character encoding is a separate concept from HTTP compression.

[6] [3]

Case and quotation rules are specific

These two values describe the same HTML type and UTF-8 charset:

text/html; charset=utf-8
TEXT/HTML; CHARSET="UTF-8"

Type, subtype, and parameter names are case-insensitive. Charset names are too, so the capitalization and permitted quotation above do not change the declaration. Do not generalize that rule to every parameter value: its own definition determines whether case matters.

[1] [3]

Send one declaration, not a list of alternatives

Content-Type is a singleton field. Sending it twice or combining types as text/html, text/plain is not a way to offer alternatives. Recovery from malformed declarations can differ between recipients. Send one accurate value; preferences belong to content negotiation.

[1] [5]
THE IDEA TO KEEP

Read one type/subtype declaration, then interpret each parameter according to its definition.

ONE THING TO WATCH OUT FOR

Every part of a media type can always be lowercased without changing its meaning.

Type and subtype ignore case, but a parameter value can be case-sensitive. Charset names have their own case-insensitive rule.

A QUICK CHECK, NOT A TEST
Which header declares one HTML representation using UTF-8?
Show the explanation

Content-Type: text/html; charset=UTF-8 The first has a type/subtype and a charset parameter. The second incorrectly lists alternatives; the third omits the required type/subtype.

Progress is saved only in this browser.

KEEP EXPLORINGHTTP content negotiation
Was this explanation clear?
Report a mistake by email
Advanced explanation
3 min read · estimate

YOUR GOALDistinguish supplied and computed MIME types and apply nosniff without mistaking it for content validation.

Reason about the browser's loading context.

Supplied and computed types answer different questions

The supplied MIME type comes from resource metadata. The computed type is the result of the browser's type-handling algorithm. In some contexts, those rules inspect content bytes and can reach a different result. This is MIME sniffing, not proof that the sender's declaration was accurate. Do not depend on guessing to repair a misconfigured header.

[2] [6]

A stylesheet has a concrete MIME check

Consider a stylesheet request, whose destination is style, receiving these response headers:

Content-Type: text/plain
X-Content-Type-Options: nosniff

The nosniff check blocks this response even if its body contains valid CSS. For an actual stylesheet, send text/css. Script-like destinations instead require a JavaScript MIME type. A missing type also fails these checks. Passing this check does not guarantee that every other loading requirement is satisfied.

[5] [4]

Plain-text navigation is a different context

Suppose a navigation receives Content-Type: text/plain; charset=utf-8 and X-Content-Type-Options: nosniff, with body text <p>Trail open</p>. The browser treats it as plain text rather than interpreting that markup as HTML. Thus nosniff is not limited to the stylesheet example.

It also is not a content validator: the header does not prove the body harmless. Policies such as CSP remain separate checks.

[4] [2] [5]
THE IDEA TO KEEP

Match the header to the real format, then consider the request destination and the other policies independently.

ONE THING TO WATCH OUT FOR

If nosniff allows a response, its contents have been validated and are safe.

MIME handling and destination checks do not establish that a body is valid, harmless, or allowed by other policies.

A QUICK CHECK, NOT A TEST
A valid CSS body is blocked as a stylesheet because it was served with text/plain and nosniff. Which change addresses this MIME error?
Show the explanation

Send text/css for that CSS body; this resolves the illustrated type mismatch. For a style destination, the nosniff check requires text/css. Correcting that declaration addresses this check; it does not promise that other policies or content requirements will pass.

Progress is saved only in this browser.

KEEP EXPLORINGHTTP content negotiation
Was this explanation clear?
Report a mistake by email
GO STRAIGHT TO THE SOURCE

Keep asking. Check the details.

Source-checked using AI (OpenAI Codex) on . The checks covered sources, examples, and quizzes for this article version.

No human review is claimed. AI review can miss errors; check the original sources below.

  1. RFC 9110 — Content-Type, media types, and parameter rules
  2. WHATWG MIME Sniffing — Supplied and computed MIME types
  3. MDN — Content-Type header and character encoding
  4. MDN — X-Content-Type-Options and context-specific nosniff behavior
  5. WHATWG Fetch — MIME extraction and nosniff request blocking
  6. MDN — Media types, format labels, and correct server configuration
How explanations are prepared