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/SubtypeThe 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=valueMIME 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:
| Type | Description | Example of typical subtypes |
|---|---|---|
| application | Contains binary data | application/javascript, application/octet-stream, application/pkcs12, application/vnd.mspowerpoint, application/xhtml+xml, application/xml, application/pdf |
| audio | Audio file | audio/midi, audio/mpeg, audio/webm, audio/ogg, audio/wav |
| font | Font/typeface data | font/woff, font/ttf, and font/otf |
| model | Model data for 3D objects | model/3mf, model/vrml |
| text | Text document | text/plain, text/html, text/css, text/javascript |
| video | Video file | video/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/byterangesMultipart types indicate documents that consist of several parts, each of which can have a different MIME type.
| Type | Description | Example of typical subtypes |
|---|---|---|
| message | Message that covers other messages | message/rfc822, message/partial |
| multipart | Data composed of multiple components | multipart/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 extension | Media Type |
|---|---|
.html, .htm | text/html |
.css | text/css |
.js | application/javascript |
.json | application/json |
.png | image/png |
.jpg, .jpeg | image/jpeg |
.gif | image/gif |
.svg | image/svg+xml |
.mp3 | audio/mpeg |
.mp4 | video/mp4 |
.pdf | application/pdf |
.zip | application/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 .cssNode.js (Express)
app.get('/api/status', (req, res) => {
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({ status: 'ok' }));
});Practice
What are MIME types and what is their function?