MIME Types and File Extensions - Colin Mackay

Understanding the relationship between MIME types and file extensions, how they work on the web, and troubleshooting content type issues.

Last updated: January 2026

When files are transferred over the internet, how do browsers and other applications know what type of content they're receiving? This is where MIME types come in. Understanding the relationship between MIME types and file extensions helps troubleshoot issues with file downloads, web content display, and application behaviour.

This guide explains what MIME types are, how they relate to file extensions, and how they're used in web development and everyday computing.

What Are MIME Types?

MIME stands for Multipurpose Internet Mail Extensions. Originally developed to allow email to include attachments beyond plain text, MIME types are now used throughout the internet to identify the nature and format of data.

A MIME type (also called a media type or content type) is a standardised identifier that tells applications what kind of data they're dealing with. Unlike file extensions, which are simply conventions that applications may or may not recognise, MIME types are part of the HTTP protocol and are used by servers and clients to communicate about content.

For a broader understanding of file formats on the web, the Wikipedia article on file formats provides historical context on how different identification systems evolved.

MIME Type Structure

MIME types follow a consistent format:

type/subtype

For example:

  • text/html – HTML documents
  • image/png – PNG images
  • application/json – JSON data

Primary Types

The main type categories are:

  • text – Human-readable text (text/plain, text/html, text/css)
  • image – Image data (image/png, image/jpeg, image/gif)
  • audio – Audio content (audio/mpeg, audio/ogg)
  • video – Video content (video/mp4, video/webm)
  • application – Binary data or specific applications (application/pdf, application/json)
  • multipart – Data composed of multiple parts (multipart/form-data)
  • font – Font files (font/woff, font/woff2)

Parameters

MIME types can include additional parameters:

text/html; charset=utf-8
application/json; charset=utf-8

The charset parameter is common for text formats, specifying character encoding.

Common MIME Types

Here are frequently encountered MIME types grouped by category:

Text and Documents

MIME Type Extension Description
text/plain.txtPlain text
text/html.html, .htmHTML documents
text/css.cssStylesheets
text/javascript.jsJavaScript
application/pdf.pdfPDF documents
application/json.jsonJSON data
application/xml.xmlXML data

Images

MIME Type Extension Description
image/jpeg.jpg, .jpegJPEG images
image/png.pngPNG images
image/gif.gifGIF images
image/svg+xml.svgSVG graphics
image/webp.webpWebP images

Audio and Video

MIME Type Extension Description
audio/mpeg.mp3MP3 audio
audio/ogg.oggOgg Vorbis audio
audio/wav.wavWAV audio
video/mp4.mp4MP4 video
video/webm.webmWebM video

Archives and Applications

MIME Type Extension Description
application/zip.zipZIP archives
application/gzip.gzGzip compressed
application/octet-stream(various)Generic binary data

The authoritative registry of MIME types is maintained by IANA (Internet Assigned Numbers Authority).

File Extensions vs MIME Types

File extensions and MIME types serve similar purposes but work differently:

File Extensions

  • Part of the filename (e.g., .pdf, .jpg)
  • Used by operating systems to associate files with applications
  • Can be changed by users (potentially misleading)
  • Convention-based—there's no central enforcement

MIME Types

  • Sent as HTTP headers by web servers
  • Determined by server configuration, not the filename
  • Used by browsers to decide how to handle downloaded content
  • Standardised through IANA

When They Disagree

What happens when a file's extension doesn't match the MIME type the server sends? Behaviour varies:

  • Browsers: Generally trust the MIME type over the extension for security reasons
  • Downloads: May save with the original filename but handle based on MIME type
  • Some applications: May check both and refuse to open mismatched files

How MIME Types Are Used

Web Servers

Web servers include the Content-Type header when serving files:

HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8

Server configuration maps file extensions to MIME types. In Apache, this is configured in mime.types or via .htaccess. In Nginx, it's in mime.types or server blocks.

Web Browsers

Browsers use MIME types to decide how to handle content:

  • text/html – Render as a web page
  • image/* – Display as an image
  • application/pdf – Display in PDF viewer or download
  • application/octet-stream – Prompt for download

Forms and Uploads

When uploading files via HTML forms, the browser sends MIME type information:

<form enctype="multipart/form-data">
  <input type="file" accept="image/*">
</form>

The accept attribute can filter by MIME type, and the browser reports the file's MIME type to the server.

API Responses

Web APIs typically use application/json for responses:

Content-Type: application/json

{"status": "success", "data": {...}}

Common Issues

File Downloads Instead of Displaying

If a file downloads when it should display in the browser (or vice versa), the MIME type may be incorrect. Common causes:

  • Server misconfiguration
  • Missing MIME type mapping for the extension
  • Server defaulting to application/octet-stream

Solution: Configure the server to send the correct Content-Type header.

CSS or JavaScript Not Working

Modern browsers enforce MIME type checking for scripts and stylesheets. If CSS is served as text/plain instead of text/css, the browser may refuse to apply it.

Solution: Ensure your server configuration correctly maps .css to text/css and .js to text/javascript.

Images Not Displaying

If images load in some contexts but not others, MIME type issues may be involved. Some image processing libraries are stricter about MIME types than browsers.

Solution: Verify the server sends the correct image MIME type (image/png, image/jpeg, etc.).

Upload Validation Failures

If file uploads fail validation despite appearing correct, there may be a mismatch between the file's actual content and its extension/MIME type.

Solution: Validate file content server-side by examining file headers ("magic bytes"), not just the reported MIME type or extension.

Frequently Asked Questions

Can I change a file's MIME type?

You can't change a file's "inherent" MIME type—it's determined by the file's actual content. However, you can configure servers to send different Content-Type headers, and you can change file extensions. Note that misrepresenting file types can cause issues and may be a security concern.

Why does my browser download instead of display a file?

The server is probably sending a MIME type that triggers download behaviour (like application/octet-stream) or including a Content-Disposition: attachment header. Check your server configuration.

What MIME type should I use for JSON?

Use application/json. Some older systems accept text/json, but application/json is the standard. Include charset=utf-8 if you want to be explicit about encoding.

How do I find a file's MIME type?

On Linux/macOS, use the file --mime-type filename command. On Windows, tools like 7-Zip show file type information. In browsers, check the Network tab in developer tools to see Content-Type headers.

Is text/javascript or application/javascript correct?

text/javascript is the standard per current specifications. application/javascript was once preferred but is now considered legacy. Both work in practice, but use text/javascript for new projects.