MIME Types

Search a reference table of common file extensions and their IANA MIME types, filtered by top-level category, to set the right Content-Type header every time.

Which Content-Type header does this file need? Type an extension such as .webp or part of a media type such as image to filter the table. Every entry follows the IANA media type registry and the MDN common types list.

Matches
Extension MIME type

What a MIME type tells the browser

Anatomy of a media type

A MIME type - properly called a media type - is the label a server attaches to a response so the client knows how to handle the bytes that follow. It has two parts separated by a slash: a top-level type such as text, image, audio, video, font, model or application, and a subtype that names the specific format. image/png and application/json are both complete media types; image alone is not.

Subtypes carry conventions of their own. A leading x- once marked an experimental type, as in application/x-tar, and although the practice is deprecated the surviving names are too widely deployed to change. A trailing +suffix says the format is built on a more general syntax: image/svg+xml is XML, application/ld+json is JSON, and a parser can fall back to the base syntax when it does not recognise the specific format.

Some types accept parameters after a semicolon. The most important is charset, as in text/html; charset=utf-8. Omitting it on a text response invites the browser to guess the encoding, which is a classic source of mojibake, so declaring UTF-8 explicitly is always worth the extra characters.

Why the header matters more than the extension

Browsers decide what to do with a response based on the Content-Type header, not the file name in the URL. Serving a PNG as text/plain shows a wall of binary garbage; serving JSON as text/html may cause a fetch client to reject it. Getting the header right is what makes a download open in the correct application and an inline asset render instead of downloading.

The mismatch has security consequences too. Older browsers practised MIME sniffing, inspecting the first bytes of a response and overriding a header they judged wrong. An attacker who could upload a file that looked like HTML could get it executed in the site's origin even when the server labelled it as an image. The X-Content-Type-Options: nosniff header disables that behaviour and is now standard practice on any endpoint that serves user-uploaded content.

For downloads, pair the media type with Content-Disposition: attachment; filename="report.pdf". The media type describes what the bytes are, the disposition describes what the browser should do with them, and the two answer different questions.

Where the mapping actually lives

There is no single authoritative extension-to-type table, which surprises people. IANA registers media types themselves, but the mapping from a file extension to a type is a local convention maintained by each server. Apache reads mime.types, nginx has its own mime.types file, and application frameworks ship their own lookup tables. That is why the same .wasm file can be served correctly by one server and as application/octet-stream by another that has not been updated.

application/octet-stream is the generic fallback meaning "arbitrary binary data". It is the honest answer when the format is genuinely unknown, but it defeats inline rendering, so it is worth adding an explicit mapping for any format your site serves regularly. Newer formats such as AVIF, JXL and WebAssembly are the ones most often missing from an older server configuration.

Open-source note: implemented in vanilla JavaScript with no third-party libraries.

FAQ

Why is my file downloading instead of displaying?
Either the media type is `application/octet-stream` or the response carries `Content-Disposition: attachment`. Set the correct type and drop the attachment disposition to render inline.
What is the MIME type for JSON?
`application/json`. Older code sometimes used `text/json` or `application/x-json`, but neither is registered and some clients reject them.
Should JavaScript be text/javascript or application/javascript?
`text/javascript` is the currently recommended form. Both work in every browser, but the HTML specification settled on the text variant and lists the application form as obsolete.
Do I need to include charset?
For textual types, yes. Without it the browser guesses, which produces mojibake for non-ASCII content. Send `text/html; charset=utf-8` or the equivalent for your type.
What does the +xml or +json suffix mean?
That the format is built on a more general syntax. A client that does not know `application/ld+json` specifically can still parse it as JSON, which makes generic tooling possible.
Why does my server send the wrong type for .webp or .avif?
The extension is missing from that server's `mime.types` file. Add an explicit mapping in the server configuration; the file itself is fine and needs no change.