What is MIME Type?

Understanding how computers identify and handle different file types

Simple Answer
A MIME type (Multipurpose Internet Mail Extensions) is a standardized label that identifies what kind of data a file contains. It uses the format "type/subtype" like image/jpeg, text/html, or application/pdf. Browsers and servers use MIME types to know how to handle files—display an image, play a video, download a document, etc.

The Problem: How Do Computers Know What a File Is?

You download a file called "vacation.jpg" from a website. Your browser needs to answer: "What do I do with this?" Should it:

The filename extension (.jpg) provides a hint, but it's unreliable—anyone can rename "malware.exe" to "document.pdf". MIME types solve this by providing a standardized, official way for servers to tell clients: "This is the type of data I'm sending you."

MIME Type Format: type/subtype

Every MIME type follows the pattern type/subtype:

Examples:

image/jpeg → Type: image, Subtype: jpeg
text/html → Type: text, Subtype: html
application/pdf → Type: application, Subtype: pdf
video/mp4 → Type: video, Subtype: mp4
audio/mpeg → Type: audio, Subtype: mpeg

The type indicates the general category. The subtype specifies the exact format. Some MIME types also include parameters:

text/html; charset=utf-8
image/png; name="photo.png"
application/json; charset=utf-8

Common MIME Type Categories

text/* - Text-Based Content

MIME Type Description File Extension
text/plain Plain text file .txt
text/html HTML document .html, .htm
text/css CSS stylesheet .css
text/javascript JavaScript code (legacy) .js
text/csv Comma-separated values .csv

image/* - Image Files

MIME Type Description File Extension
image/jpeg JPEG image .jpg, .jpeg
image/png PNG image .png
image/gif GIF image/animation .gif
image/svg+xml SVG vector image .svg
image/webp WebP image format .webp

video/* and audio/* - Media Files

MIME Type Description File Extension
video/mp4 MP4 video .mp4
video/webm WebM video .webm
audio/mpeg MP3 audio .mp3
audio/wav WAV audio .wav
audio/ogg Ogg Vorbis audio .ogg

application/* - Binary and Complex Files

MIME Type Description File Extension
application/pdf PDF document .pdf
application/json JSON data .json
application/xml XML data .xml
application/zip ZIP archive .zip
application/javascript JavaScript (modern standard) .js
application/octet-stream Generic binary data (download) Any

How MIME Types Are Used

1. HTTP Headers (Web Servers)

When a web server sends a file to your browser, it includes a Content-Type header with the MIME type:

HTTP Response:

HTTP/1.1 200 OK
Content-Type: image/jpeg
Content-Length: 245789

[binary image data...]

The browser sees Content-Type: image/jpeg and knows: "This is a JPEG image. I should display it using my image renderer."

2. HTML <link> and <script> Tags

HTML tags can specify MIME types to help browsers:

<link rel="stylesheet" href="style.css" type="text/css">
<script src="app.js" type="application/javascript"></script>
<img src="photo.jpg" type="image/jpeg">

Modern browsers often ignore these and determine type from the Content-Type header or file inspection, but they provide a fallback.

3. Email Attachments

MIME types originated in email! Email messages use MIME types to indicate attachment types:

Content-Type: application/pdf; name="invoice.pdf"
Content-Disposition: attachment; filename="invoice.pdf"

4. File Upload Forms

HTML file inputs can restrict accepted file types using MIME types:

<input type="file" accept="image/png, image/jpeg">
<input type="file" accept="application/pdf">
<input type="file" accept="video/*">

The browser's file picker will filter to show only matching files (though users can sometimes override this).

MIME Type vs File Extension

Critical Difference
File extensions (.jpg, .pdf, .exe) are just naming conventions—anyone can rename a file. MIME types are declarations from the server about what the data actually is. Browsers trust MIME types over extensions for security and proper handling.
Aspect File Extension MIME Type
Purpose Human/OS convention Machine-readable identifier
Reliability Can be wrong/misleading Official declaration
Change Easily changed (rename file) Set by server/application
Example photo.jpg image/jpeg
Browser Trusts Secondary/fallback Primary authority
Scenario: Mismatched Extension and MIME Type

File name: document.jpg
Content-Type: application/pdf

Browser behavior: Displays as PDF, ignoring .jpg extension
Why: MIME type takes precedence over filename

Special MIME Types

application/octet-stream (Generic Binary)

This is the "I don't know what this is" MIME type. When a server uses application/octet-stream, it's saying "This is binary data; I'm not telling you what kind." Browsers typically prompt the user to download rather than trying to display it.

Content-Type: application/octet-stream
Content-Disposition: attachment; filename="download.bin"

multipart/* (Multiple Parts)

Used when a single message contains multiple pieces of different types:

text/plain vs text/html

Both are text, but the MIME type tells browsers how to interpret:

How Servers Determine MIME Types

Web servers need to know what MIME type to send. They typically use:

1. Extension-Based Mapping

Servers have configuration files mapping extensions to MIME types:

Apache (.htaccess or mime.types):
AddType image/jpeg .jpg .jpeg
AddType application/pdf .pdf
AddType video/mp4 .mp4

Nginx (mime.types):
types {
    text/html html htm;
    image/jpeg jpg jpeg;
    application/pdf pdf;
}

2. File Content Inspection

Some systems examine the file's actual content (magic bytes) to determine type, regardless of extension:

JPEG files start with: FF D8 FF
PNG files start with: 89 50 4E 47
PDF files start with: 25 50 44 46 (%PDF)
ZIP files start with: 50 4B 03 04

3. Explicit Configuration

Programmers can explicitly set MIME types in server code:

Node.js (Express):
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify(data));

PHP:
header('Content-Type: application/json');
echo json_encode($data);

Python (Flask):
return send_file('document.pdf', mimetype='application/pdf')

Common MIME Type Problems

Problem 1: Wrong MIME Type Causes Download Instead of Display

Issue: Image sent as application/octet-stream
Result: Browser downloads instead of displaying
Fix: Server must send correct Content-Type: image/jpeg

Problem 2: CSS/JS Not Loading

Issue: Stylesheet served as text/plain instead of text/css
Result: Browser refuses to apply styles (security)
Fix: Configure server to send correct MIME type

Problem 3: JSON Served as text/html

Issue: API returns JSON with text/html MIME type
Result: JavaScript can't parse response properly
Fix: Set Content-Type: application/json
Security Risk: MIME Type Confusion
If a server sends executable JavaScript with MIME type text/plain, older browsers might still execute it, creating a security vulnerability. Modern browsers enforce strict MIME type checking to prevent this.

MIME Type Sniffing (and Why It's Dangerous)

Some browsers try to be "helpful" by ignoring declared MIME types and guessing based on content. This is called MIME sniffing or content sniffing.

The Problem: A malicious user uploads "image.jpg" that's actually JavaScript. If the server says "image/jpeg" but the browser sniffs the content and decides "this looks like JavaScript," it might execute the code—creating a security hole.

Best Practice: Disable MIME Sniffing
Add this HTTP header to prevent browsers from overriding your MIME type:

X-Content-Type-Options: nosniff

This forces browsers to trust your declared MIME type, preventing content-sniffing attacks.

Checking MIME Types

Browser Developer Tools

  1. Open Developer Tools (F12)
  2. Go to Network tab
  3. Reload the page
  4. Click on any file
  5. Look at Response Headers → Content-Type

Command Line (curl)

curl -I https://example.com/image.jpg

# Output includes:
Content-Type: image/jpeg

Command Line (file command)

file --mime-type photo.jpg
# Output: photo.jpg: image/jpeg

Frequently Asked Questions

What's the difference between MIME type and file format?

File format is what the file actually is (JPEG, PDF, MP4). MIME type is the standardized label used to communicate that format between computers. Think of file format as the actual language spoken, and MIME type as the official name for that language in a directory.

Why do some files have multiple MIME types?

Some formats have legacy or alternative MIME types. For example, JavaScript historically used text/javascript, but the modern standard is application/javascript. Both work, but prefer the official/modern version when possible.

Do I need to set MIME types for files on my computer?

No. MIME types are primarily for network communication (web servers, email). Your local operating system uses file extensions and internal databases to determine file types. MIME types matter when files are transmitted between systems.

Can MIME types be wrong?

Yes. If a server is misconfigured or a programmer explicitly sets the wrong MIME type, clients will misinterpret the data. This causes display issues (CSS not loading), download prompts when inline display was intended, or security vulnerabilities.

What happens if there's no MIME type?

If a server doesn't specify a Content-Type header, browsers fall back to: 1) Checking file extension, 2) Inspecting file content (MIME sniffing), or 3) Using a default (usually application/octet-stream for downloads). This is unreliable—always set explicit MIME types.