MIME Types Cheat Sheet: Content-Type, Sniffing and Magic Bytes
Checked against MIME types MDN common types list and WHATWG MIME Sniffing standard (updated 19 Oct 2026); signatures checked on local files on 28 November 2026. Each section links to the official docs it was checked against.
This sheet is for developers who configure servers, handle uploads, or debug a browser that refuses to run a script. Types come from MDN's common types list and the IANA registry, and the sniffing rules from the WHATWG MIME Sniffing standard as updated on 19 Oct 2026. File signatures marked as tested were read from real files in our repository with a short Node script.
When to use what
Set Content-Type on every response you send, and set it to the specific type, not a generic one. Browsers treat text/plain as "show this as text", so a stylesheet served that way is ignored. For JavaScript, text/javascript is the type MDN and RFC 9239 point to; the older application/javascript still works but there is no reason to pick it for new config.
Use application/octet-stream only when you really do not know what the bytes are, or when you want the browser to download rather than display. Pair it with Content-Disposition: attachment if downloading is the point.
For uploads, never trust the extension or the Content-Type the browser sent. Check the first bytes of the file against the signatures below, then store it with the type you detected. Add X-Content-Type-Options: nosniff to every response so the browser does not second-guess you. Our MIME type lookup maps extensions to types, and the image format detector reads signatures from a file you drop in. The HTTP security headers guide shows nosniff alongside the other headers you want.
The full registry is at https://www.iana.org/assignments/media-types/media-types.xhtml.
.html text/htmlHTML documents; add ; charset=utf-8 on the header
.js .mjs text/javascriptClassic scripts and ES modules both use this type
.css text/cssStylesheets; browsers ignore CSS sent with any other type
.json application/jsonJSON API responses and data files
.svg image/svg+xmlSVG images; the +xml suffix says the body is XML
.png image/png .jpg image/jpeg .webp image/webp .avif image/avifRaster image types for the common web formats
.ico image/vnd.microsoft.iconType for .ico favicon files served from the site root
.woff2 font/woff2 .woff font/woffWeb fonts, under the top-level font type
.wasm application/wasmWebAssembly modules; streaming compile expects this exact type
.pdf application/pdf .zip application/zip .gz application/gzipDocuments and archives
Windows may upload .zip as application/x-zip-compressed.
.mp4 video/mp4 .webm video/webm .mp3 audio/mpegMedia files for video and audio elements
.csv text/csv .md text/markdown .xml application/xmlText data formats
.bin application/octet-streamUnknown binary data; browsers download it rather than display it
Types are case-insensitive and usually written in lowercase. Parameter values can be case-sensitive.
Content-Type: text/html; charset=utf-8Declare the body type and its text encoding on a response or request
Accept: application/jsonClient tells the server which response types it can handle
Content-Type: multipart/form-data; boundary=...Form upload body split into parts, each with its own headers
multipart/byterangesBody of a 206 Partial Content response carrying several ranges
Content-Disposition: attachment; filename="report.pdf"Ask the browser to save the response instead of showing it
curl -sI https://example.com/app.jsPrint response headers so you can check the Content-Type a server sends
Sniffing rules themselves are in the WHATWG standard at https://mimesniff.spec.whatwg.org/.
X-Content-Type-Options: nosniffTell the browser to trust the declared type and not guess from the bytes
nosniff + scriptBlocks a script response whose type is not a JavaScript MIME type
nosniff + styleBlocks a stylesheet response whose type is not text/css
text/plain + nosniffUploaded HTML served as plain text stays as text instead of rendering
Tested rows were read from files in our repo (favicon, PNG and GIF images, Next.js and Prisma fonts, the Prisma WASM engine) or made locally with zip and Node's zlib. JPEG, WebP, PDF, BMP and media rows are from the standard only.
89 50 4E 47 0D 0A 1A 0APNG: the eight-byte signature starting with .PNG
47 49 46 38 39 61GIF89a; GIF87a ends in 37 61 instead
FF D8 FFJPEG: the three bytes every JPEG file starts with
52 49 46 46 ?? ?? ?? ?? 57 45 42 50 56 50WebP: RIFF, four size bytes, then WEBPVP
00 00 01 00ICO icon file (00 00 02 00 is a cursor)
25 50 44 46 2DPDF: the text %PDF-
50 4B 03 04ZIP archive, and formats built on ZIP
1F 8B 08gzip stream using deflate
77 4F 46 32 / 77 4F 46 46WOFF2 (wOF2) and WOFF (wOFF) fonts
00 61 73 6DWebAssembly module: a null byte then asm
Read from a real .wasm file; the WHATWG tables do not list it.
1A 45 DF A3WebM/Matroska EBML header
49 44 33MP3 with an ID3 tag
Worked example: Read the first bytes of local files to confirm their type
Extensions lie, so this Node script walks a folder, takes the first 16 bytes of one file per extension and prints them as hex and as text:
import fs from 'node:fs';
function head(path) {
const b = Buffer.alloc(16);
const fd = fs.openSync(path, 'r');
fs.readSync(fd, b, 0, 16, 0);
fs.closeSync(fd);
return b.toString('hex').match(/../g).join(' ');
}
for (const f of process.argv.slice(2)) console.log(f, head(f));
Run against files in our repo, it printed:
apple-touch-icon.png 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52
favicon.ico 00 00 01 00 01 00 10 10 00 00 01 00 20 00 28 04
x-anim-...-27.gif 47 49 46 38 39 61 b0 04 a3 02 83 00 00 83 5b ee
geist-latin-ext.woff2 77 4f 46 32 00 01 00 00 00 00 3b bc 00 13 00 00
query_engine_bg.wasm 00 61 73 6d 01 00 00 00 01 f0 06 76 60 02 7f 7f
Each file starts with the signature from the table above. The WASM signature is not in the WHATWG tables, which only cover types a browser sniffs, but the bytes are just as useful for an upload check. An upload handler can do the same check on the first bytes before saving, and reject a file whose bytes do not match the type it claims.
Common mistakes
Serving JavaScript or CSS as
text/plainorapplication/octet-streamfrom object storage.Set the correct type when you upload the object, or in the bucket or CDN config. With nosniff on, the browser blocks the file otherwise.
Trusting the
Content-Typesent with a multipart upload.The client controls that value. Detect the type from the file's first bytes and store your own value.
Leaving out
charseton HTML or plain text responses.MDN says text types default to US-ASCII without it. Send
charset=utf-8so accented characters and emoji display correctly.Putting
charsetin a script tag'stypeattribute.In HTML the
typeattribute cannot carry parameters. Set the charset in the HTTP header instead.Assuming a ZIP signature means the upload is a plain .zip.
Many document and package formats are ZIP containers. Open the archive and check its contents before trusting it.
Related cheat sheets
Sources
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Content-Type-Options
- https://mimesniff.spec.whatwg.org/
- https://www.iana.org/assignments/media-types/media-types.xhtml
How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.