MIME Type Lookup
The MIME type for any file extension, and the extension for any type. Search either way. The types that servers most often get wrong carry a note explaining the mistake.
Text and web
text/html text/css text/javascript application/json application/ld+json application/xml text/csv text/plain text/markdown text/calendar text/vcard application/wasm Images
image/png image/jpeg image/webp image/avif image/gif image/svg+xml image/x-icon image/bmp image/tiff image/heic Fonts
font/woff2 font/woff font/ttf font/otf application/vnd.ms-fontobject Audio and video
video/mp4 video/webm video/quicktime audio/mpeg audio/mp4 audio/wav audio/ogg audio/flac text/vtt Documents
application/pdf application/msword application/vnd.openxmlformats-officedocument.wordprocessingml.document application/vnd.ms-excel application/vnd.openxmlformats-officedocument.spreadsheetml.sheet application/vnd.ms-powerpoint application/vnd.openxmlformats-officedocument.presentationml.presentation application/vnd.oasis.opendocument.text application/vnd.oasis.opendocument.spreadsheet application/rtf application/epub+zip Archives and binaries
application/zip application/gzip application/x-tar application/x-7z-compressed application/vnd.rar application/x-bzip2 application/octet-stream Form and API payloads
application/x-www-form-urlencoded multipart/form-data application/problem+json text/event-stream application/graphql-response+json 1 Why a wrong type breaks things
The browser decides what to do with a response from its
Content-Type header and ignores the file extension in the URL.
Serve a font as application/octet-stream and it
refuses to use it. Serve an SVG as text/plain and
you get the source code on screen instead of a picture. Serve a module with a non-JavaScript type such as text/plain
and strict MIME checking blocks it.
When something will not load, read the response headers before you change any code. A wrong Content-Type is a more common cause than broken markup.
2 Never trust the type on an upload
The Content-Type on an uploaded file is set by the client and
can say anything. A PHP script renamed to
.jpg and declared as image/jpeg is a
classic upload bypass, and checking the extension is no better.
Check the magic bytes at the start of the file on the server:
finfo_file in PHP, python-magic in
Python, file-type in Node. Then serve user uploads
from a separate domain with
X-Content-Type-Options: nosniff, so a browser cannot sniff them into a different, executable type.
3 Four details that cause wrong types
charset matters for text
text/html without charset=utf-8 makes the browser guess, and a guess of Latin-1 on UTF-8 content turns accented characters into mojibake (é shows as é).
The x- prefix is deprecated
RFC 6648 deprecated it in 2012. Some survivors are too entrenched to rename, application/x-www-form-urlencoded above all.
Fonts moved namespace
RFC 8081 gave fonts their own font/* tree. Old configs still say application/x-font-woff, which mostly works and is no longer correct.
octet-stream means download
Use it when the server does not know the type. For anything the browser should render, it makes the browser download the file instead.
Quick guide
Searching MIME Content-Type headers by extension
- 01 Type an extension, with or without the leading dot, to find its type.
- 02 Type a type such as image/ or font to see everything in that family.
- 03 Search by name too: spreadsheet, subtitle, archive.
- 04 Types that servers often get wrong carry a note explaining the mistake.
Server configs
Setting and checking Content-Type
nginx
nginx# Types come from mime.types; add the ones it misses
types {
application/wasm wasm;
image/avif avif;
}
# charset matters for text, or the browser guesses
charset utf-8;
charset_types text/css text/plain application/javascript application/json;
# Stop the browser second-guessing you, and stop it
# interpreting a user upload as something executable
add_header X-Content-Type-Options "nosniff" always; Detecting a real type on upload
php<?php
// NEVER trust $_FILES['x']['type']: it comes from the client
$declared = $_FILES['avatar']['type']; // attacker-controlled
// Read the magic bytes instead
$finfo = new finfo(FILEINFO_MIME_TYPE);
$actual = $finfo->file($_FILES['avatar']['tmp_name']);
$allowed = ['image/jpeg', 'image/png', 'image/webp'];
if (!in_array($actual, $allowed, true)) {
http_response_code(415);
exit('Unsupported file type');
}
// Then store it with an extension you chose, not one they sent,
// and serve it from a domain that cannot run scripts. Checking the extension is no better than checking the declared type. Both are supplied by whoever is uploading.
Python
pythonimport mimetypes
print(mimetypes.guess_type("report.xlsx")[0])
print(mimetypes.guess_extension("image/webp"))
# The stdlib table is incomplete and platform-dependent.
# For real detection, read the bytes:
# pip install python-magic
import magic
print(magic.from_buffer(open("unknown.bin", "rb").read(2048), mime=True)) Troubleshooting
Modules blocked by wrong MIME type and nosniff errors
- A web font will not load
- It is most likely being served as application/octet-stream, and browsers refuse a font with the wrong type. Add font/woff2 to your server's type table.
- A module script is blocked
- Strict MIME checking rejects anything but a JavaScript type. Serve it as text/javascript; application/javascript is deprecated but still accepted.
- An SVG shows as source code
- Served as text/plain or text/xml. It needs image/svg+xml to render.
- Accented characters render as mojibake
- No charset on a text type, so the browser guessed a different encoding. Add charset=utf-8.
- An uploaded file executed on the server
- The type was trusted. Check magic bytes, rename with your own extension, store outside the web root or on a separate domain, and send nosniff.
Header notes
Why charset=utf-8 belongs on text responses
MIME stands for Multipurpose Internet Mail Extensions: the scheme was designed in 1992 for email attachments and only later borrowed by HTTP. That is why IANA maintains the registry rather than a web standards body, and why some names, such as message/rfc822, come from email.
Registries
IANA Media Types and MDN MIME references
Q&A
MIME type questions
Why does my font or video not load?
Usually the server is sending the wrong Content-Type, or none. Browsers refuse a font served as application/octet-stream, and a video can fail to play with the wrong type. Check the response headers before you change anything else.
What is the correct type for a JavaScript module?
text/javascript. The WHATWG and RFC 9239 deprecated application/javascript in favor of it, the reverse of what many developers expect. Both work in browsers; only text/javascript is current.
Should I trust the type a browser sends on upload?
No. The Content-Type on an uploaded file comes from the client and can say anything. Check the magic bytes at the start of the file on the server, and never decide what to do with a file based on its extension or its claimed type.
What does charset=utf-8 do?
It tells the browser how to decode the bytes of a text type. Without it, the browser guesses, and a guess of Latin-1 on UTF-8 content renders accented characters as mojibake (é becomes é).
Why do some types start with x-?
The x- prefix once marked unregistered experimental types. RFC 6648 deprecated the convention in 2012, but plenty survive, like application/x-www-form-urlencoded, which is far too widely used to rename now.