How a MIME type is written
type "/" subtype [ "+" suffix ] [ ";" parameter "=" value ] application/json text/html; charset=utf-8 application/problem+json multipart/form-data; boundary=----x7Tq2
The type is the broad family and the subtype the exact format. Names
are not case-sensitive and are conventionally written in lower case. A parameter after
a semicolon adds detail: charset on text types, and the required boundary on
multipart bodies.
| Top-level type | Holds |
|---|---|
application | Structured or binary data meant for a program |
text | Data a person could read as characters |
image, audio, video, font | Media and typefaces |
multipart | Several parts, each with its own type, in one body |
message, model | Wrapped messages and 3D models; rare in API work |
MIME types for API requests and responses
| MIME type | Used for |
|---|---|
application/json | JSON bodies. The default for web APIs. |
application/x-www-form-urlencoded | HTML form fields as a=1&b=2. Also OAuth token requests. |
multipart/form-data | Forms that include file uploads. |
application/xml | XML meant for programs. |
text/xml | XML; the type SOAP 1.1 uses. |
application/soap+xml | SOAP 1.2 envelopes. See SOAP vs REST. |
application/problem+json | Standard error bodies defined by RFC 9457. |
application/ld+json | JSON-LD linked data, including schema.org markup. |
application/merge-patch+json | A JSON Merge Patch body for PATCH. See PUT vs PATCH. |
application/json-patch+json | A JSON Patch list of operations for PATCH. |
application/jwt | A JSON Web Token sent as a body. |
application/yaml | YAML documents, registered by RFC 9512. |
text/event-stream | Server-sent events: a response that stays open and streams. |
application/x-ndjson | Newline-delimited JSON streams. Widely used, not formally registered. |
application/octet-stream | Arbitrary bytes of no declared format; the fallback for unknown files. |
Text, documents and archives
| MIME type | Typical extension | Used for |
|---|---|---|
text/plain | .txt | Unformatted text |
text/html | .html | Web pages |
text/css | .css | Stylesheets |
text/javascript | .js, .mjs | JavaScript. The registered type; application/javascript is obsolete. |
text/csv | .csv | Comma-separated tables |
text/markdown | .md | Markdown |
application/pdf | PDF documents | |
application/zip | .zip | ZIP archives |
application/gzip | .gz | Gzip-compressed files |
application/wasm | .wasm | WebAssembly modules |
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet | .xlsx | Excel workbooks |
application/vnd.openxmlformats-officedocument.wordprocessingml.document | .docx | Word documents |
Images, audio, video and fonts
| MIME type | Typical extension |
|---|---|
image/png | .png |
image/jpeg | .jpg, .jpeg |
image/gif | .gif |
image/webp | .webp |
image/avif | .avif |
image/svg+xml | .svg |
image/x-icon | .ico (in common use; the registered name is image/vnd.microsoft.icon) |
audio/mpeg | .mp3 |
audio/wav | .wav |
audio/ogg | .ogg, .oga |
video/mp4 | .mp4 |
video/webm | .webm |
font/woff2 | .woff2 |
font/woff | .woff |
font/ttf | .ttf |
Reading a type you have not seen before
Structured suffixes: +json and +xml
A suffix says which general syntax a specialised format is built on.
application/problem+json is a specific kind of error document, and it is also JSON, so a
client that does not know the specific type can still parse it as JSON. image/svg+xml is an
image that happens to be XML. When you meet an unfamiliar type ending in +json, treat the
body as JSON and read the provider's documentation for what the fields mean.
Vendor types: vnd.
A subtype beginning vnd. belongs to a particular company or product. APIs use them for
versioning: GitHub's API, for example, accepts Accept: application/vnd.github+json. The
long Office types in the table above are vendor types too.
The x- prefix
Subtypes starting with x- were never registered. The convention is discouraged for new
types, but several old ones are permanent fixtures:
application/x-www-form-urlencoded is among the most used media types on the web.
charset
The charset parameter matters on text/* types, where leaving it off invites
the receiver to guess and turn accented characters into nonsense. application/json defines
no charset parameter, because JSON between systems is always UTF-8. Adding
; charset=utf-8 to it is common and harmless.
Where MIME types appear in HTTP
| Header | Sent by | Says |
|---|---|---|
Content-Type | Whoever sends a body | “This body is in this format.” |
Accept | The client | “These are the formats I can read, in order of preference.” |
Two status codes exist only for mismatches between them. A server that cannot read the format you sent
answers 415 Unsupported Media Type. A server that cannot produce
any format your Accept header lists answers
406 Not Acceptable. The
Content-Type header guide goes through both headers in detail,
and the curl Content-Type example shows how to set them on a command
line.
Sniffing, and how to stop it
When a response has a missing or implausible Content-Type, browsers may inspect the bytes
and decide the format themselves. That is how a file uploaded as a harmless image can end up executed
as a script. Servers prevent it by sending the correct type along with
X-Content-Type-Options: nosniff, which tells the browser to believe the header. If you
serve files that users uploaded, send both, and serve anything you cannot identify as
application/octet-stream so it downloads instead of rendering.
A file extension is a hint for people and operating systems; over HTTP only the header counts. A JSON
response served as text/html will be treated as HTML however its URL ends. To see what a
server really sends, request the URL in the API tester and read the
content-type response header, or use a curl HEAD request.
References
- IANA: Media Types registry — The authoritative list of every registered type.
- RFC 6838: Media Type Specifications and Registration — The naming rules: trees, vendor prefixes and structured suffixes.
- MDN: MIME types — How browsers use media types, including sniffing.
- MDN: Common media types — A longer table of types by file extension.
These links leave api-tester.com, which is independent of the organisations they point to.
Frequently asked questions
What is a MIME type?
A label that identifies the format of some data, written as a type and a subtype separated by a slash, such as text/html or application/json. HTTP sends it in the Content-Type header so the receiver knows how to interpret the body.
What does MIME stand for?
Multipurpose Internet Mail Extensions. The labels were invented to describe email attachments and were later adopted by HTTP. The current official name is media type, and the two terms mean the same thing.
What is the MIME type for JSON?
application/json. Specialised JSON formats add a suffix, as in application/problem+json for error details and application/ld+json for linked data.
What is application/octet-stream?
The generic type for binary data of no declared format. Servers use it when they cannot identify a file, and browsers respond by offering to download the content instead of displaying it.
Is a MIME type the same as a file extension?
No. An extension is part of a file name and is only a hint. The MIME type is metadata sent alongside the data, and over HTTP it is the Content-Type header, not the extension in the URL, that decides how the body is handled.
What is the difference between Content-Type and Accept?
Content-Type describes the format of the body in the message that carries it. Accept is sent by a client to list the formats it is willing to receive in the response.