MIME Type Lookup · Tutorial
How to serve web fonts with the right MIME type
5 min readbeginnerUpdated
Your self-hosted font works on your laptop but not on the live server, and the browser console mentions a MIME type. This tutorial looks up the right types for font files, adds them to your server configuration, and checks a file that might be misnamed.
What you need
- The MIME Type Lookup
- Access to your server’s configuration, and the font files
Steps
Look up the font types
Search for
font. The table lists the current types:font/woff2for .woff2,font/wofffor .woff,font/ttffor .ttf andfont/otffor .otf.Check your font file
Drop the font file on Check what a file really is. A real WOFF2 file starts with the signature wOF2. If the tool reports something else, such as an HTML page, the file is a download error page saved with a font name.
Configure Apache
Add the types to
.htaccessor the server config if they are missing. Older servers often don’t know them.AddType font/woff2 .woff2 AddType font/woff .woff AddType font/ttf .ttf AddType font/otf .otfConfigure nginx
Check your
mime.typesfile includes the font lines; add them inside thetypesblock if not, then reload nginx.types { font/woff2 woff2; font/woff woff; }Verify in the browser
Open the developer tools, reload the page, select the font request in the Network panel, and check that the response header says
Content-Type: font/woff2.
Try it yourself
Opens the MIME Type Lookup with this tutorial's sample loaded.
Common mistakes
- Using old font types
- Types like application/font-woff or application/x-font-ttf still appear in old guides. Browsers accept the font/ types, which are the registered ones.
- Fonts from another domain
- Fonts loaded from a different domain also need an Access-Control-Allow-Origin header, or the browser blocks them.
- Only shipping TTF
- WOFF2 files are much smaller. Serve WOFF2 to all current browsers and keep other formats only if you need very old ones.
Next steps
Go back to the MIME Type Lookup, or keep going with one of these:
FAQ
Do I need WOFF as well as WOFF2?
Every current browser supports WOFF2, so WOFF is only for very old browsers.
Does the type matter if the font loads anyway?
Yes. With the nosniff security header, which many hosts add by default, browsers may refuse resources with the wrong type.