Skip to content

Menu

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/html

HTML documents; add ; charset=utf-8 on the header

.js .mjs text/javascript

Classic scripts and ES modules both use this type

.css text/css

Stylesheets; browsers ignore CSS sent with any other type

.json application/json

JSON API responses and data files

.svg image/svg+xml

SVG images; the +xml suffix says the body is XML

.png image/png .jpg image/jpeg .webp image/webp .avif image/avif

Raster image types for the common web formats

.ico image/vnd.microsoft.icon

Type for .ico favicon files served from the site root

.woff2 font/woff2 .woff font/woff

Web fonts, under the top-level font type

.wasm application/wasm

WebAssembly modules; streaming compile expects this exact type

.pdf application/pdf .zip application/zip .gz application/gzip

Documents and archives

Windows may upload .zip as application/x-zip-compressed.

.mp4 video/mp4 .webm video/webm .mp3 audio/mpeg

Media files for video and audio elements

.csv text/csv .md text/markdown .xml application/xml

Text data formats

.bin application/octet-stream

Unknown 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-8

Declare the body type and its text encoding on a response or request

Accept: application/json

Client 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/byteranges

Body 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

From the docs, not run by us
curl -sI https://example.com/app.js

Print response headers so you can check the Content-Type a server sends

Try it: HTTP Header ParserFrom the docs, not run by us

Sniffing rules themselves are in the WHATWG standard at https://mimesniff.spec.whatwg.org/.

X-Content-Type-Options: nosniff

Tell the browser to trust the declared type and not guess from the bytes

nosniff + script

Blocks a script response whose type is not a JavaScript MIME type

nosniff + style

Blocks a stylesheet response whose type is not text/css

text/plain + nosniff

Uploaded 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 0A

PNG: the eight-byte signature starting with .PNG

47 49 46 38 39 61

GIF89a; GIF87a ends in 37 61 instead

FF D8 FF

JPEG: the three bytes every JPEG file starts with

Try it: image-format-detectorFrom the docs, not run by us
52 49 46 46 ?? ?? ?? ?? 57 45 42 50 56 50

WebP: RIFF, four size bytes, then WEBPVP

Try it: image-format-detectorFrom the docs, not run by us
00 00 01 00

ICO icon file (00 00 02 00 is a cursor)

25 50 44 46 2D

PDF: the text %PDF-

From the docs, not run by us
50 4B 03 04

ZIP archive, and formats built on ZIP

1F 8B 08

gzip stream using deflate

77 4F 46 32 / 77 4F 46 46

WOFF2 (wOF2) and WOFF (wOFF) fonts

00 61 73 6D

WebAssembly module: a null byte then asm

Read from a real .wasm file; the WHATWG tables do not list it.

1A 45 DF A3

WebM/Matroska EBML header

From the docs, not run by us
49 44 33

MP3 with an ID3 tag

From the docs, not run by us

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/plain or application/octet-stream from 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-Type sent 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 charset on HTML or plain text responses.

    MDN says text types default to US-ASCII without it. Send charset=utf-8 so accented characters and emoji display correctly.

  • Putting charset in a script tag's type attribute.

    In HTML the type attribute 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.