W3docs

MIME-Types

The Multipurpose Internet Mail Extensions (MIME) type is a specification that extends the format of email to support sending images, audio/video files, archives, etc.

The Multipurpose Internet Mail Extensions, known as a MIME type, is a specification extending the format of email and used by browsers and servers to identify the type of content being transferred. The specification is standardized in IETF RFC 6838. A MIME type is an identifier string, not a file extension. Browsers generally use the MIME type (and not the file extension) to determine how to process a document; that’s why it is important to configure servers correctly to attach the proper MIME type to the response header. If it is not configured correctly, browsers may misinterpret the files' contents, and sites won't work correctly. Downloaded files may be mishandled as well.

Syntax

MIME Types

Type/Subtype

The structure of a MIME type consists of a type and subtype, separated by a slash (/), without spaces. MIME types are not case-sensitive, but they are commonly written in lower case.

A MIME type must always have both a type and subtype. Each type has its set of possible subtypes.

To provide additional details, you can use an optional parameter.

MIME Types

type/subtype;parameter=value

MIME types are divided into two categories: discrete and multipart. Each has specific subtypes.

Discrete Types

MIME Types

text/plain
text/html
image/jpeg
image/png
audio/mpeg
audio/ogg
audio/*
video/mp4
application/*
application/json
application/javascript
application/ecmascript
application/octet-stream

Discrete types indicate the category of the document. They can be one of the following:

TypeDescriptionExample of typical subtypes
applicationContains binary dataapplication/javascript, application/octet-stream, application/pkcs12, application/vnd.mspowerpoint, application/xhtml+xml, application/xml, application/pdf
audioAudio fileaudio/midi, audio/mpeg, audio/webm, audio/ogg, audio/wav
fontFont/typeface datafont/woff, font/ttf, and font/otf
modelModel data for 3D objectsmodel/3mf, model/vrml
textText documenttext/plain, text/html, text/css, text/javascript
videoVideo filevideo/webm, video/ogg

For describing a text document that doesn’t belong to a particular subtype, text/plain is used. Documents containing binary data without a specific subtype are described using application/octet-stream.

Multipart Types

MIME Types

multipart/form-data
multipart/byteranges

Multipart types indicate documents that consist of several parts, each of which can have a different MIME type.

TypeDescriptionExample of typical subtypes
messageMessage that covers other messagesmessage/rfc822, message/partial
multipartData composed of multiple componentsmultipart/form-data, multipart/byteranges

Common MIME Types

The following table lists widely used, modern MIME types. Many legacy types prefixed with x- (e.g., image/x-icon) are deprecated and should be avoided in new projects. For a complete, authoritative list, refer to the IANA Media Types registry.

File extensionMedia Type
.html, .htmtext/html
.csstext/css
.jsapplication/javascript
.jsonapplication/json
.pngimage/png
.jpg, .jpegimage/jpeg
.gifimage/gif
.svgimage/svg+xml
.mp3audio/mpeg
.mp4video/mp4
.pdfapplication/pdf
.zipapplication/zip

Setting Content-Type Headers

Servers must send the correct Content-Type header so browsers know how to handle the response. Below are quick examples for common environments:

Nginx

location /api/data {
    default_type application/json;
    add_header Content-Type application/json;
}

Apache (.htaccess)

AddType application/json .json
AddType text/css .css

Node.js (Express)

app.get('/api/status', (req, res) => {
    res.setHeader('Content-Type', 'application/json');
    res.send(JSON.stringify({ status: 'ok' }));
});

Practice

Practice

What are MIME types and what is their function?