MIME types

Convert MIME types to file extensions and vice-versa.

loading MIME types
About this tool

What is a MIME type?

A MIME type (also called media type or content type) is a short label of the form type/subtype that says what kind of data a file or a response contains: text/html, image/png, application/pdf, audio/mpeg. Programs do not guess from the file name; they trust this label. A browser decides whether to render a page, play a video or offer a download from the Content-Type header of the response, and a server decides whether an upload is acceptable from the type the client announces.

The label looks small, but wrong ones cause real problems. A stylesheet served as text/plain is ignored by the browser, a JSON API that answers text/html breaks clients that check the header, a module script served with the wrong type fails to load, and an upload form that accepts only image/jpeg rejects a perfectly good .jpg if the system reports something else. The list of official types lives in the IANA media type registry, and the rules for the header are in the HTTP specification (RFC 9110).

This tool answers the two questions that come up every week: which extensions belong to a MIME type, and which MIME type belongs to an extension. It also has a searchable table of the whole list. The data is embedded in the page, generated from the mime-db package, so nothing you type is sent anywhere.

How to find the MIME type of a file extension

  1. For extension to type, use the second card, File extension to MIME type. Open the selector, type part of the extension (for example webp) and pick it. The MIME type appears below with a button to copy it.
  2. For type to extensions, use the first card, MIME type to extension. Search for the type in the selector, such as image/jpeg. All the extensions that map to it appear as tags, and one button copies them as a list (.jpeg, .jpg, .jpe).
  3. To browse instead of guess, use the filter above the table. It looks in both the types and the extensions, and ignores a leading dot, so .zip and zip give the same list. The row that matches exactly comes first, then those that start with your text, then those that contain it.
  4. The table shows 100 rows at a time. The counter under it says how many are shown out of the total, and Show 100 more loads the next batch.
  5. If nothing matches, the table says so with the text you typed, so you can spot a typo.

The lookup uses the extension only. It does not open or inspect your file, so a file named photo.jpg that is really a PNG still gets image/jpeg here. To check what a file really contains, use file --mime-type on the command line.

Examples

The usual web files

ExtensionMIME type
.jsonapplication/json
.svgimage/svg+xml
.webpimage/webp
.woff2font/woff2
.csvtext/csv
.wasmapplication/wasm

These are the values to put in the Content-Type header, in the type attribute of a <source> or <link> tag, and in the accept attribute of an upload field.

One type, several extensions

Searching image/jpeg returns .jpeg, .jpg and .jpe. They are the same format. In the other direction, all three extensions return image/jpeg. The same goes for text/html, which covers .html, .htm and .shtml.

Office documents have long types

.docx maps to application/vnd.openxmlformats-officedocument.wordprocessingml.document and .xlsx to application/vnd.openxmlformats-officedocument.spreadsheetml.sheet. This is why an upload filter written as application/msword rejects modern Word files: that is the type of the old .doc. Copy the long values with the button instead of typing them.

Surprises you will find in the list

  • .js returns text/javascript, the type the current standard, RFC 9239, prefers. Older tables and some servers still say application/javascript; browsers accept both.
  • .ts returns video/mp2t, because that extension was a video transport stream long before TypeScript existed. A TypeScript source file served by a static server may be mislabelled as video.
  • .wav returns audio/wave, while some systems report audio/x-wav or audio/wav.

Common problems and how to fix them

  • The browser downloads a file instead of showing it: the server sent a generic type such as application/octet-stream, or the header Content-Disposition: attachment. Send the right Content-Type for the file.
  • A stylesheet or script is blocked with a MIME type error: the server answered with text/html (often a 404 page) or text/plain. Fix the path first, then check the type of the file the server really sends.
  • An upload is rejected with 415: the API did not accept the type of the body, such as text/plain where it expected application/json. Look up the exact value here and see the meaning in HTTP status codes.
  • No MIME type matches the text: the filter says nothing matches. Try a shorter piece of the name or search by the kind of type, such as video.
  • A custom extension is not in the list: private formats have no registered type. Use application/octet-stream, or a vendor type that starts with application/vnd..
  • A type you know is missing: the list comes from a fixed version of mime-db, so very recent or rarely used types may not be there.

Frequently asked questions

What is the MIME type for a file extension?

Pick the extension in the second card and the type appears below it. For example, .pdf is application/pdf and .png is image/png.

What is the difference between a MIME type, a media type and Content-Type?

They name the same thing. "Media type" is the official name, "MIME type" is the traditional one (from email) and Content-Type is the HTTP header that carries it, sometimes with a parameter such as ; charset=utf-8.

Can a file have two MIME types?

A file has one real format, but systems may disagree on its label (audio/wav and audio/x-wav), and a type can have several extensions. When you build a filter, accept every label the browsers and your users' systems may send. For data URLs that embed the type, see Base64 and image to Base64.

Is the MIME type enough to trust an upload?

No. The type comes from the client, which can lie. Check the file's first bytes on the server and limit the size and the extensions you accept.

Doing it in code

JavaScript (Node)

import mime from 'mime-types';

console.log(mime.lookup('report.pdf'));     // application/pdf
console.log(mime.extension('application/pdf')); // pdf
console.log(mime.contentType('json'));      // application/json; charset=utf-8

Python

import mimetypes

print(mimetypes.guess_type('report.pdf'))        # ('application/pdf', None)
print(mimetypes.guess_extension('application/pdf'))  # .pdf

Go

package main

import (
	"fmt"
	"mime"
)

func main() {
	fmt.Println(mime.TypeByExtension(".pdf")) // application/pdf
}

Bash

file --mime-type -b report.pdf   # application/pdf, read from the content
Report a problem