The page loads, but the browser console shows "Refused to execute script because its MIME type ('text/html') is not executable". A PDF link downloads instead of opening. An upload form rejects a perfectly good .webp image. A WebAssembly module fails to compile with a streaming error. All of these come back to the same small label: the MIME type.
This guide explains what MIME types are, where they come from, how browsers treat them, and how to look up and set the correct one on common servers and in code.
What a MIME type is
A MIME type (also called a media type or content type) is a short label that tells software what kind of data it is dealing with. It has two parts separated by a slash, with optional parameters:
type/subtype; parameter=value
text/html; charset=utf-8
The top-level type is a broad category: text, image, audio, video, font, model or application (anything else, including most binary formats). The subtype names the specific format: image/png, audio/mpeg, application/pdf.
Some patterns in subtypes are worth recognising:
vnd.marks a vendor-specific format, such asapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheetfor.xlsx.+jsonor+xmlsuffixes say the format is built on JSON or XML, as inapplication/manifest+jsonorimage/svg+xml.x-prefixes are old unregistered types (application/x-7z-compressed). Many are still used because no official type was ever registered.
The name comes from MIME (Multipurpose Internet Mail Extensions), the email standard that introduced these labels. HTTP adopted them, and the IANA keeps the official registry.
Where MIME types are used
The Content-Type header
When a server sends a response, the Content-Type header tells the browser how to handle the bytes. The file extension in the URL is not what the browser trusts; the header is. You can see it with:
curl -sI https://example.com/app.js | grep -i content-type
A mismatched header causes most MIME problems:
- Scripts and stylesheets: browsers refuse a
<script type="module">that is not served with a JavaScript type, and refuse stylesheets not served astext/cssin standards mode. WithX-Content-Type-Options: nosniff, classic scripts are also blocked. A frequent cause is a missing file that returns an HTML error page with a 200 or 404 status. - Downloads versus inline display:
application/pdfusually opens in the browser's viewer;application/octet-stream(generic binary) is usually downloaded. TheContent-Dispositionheader also plays a part. - WebAssembly:
WebAssembly.instantiateStreaming()requiresapplication/wasm.
Uploads and forms
When you pick a file in a browser, the browser guesses a type from the extension using the operating system's registry and reports it as file.type. Upload forms often check this value. The accept attribute on <input type="file"> filters the file picker by type or extension:
<input type="file" accept="image/png, image/jpeg, .webp">
This check is a convenience, not security. The type comes from the file name, so a server must still validate the real contents.
Email and APIs
Email attachments and multipart form uploads each carry a Content-Type per part. APIs declare the body format with Content-Type: application/json and ask for a response format with the Accept header.
Look up a type or check a file
The MIME Type Lookup combines a searchable table with a file checker. Nothing is uploaded: for dropped files it only reads the name, size and the type your browser reports.
- Open the MIME Type Lookup and type into the search box. You can search by extension (
.webporwebp), by MIME type (image/png), or by description (excel). - Narrow the list with the filter buttons: all, application, audio, font, image, model, text or video. The counter shows how many entries match.
- Click the copy icon on a row to copy the MIME type.
- To check real files, drop them onto the box at the top or click Choose files. The table shows the Browser type, the type Expected from extension, and the size.
- If Browser type is empty, your browser and operating system do not know that extension. That is exactly the case where an upload form that relies on
file.typewill reject the file.
Setting the right type on a server
Most servers map extensions to types from a built-in list. Newer formats sometimes are not in older lists and fall back to application/octet-stream or text/plain.
Nginx reads its mappings from the types { ... } block in its mime.types file. Add any missing lines to that block:
types {
application/wasm wasm;
application/manifest+json webmanifest;
image/avif avif;
}
Be careful about putting a separate types block inside a server or location section: it replaces the inherited list there instead of adding to it, so every other extension would lose its type.
Apache can add types in the config or .htaccess:
AddType application/wasm .wasm
AddType image/avif .avif
Node.js frameworks usually set the type for static files automatically. For responses you build yourself, set it explicitly:
res.setHeader("Content-Type", "application/json; charset=utf-8");
Object storage (S3 and similar) stores the Content-Type with each object at upload time. If a file was uploaded with the wrong type, re-upload it or edit its metadata; changing the server config does not help.
Other ways to identify a type
- Command line: on Linux and macOS,
file --mime-type report.pdfinspects the file's contents ("magic bytes") rather than its name. That catches renamed files that the extension-based approach misses. - Browser DevTools: the Network tab shows the Content-Type of every response, which is the quickest way to debug the "refused to execute" family of errors.
- Programming libraries: packages such as
mime-typesfor Node.js or Python's built-inmimetypesmodule map extensions to types in code.
Pitfalls and troubleshooting
Several types for one extension
Some extensions have more than one type in use. .js is officially text/javascript (the older application/javascript still works). .ico appears as both image/vnd.microsoft.icon and image/x-icon. Both usually work in browsers; use the registered one when you have a choice.
Charset on text types
For text/*, application/json and similar, add charset=utf-8 if your files are UTF-8. Without it, older clients may guess the wrong encoding and show garbled accented characters.
Serving files for download
To force a download regardless of type, send Content-Disposition: attachment; filename="report.csv" rather than lying about the type.
For the status code side of HTTP responses, see the HTTP status codes reference. If you are embedding small files directly in HTML or CSS, a data URI needs the MIME type too; the Base64 converter and image to Base64 tools produce those. Redirect and header rules for Apache can be drafted with the .htaccess redirect generator.
Frequently asked questions
What is the MIME type for JSON?
application/json. Formats built on JSON often use a +json suffix, such as application/ld+json for structured data or application/manifest+json for web app manifests.
Why does my browser say "strict MIME type checking is enabled"?
The server sent a script or stylesheet with a Content-Type that is not JavaScript or CSS, very often text/html because the URL returned an error page. Check the file path and the server's type mapping.
What does application/octet-stream mean?
It means "arbitrary binary data" with no more specific type. Browsers usually download such files instead of displaying them.
Is the MIME type stored inside the file?
No. It is metadata supplied by the server, operating system or uploader. Many formats do start with recognisable "magic bytes", which tools like file use to guess the type from contents.
Can I trust file.type for upload validation?
Only as a first filter. The browser derives it from the file extension, so anyone can rename a file. Validate the actual content on the server.