Behind the link

What is a MIME type?

Definition

A MIME type is the label that says what kind of data a file is, such as application/pdf or image/png. Browsers use it to decide how to open a file, but it is easy to fake, so careful hosts do not trust it alone.

Also called: Media type, Content type, Content-Type header, MIME

What does a MIME type look like?

A MIME type has two parts joined by a slash: a broad type and a specific subtype. In image/png, the type is image and the subtype is png. The common broad types are text, image, audio, video and application, which covers most other files, such as PDFs and ZIP archives.

MIME stands for Multipurpose Internet Mail Extensions. It began as the way email labels its attachments, which travel as Base64 text, and the web adopted it. A server sends it in a Content-Type header, sometimes with extra detail, such as text/html; charset=utf-8. The official list is kept by IANA, the body that manages internet numbers and names.

How do browsers use MIME types?

Browsers use the MIME type to decide what to do with a file before reading it. A file sent as application/pdf opens in the PDF viewer, video/mp4 plays in a video player, and application/octet-stream, the generic label for unknown binary data, is usually downloaded.

A wrong label causes odd results. A PDF sent as plain text shows up as a wall of symbols. A file sent as text/html runs any scripts inside it, which is why careful hosts never let an upload pick that label by itself. Many also send a header called X-Content-Type-Options: nosniff, which tells the browser to stick to the label instead of guessing.

Why can't a host trust the MIME type?

A host can't trust the MIME type because the sender chooses it. When you upload a file, your browser usually guesses the type from the file name, and a script can send any label it likes. Rename setup.exe to setup.pdf and most browsers will report application/pdf, though nothing inside the file changed.

So a careful host treats the label as a claim and checks it against the file itself. It reads the magic bytes at the start of the file, which reveal the real format, and refuses the upload if the label and the contents disagree.

What is the difference between a MIME type and a file extension?

A file extension is the end of the file name, such as .pdf, while the MIME type is a label sent alongside the file. Your computer uses the extension to pick an app, and the web uses the MIME type. One extension can map to several types and the other way round, and both are labels that can be wrong.

Common MIME types and what a browser does with them
FileMIME typeWhat a browser usually does
PDF (.pdf)application/pdfOpens it in a PDF viewer
PNG image (.png)image/pngShows the image
MP4 video (.mp4)video/mp4Plays it in a video player
ZIP archive (.zip)application/zipDownloads it
Web page (.html)text/htmlRenders it and runs its scripts

MIME type: common questions

What MIME type should I use for an unknown file?

Use application/octet-stream, the generic label for binary data. Browsers then offer to download the file instead of trying to open it.

Is a MIME type the same as a content type?

Nearly. Content-Type is the name of the header that carries the MIME type, so people use both names for the same thing. The official name today is media type.

Why does my file download instead of opening in the browser?

Usually the server sent a generic or wrong MIME type, or told the browser to save the file as an attachment. Some formats, such as ZIP archives, can't be shown at all.

Can a MIME type contain a virus?

No, it is only a label. The risk is a label that lies about the file, which is why hosts check the contents too.

What is the MIME type of a Word document?

A .docx file is application/vnd.openxmlformats-officedocument.wordprocessingml.document. Inside, it is a ZIP archive of XML files, so it starts with the same bytes as a ZIP.

Go deeper

Updated

Share a file as a link in seconds

Upload any file and get one clean link, with every setting on this page.

Try Link in Seconds

Optional cookies for analytics, ads and session replay.