Cheat Sheets Web & HTTP

MIME Types Cheat Sheet

The MIME types for web pages, data, images, audio, video, fonts and archives, with the rules that cause wrong-type bugs and how to check uploads.

Last reviewed:

AdSense Placeholder
Slot: header_reference_page
On this page

A MIME type (or media type) names the format of a piece of content in the form type/subtype, such as image/png. Web servers send it in the Content-Type header so the browser knows whether to render a page, play a video or offer a download. Look up any extension with the MIME Type Lookup.

Common types

Type Extensions Used for
text/html .html .htm Web pages
text/css .css Stylesheets
text/javascript .js .mjs JavaScript (the current standard type)
application/json .json JSON data and API responses
application/xml .xml XML documents
text/plain .txt Plain text
text/csv .csv Comma-separated tables
text/markdown .md Markdown text
application/pdf .pdf PDF documents
application/zip .zip ZIP archives
application/gzip .gz Gzip-compressed data
application/wasm .wasm WebAssembly modules (must be served with this type to stream-compile)
image/png .png PNG images
image/jpeg .jpg .jpeg JPEG photos
image/gif .gif GIF images and animations
image/webp .webp WebP images
image/svg+xml .svg SVG vector graphics
audio/mpeg .mp3 MP3 audio
audio/wav .wav WAV audio
video/mp4 .mp4 MP4 video
video/webm .webm WebM video
font/woff2 .woff2 Web fonts (WOFF2)

Rules worth remembering

  • Unknown binary data is application/octet-stream. Browsers usually offer to download it instead of opening it.
  • Form submissions use application/x-www-form-urlencoded by default and multipart/form-data when a file is attached.
  • Text types often carry a charset, as in text/html; charset=utf-8. Always send UTF-8 for text (UTF-8).
  • Structured types end in +json or +xml when they are specialised versions of those formats, such as image/svg+xml or application/ld+json.
  • Vendor and experimental types start with vnd. (for example application/vnd.ms-excel) or x-.

Common problems

  • A page shows as plain text. The server sent text/plain instead of text/html.
  • A script or module will not run. Browsers refuse JavaScript modules and strict-MIME scripts served with a wrong type such as text/html or application/octet-stream.
  • A font or WebAssembly file fails to load. Servers that do not know .woff2 or .wasm may send a generic type.
  • Type sniffing. Browsers sometimes guess a type from the content. Send X-Content-Type-Options: nosniff so they trust your Content-Type instead.

Checking uploads

Never trust an uploaded file's extension or the Content-Type the client sent: both are chosen by the sender. Check the file's first bytes against its expected signature instead (see How File Signatures (Magic Bytes) Work), and serve uploads from a separate domain with nosniff.

Try these tools

See also

  • Glossary MIME type
    A MIME type (media type) names the format of content as type/subtype, such as text/html or image/png, so software knows how to handle it.
  • Glossary UTF-8
    UTF-8 is the dominant Unicode encoding, writing each character as one to four bytes and staying identical to ASCII for the first 128.
  • Guide How File Signatures (Magic Bytes) Work
    How the first bytes of a file identify its real type, a table of common signatures verified against real files.
  • Cheat sheet HTTP Headers Cheat Sheet
    Request and response headers, Cache-Control directives, security headers, cookie attributes and CORS headers.
AdSense Placeholder
Slot: footer_leaderboard