Development

MIME Type Lookup

Search and lookup MIME types for file extensions. Quick reference for web developers.

Advertisement

What Are MIME Types and Why They Matter

A MIME type (Multipurpose Internet Mail Extensions type, now officially called a media type) is a standardized string that identifies the format of a piece of content. Examples include text/html for web pages, application/json for JSON data, image/png for PNG images, and application/pdf for PDF documents. MIME types are defined in RFC 6838 and registered with IANA, the organization that maintains the official registry of media types.

MIME types matter because they tell browsers and other clients how to interpret the bytes they receive. Without a correct MIME type, a browser might display a PNG image as garbled text, refuse to execute a JavaScript file, or fail to render a stylesheet. The Content-Type header in HTTP responses carries the MIME type, and browsers rely on it (with some safeguards) to choose the correct handler for each resource.

MIME types also affect security. Browsers implement MIME type checking to prevent certain attacks — for example, they may refuse to execute a file as JavaScript if its MIME type does not match a whitelist of executable script types. The X-Content-Type-Options: nosniff header strengthens this behavior by telling the browser not to guess the MIME type if the declared type seems wrong, which prevents certain classes of content injection attacks.

  • Standardized strings identifying content format (text/html, application/json)
  • Defined in RFC 6838, registered with IANA
  • Carried in the HTTP Content-Type header
  • Tell browsers how to interpret received bytes
  • Affect security through MIME type checking and nosniff

MIME Type Structure and Syntax

A MIME type consists of two parts separated by a slash: a type and a subtype. The type is a broad category (text, image, audio, video, application), and the subtype identifies the specific format within that category. For example, in image/png, image is the type and png is the subtype. Together they uniquely identify the PNG image format.

MIME types can also carry optional parameters after a semicolon. The most common parameter is charset, used with text types to specify the character encoding. For example, text/html; charset=utf-8 declares HTML content encoded in UTF-8. Other parameters include boundary for multipart content, q for quality factors in Accept headers, and codec information for audio and video types.

Subtypes can have a structured suffix after a plus sign to indicate an underlying format. For example, application/ld+json indicates Linked Data structured as JSON, and application/vnd.api+json indicates a JSON:API document. This convention allows new formats to build on existing ones while signaling their specific semantics to clients that understand the suffix.

  • Format: type/subtype (e.g., image/png, application/json)
  • Optional parameters after semicolon (charset=utf-8)
  • Structured suffixes with plus sign (ld+json, vnd.api+json)
  • Common types: text, image, audio, video, application
  • Vendor subtypes use the vnd. prefix (application/vnd.ms-excel)

Common MIME Types for Web Development

Web developers encounter a relatively small set of MIME types daily. For HTML content, text/html is universal. For stylesheets, text/css. For JavaScript, application/javascript (historically text/javascript, which is still widely accepted). For JSON, application/json is the standard, though some older APIs use text/json. For XML, application/xml is preferred, with text/xml accepted for backward compatibility.

Images have distinct MIME types for each format: image/jpeg for JPEG, image/png for PNG, image/gif for GIF, image/webp for WebP, image/svg+xml for SVG, and image/avif for AVIF. Modern formats like WebP and AVIF offer better compression but require browser support, so serving them with the correct MIME type and providing fallbacks is important for cross-browser compatibility.

For binary downloads, application/octet-stream is the generic fallback that triggers download behavior in browsers. For file uploads, multipart/form-data is used to encode form fields and files together. For fonts, formats include font/woff, font/woff2, font/ttf, and font/otf. For documents, application/pdf is universal, while office formats use longer vendor-specific types like application/vnd.openxmlformats-officedocument.wordprocessingml.document for .docx files.

  • text/html, text/css, application/javascript — core web types
  • application/json — universal for modern APIs
  • image/jpeg, image/png, image/webp, image/svg+xml — common images
  • application/octet-stream — generic binary download
  • multipart/form-data — file uploads
  • font/woff2 — modern web fonts

How Browsers Determine the MIME Type

Browsers use several mechanisms to determine a resource's MIME type. The most authoritative source is the Content-Type header sent by the server in the HTTP response. When this header is present and correct, the browser uses it directly. This is why configuring your web server to send accurate Content-Type headers for every resource is important.

If the Content-Type header is missing or the browser suspects it is wrong, the browser may perform MIME sniffing — examining the first bytes of the response to guess the actual format. MIME sniffing was historically useful but has security implications: an attacker who uploads a malicious file could trick the browser into executing it as a different type. Modern browsers now limit sniffing in many contexts, and the X-Content-Type-Options: nosniff header disables it entirely for a given resource.

For file uploads from the user's filesystem, browsers use the file extension and may also examine the file's magic bytes (the first few bytes that identify the format). The File API exposes a type property on File objects containing the guessed MIME type, but this value is not always reliable — it can be empty or incorrect for unusual file types. Always validate uploaded files server-side using a library that inspects the actual content rather than trusting the client-provided type.

  • Content-Type HTTP header is the authoritative source
  • MIME sniffing guesses the type from content bytes
  • X-Content-Type-Options: nosniff disables sniffing for security
  • File API exposes a type property, but it may be unreliable
  • Always validate uploaded files server-side by inspecting content

Configuring MIME Types on Your Server

Most web servers ship with sensible default MIME type mappings, but you may need to add or override entries for specific file types. In Nginx, the types directive in the http or server block maps file extensions to MIME types, and the default_type directive sets the fallback for unknown extensions. In Apache, the AddType directive and the mime.types configuration file serve the same purpose.

Common configuration tasks include adding MIME types for newer formats like WebP (image/webp), AVIF (image/avif), and WOFF2 (font/woff2) if your server's defaults are outdated. You should also set the correct type for JavaScript modules (text/javascript or application/javascript both work), JSON files served statically (application/json), and manifest files for web apps (application/manifest+json for Web App Manifest).

For security, set X-Content-Type-Options: nosniff on all responses to prevent MIME sniffing attacks. For user-uploaded content served from your domain, consider serving it from a separate origin (like a CDN with a different domain) to prevent same-origin script execution. If you must serve user uploads from your main domain, force download with Content-Disposition: attachment and use application/octet-stream to prevent inline rendering.

  • Nginx: types directive and default_type for fallback
  • Apache: AddType directive and mime.types file
  • Add types for newer formats (webp, avif, woff2) if outdated
  • Set X-Content-Type-Options: nosniff on all responses
  • Serve user uploads from a separate origin when possible

MIME Types in API Design

In API design, MIME types are central to content negotiation. The Accept header in a request tells the server which content types the client can handle, and the server responds with the best match indicated in the Content-Type header. For REST APIs, application/json is the de facto standard, but content negotiation allows the same endpoint to serve different representations — HTML for browsers, JSON for API clients, XML for legacy systems.

Versioning via MIME types is a powerful pattern. Instead of putting the version in the URL (like /api/v1/users), you use a custom MIME type like application/vnd.myapi.v1+json. The client sends this type in the Accept header, and the server responds with the corresponding version. This keeps URLs stable across versions and allows fine-grained versioning of individual resources.

For error responses, use application/problem+json as defined in RFC 7807 (Problem Details for HTTP APIs). This standardized format provides a consistent structure for error details — including type, title, status, detail, and instance fields — that API clients can parse generically. Using a standard error format across all your endpoints makes your API more consistent and easier to integrate with.

When designing custom MIME types for your API, use the vnd. prefix (vendor) and register them in your documentation. Document each type's semantics, the schema of its payload, and whether it is versioned. Well-designed MIME types make your API self-describing and enable clients to handle different content types cleanly without parsing URLs or response bodies to determine the format.

  • Content negotiation via Accept and Content-Type headers
  • application/json is the de facto standard for REST APIs
  • Versioning via vnd. prefix (application/vnd.myapi.v1+json)
  • RFC 7807 problem+json for standardized error responses
  • Document custom types, their schemas, and versioning strategy