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

Steps

  1. Look up the font types

    Search for font. The table lists the current types: font/woff2 for .woff2, font/woff for .woff, font/ttf for .ttf and font/otf for .otf.

  2. 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.

  3. Configure Apache

    Add the types to .htaccess or 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   .otf
  4. Configure nginx

    Check your mime.types file includes the font lines; add them inside the types block if not, then reload nginx.

    types {
        font/woff2 woff2;
        font/woff  woff;
    }
  5. 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.

Try it now

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.