MIME type

Also known as: media type · content type

On this page 7

A MIME type is a standardized two-part identifier, written as type/subtype (for example image/png or application/json), that declares what kind of data a file, message body or network response contains. The label is also called a media type or content type, and it is a cornerstone of interoperability in software because it lets a sender and a receiver agree on how bytes should be interpreted without relying on file names.

The concept originated in the Multipurpose Internet Mail Extensions specifications for email and was later adopted by HTTP, web browsers, operating systems and APIs. Today the official list of media types is maintained by the IANA media type registry, and the syntax is defined in RFC 6838 and related specifications.

How a MIME type is structured

Every MIME type consists of a top-level type, a slash and a subtype, optionally followed by parameters separated by semicolons. The top-level type names a broad category, while the subtype names the specific format. A parameter refines the meaning, most commonly charset for text, as in text/plain; charset=utf-8.

Matching is case-insensitive for the type and subtype, so Text/HTML and text/html are equivalent, although lowercase is the convention. Subtypes may also carry a structured syntax suffix such as +json or +xml, which tells a generic parser that, for example, application/ld+json can be read as ordinary JSON even when the specific vocabulary is unknown.

The following table lists the registered top-level types and what each one covers.

Top-level typeWhat it coversTypical subtypes
textHuman-readable character dataplain, html, css, csv
imageStill or animated picturespng, jpeg, webp, svg+xml
audioSound datampeg, ogg, wav
videoMoving images, often with soundmp4, webm
applicationBinary data or data for a programjson, pdf, zip, octet-stream
fontFont fileswoff2, ttf, otf
multipartSeveral parts in one bodyform-data, mixed, alternative
modelThree-dimensional modelsgltf+json, obj
Registered top-level media types

Where MIME types are declared and read

A MIME type travels as metadata alongside the data, not inside it. In HTTP, the server sends it in the Content-Type header, and the client may state the types it prefers in the Accept header, which enables content negotiation. In email, each part of a multipart message carries its own Content-Type, so a single message can hold text, HTML and attachments.

Operating systems use MIME types as well. Desktop environments map file extensions and magic numbers (signature bytes at the start of a file) to media types and then to the application that opens them. Upload forms send multipart/form-data, and the HTML accept attribute filters which files a user may select.

The table below summarizes the main places where the label appears and who relies on it.

ContextField or mechanismConsumer
HTTP responseContent-Type headerBrowser, API client
HTTP requestAccept and Content-Type headersServer, API gateway
Email messageContent-Type per MIME partMail client
File managerExtension and magic-number databaseOperating system shell
Web page markuptype and accept attributesBrowser
Archive manifestDeclared entries such as EPUB mimetypeReader application
Common contexts that carry a media type

MIME types compared with extensions and content sniffing

A MIME type is an explicit declaration, whereas a file extension is only a naming convention and content sniffing is an inference from the bytes. Each method fails in different ways, so robust software usually combines them and treats the declared type as authoritative only when the source is trusted.

MethodStrengthWeakness
Declared MIME typeExplicit, works without a file nameCan be missing or misconfigured
File extensionSimple and visible to usersEasily renamed, varies by platform
Content sniffingInspects actual bytesAmbiguous formats, security risks
Three ways to identify a format

The distinction matters for neighboring concepts such as file format and character encoding. A MIME type names the container or syntax, while the charset parameter names the character encoding, so a correct type with a wrong charset still produces mojibake.

Choosing and configuring the right media type

The most specific registered type is the correct choice whenever one exists. Generic labels force receivers to guess, and guessing undermines both reliability and security. When no registered type fits, vendors may use the vnd. tree for proprietary formats or the x- prefix, which RFC 6838 now discourages for new types.

PayloadRecommended typeReason
JSON API responseapplication/jsonRegistered, UTF-8 by definition
Web pagetext/html; charset=utf-8Explicit encoding avoids misreading
JavaScript filetext/javascriptCurrent registered form
Unknown binary downloadapplication/octet-streamSignals raw bytes, triggers download
Scalable vector graphicimage/svg+xmlSuffix exposes XML syntax
Office documentRegistered vnd. typeLets systems pick the right editor
Recommended media types for common payloads

Web servers assign types through a mapping file or configuration directive, and object storage services usually set them at upload time. A useful practice is to verify response headers after every deployment, because a missing mapping silently falls back to a generic default.

Common mistakes and security pitfalls

Incorrect media types cause both functional failures and vulnerabilities. Browsers historically sniffed content to compensate for misconfigured servers, which allowed attackers to upload a file that looked harmless but was executed as script. The X-Content-Type-Options: nosniff header tells the browser to trust the declared type and refuse mismatched scripts and stylesheets.

  • Serving everything as text/plain breaks rendering of pages, stylesheets and scripts.
  • Trusting the uploaded Content-Type lets a client mislabel malicious files; validate on the server.
  • Omitting the charset parameter for text invites wrong decoding of non-ASCII characters.
  • Inventing unregistered types reduces interoperability with tools that rely on the registry.
  • Using application/octet-stream everywhere forces downloads where inline display was intended.

The short version

A MIME type is a label that says what is inside a piece of data. Think of a parcel with a sticker that reads “fragile glass” or “frozen food”. The sticker does not change the contents, but it tells the person receiving it how to handle the box.

When a website sends a picture, it attaches the label image/png, so the browser knows to draw an image instead of showing strange symbols. Without the right label, programs have to guess, and guesses are sometimes wrong or even unsafe.

Where it makes a difference

A development team moves a single-page web application from one hosting setup to a new storage bucket behind a content delivery network. After the switch, the page loads as a blank screen. The browser console reports that the main script was refused because its MIME type was text/plain and the server sends nosniff.

The cause is that the upload tool did not map the .js and .mjs extensions, so every file received a generic default. The team adds explicit mappings for text/javascript, text/css, image/svg+xml and application/wasm, re-uploads the assets and adds a deployment check that requests each file type and compares the Content-Type header with the expected value. The application renders correctly again, and future releases fail the pipeline instead of failing in front of users.