Pular para o conteúdo

MIME Types Reference

A reference of MIME (media) types for file formats. Useful for web server configuration, Content-Type headers, and upload validation.

What is a MIME type?

MIME (Multipurpose Internet Mail Extensions) types are a standard mechanism for identifying file format and nature. Written as type/subtype, they tell browsers and servers how to process a file. Used in HTTP Content-Type headers, HTML <input type="file" accept="..."> attributes, and elsewhere.

type/subtype text/* image/* audio/* video/* application/* text/plain text/html text/css text/csv image/jpeg image/png image/webp image/svg+xml audio/mpeg audio/wav audio/ogg video/mp4 video/webm video/quicktime application/pdf application/json application/zip application/octet-stream
Figura: Estrutura hierárquica de tipos MIME (top-level type → subtype)

Image (image/*)

ExtensionMIME typeDescription
.jpg / .jpegimage/jpegJPEG — lossy compression, ideal for photos
.pngimage/pngPNG — lossless with alpha transparency
.gifimage/gifGIF — animation support, 256 colors
.webpimage/webpWebP — Google's high-compression format
.avifimage/avifAVIF — next-gen format based on AV1
.svgimage/svg+xmlSVG vector graphics, XML-based
.icoimage/x-iconIcon file, used for favicons
.bmpimage/bmpBitmap, uncompressed
.tiff / .tifimage/tiffTIFF, common in print/DTP

Documents (application/*)

ExtensionMIME typeDescription
.pdfapplication/pdfPDF document
.docapplication/mswordMicrosoft Word (legacy)
.docxapplication/vnd.openxmlformats-officedocument.wordprocessingml.documentMicrosoft Word (OOXML)
.xlsapplication/vnd.ms-excelMicrosoft Excel (legacy)
.xlsxapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheetMicrosoft Excel (OOXML)
.pptapplication/vnd.ms-powerpointMicrosoft PowerPoint (legacy)
.pptxapplication/vnd.openxmlformats-officedocument.presentationml.presentationMicrosoft PowerPoint (OOXML)

Text (text/*)

ExtensionMIME typeDescription
.txttext/plainPlain text
.html / .htmtext/htmlHTML document
.csstext/cssCSS stylesheet
.csvtext/csvComma-separated values
.xmltext/xmlXML document
.jstext/javascriptJavaScript (application/javascript also valid)
.jsonapplication/jsonJSON data
.mdtext/markdownMarkdown text

Audio (audio/*)

ExtensionMIME typeDescription
.mp3audio/mpegMP3 — most common audio format
.wavaudio/wavWAV — uncompressed PCM
.oggaudio/oggOgg Vorbis
.flacaudio/flacFLAC — lossless compression
.aacaudio/aacAAC — successor to MP3
.webmaudio/webmWebM audio
.m4aaudio/mp4MPEG-4 audio

Video (video/*)

ExtensionMIME typeDescription
.mp4video/mp4MP4 — most common video format
.webmvideo/webmWebM — open format for the web
.avivideo/x-msvideoAVI
.movvideo/quicktimeQuickTime
.mkvvideo/x-matroskaMatroska container
.mpegvideo/mpegMPEG video

Archives & Compression (application/*)

ExtensionMIME typeDescription
.zipapplication/zipZIP archive
.gz / .gzipapplication/gzipGzip-compressed file
.tarapplication/x-tartar archive
.tar.gzapplication/gziptar+gzip archive
.rarapplication/vnd.rarRAR archive
.7zapplication/x-7z-compressed7-Zip archive
.bz2application/x-bzip2Bzip2 file

Fonts (font/*)

ExtensionMIME typeDescription
.wofffont/woffWeb Open Font Format
.woff2font/woff2WOFF2 — better compression
.ttffont/ttfTrueType font
.otffont/otfOpenType font

Other

ExtensionMIME typeDescription
(unknown)application/octet-streamGeneric binary data; default for unknown formats
.wasmapplication/wasmWebAssembly binary

Using MIME types in development

Server-side configuration

Web servers (Apache / Nginx) map file extensions to MIME types. If misconfigured, browsers may fail to handle the file correctly — for example, a .webp file with the wrong MIME type may be downloaded instead of displayed inline.

Upload validation

When implementing file uploads, validate both extension and MIME type. Be aware that MIME types can be spoofed by the client, so combine them with magic-byte (file signature) validation for security.

Content-Type header

Set an appropriate Content-Type header on API responses and downloads. Use application/json for JSON, text/csv for CSV, and add a charset parameter (text/html; charset=utf-8) when needed.

Setting MIME types in server configs

Below are the configuration snippets you reach for 90% of the time when serving modern formats (WebP, AVIF, WASM, font files) that may not be in your server's default mapping.

Apache .htaccess

# Modern image formats
AddType image/webp .webp
AddType image/avif .avif
AddType image/svg+xml .svg .svgz

# Fonts (so the browser caches them aggressively)
AddType font/woff  .woff
AddType font/woff2 .woff2

# WebAssembly & modern JSON variants
AddType application/wasm        .wasm
AddType application/manifest+json .webmanifest
AddType application/ld+json     .jsonld

# Force UTF-8 for text formats
AddCharset utf-8 .html .css .js .json .xml

Nginx (mime.types overrides)

types {
    image/webp                webp;
    image/avif                avif;
    application/wasm          wasm;
    application/manifest+json webmanifest;
}

# Force charset for text/* and application/json
charset utf-8;
charset_types text/css text/plain text/xml application/javascript application/json application/xml;

PHP — sending Content-Type

// Serve a download with the right Content-Type and a filename
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="invoice.pdf"');
readfile($path);

// JSON API response (always include charset)
header('Content-Type: application/json; charset=utf-8');
echo json_encode($data, JSON_UNESCAPED_UNICODE);

Node.js / Express

// Express infers Content-Type from res.type() or the file extension
app.get('/data.json', (req, res) => {
    res.type('application/json').send({ ok: true });
});

// Streaming a file with explicit MIME
app.get('/report.csv', (req, res) => {
    res.set('Content-Type', 'text/csv; charset=utf-8');
    fs.createReadStream('report.csv').pipe(res);
});

Python — Flask / FastAPI

# Flask
from flask import Response
return Response(csv_text, mimetype='text/csv', headers={'Content-Disposition': 'attachment; filename="data.csv"'})

# FastAPI
from fastapi.responses import Response
return Response(content=json_str, media_type='application/json')

Go — net/http

w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Header().Set("X-Content-Type-Options", "nosniff")  // security: see below
json.NewEncoder(w).Encode(data)

Security: why X-Content-Type-Options: nosniff matters

Browsers historically "sniffed" file contents to guess the type when the Content-Type header was missing or wrong. This is a known attack vector — a user uploading a file labeled image/jpeg that actually contains <script> could trigger XSS if the browser sniffs it as HTML.

Always send X-Content-Type-Options: nosniff on every response. It tells the browser "trust the Content-Type I sent; do not guess." This is especially critical for user-uploaded content and JSON APIs (where a hostile attacker could try to coerce JSON into being interpreted as HTML or JS).

Upload validation — the 3-layer rule

  1. Extension check — fast, but easily bypassed by renaming files. Use as a UX hint only.
  2. Client-sent MIME type (the Content-Type in the multipart boundary) — equally easy to spoof; the browser sets it based on the file's extension.
  3. Magic bytes (file signature) detection — reads the first few bytes of the actual file content and compares against known signatures (e.g., FF D8 FF for JPEG, 89 50 4E 47 for PNG). This is the only reliable layer. See the Magic Bytes reference for the full table.

Production rule of thumb: do all three. Treat the first two as quick filters that reject obvious garbage; treat the third as the authoritative check.

Frequently asked questions

What is the difference between application/json and text/json?

application/json is the IANA-registered, standards-compliant MIME type defined in RFC 8259. text/json was an early ad-hoc usage that some servers still emit but it is not registered and should be avoided. JSON is encoded in UTF-8 by definition, so a charset parameter is technically redundant but harmless and commonly added for clarity.

Why does my .webp or .avif file download instead of displaying inline?

Your server has no mapping for that extension and is falling back to application/octet-stream, which the browser treats as "unknown binary, download it." Add the mapping (image/webp / image/avif) to your server config — see the Apache / Nginx snippets above.

Is the MIME type sent by the browser trustworthy for upload validation?

No. The browser sets it based on the file's extension at the time of selection — anyone can rename malware.exe to cute-cat.jpg and the browser will dutifully label it image/jpeg. Always combine extension + client-sent MIME + magic-byte detection (see the 3-layer rule above).

What MIME type should I use for files my server doesn't recognise?

application/octet-stream — explicitly defined as "arbitrary binary data" and the safe default. Browsers will offer to download such files rather than trying to render them, which prevents accidental code execution.

Why does application/x-www-form-urlencoded have an x- prefix?

Historically the x- prefix denoted "experimental" or "non-standard" MIME types. RFC 6648 (2012) deprecated the convention but many widely-deployed types — including this one and application/x-www-form-urlencoded, image/x-icon, application/x-tar — kept the prefix for backward compatibility.

Should I include charset for binary types like images or PDFs?

No. charset only makes sense for text-based types (text/*, application/json, application/xml). Adding it to image/jpeg or application/pdf is meaningless and some intermediaries (CDNs, proxies) may strip it.