arrow_back
Back

Web fonts: @font-face, variable fonts, loading, and fallbacks

Andrew Dorokhov Andrew Dorokhov schedule 2 min read
menu_book Table of Contents

Here’s how you can reference the font in your CSS styles:

@font-face {
    font-family: 'MyCustomFont';
    src: url('fonts/MyCustomFont.woff2') format('woff2'),
         url('fonts/MyCustomFont.woff') format('woff');
    font-weight: normal;
    font-style: normal;
}

If you provide the browser with a list of multiple font files to download, the browser will choose the first font file it’s able to use. That’s why the format you list first should be the preferred format — that is, WOFF2 — with the older formats listed after that. Browsers that don’t understand one format will then fall back to the next format in the list.

How to use it:

body {
    font-family: 'MyCustomFont', sans-serif;
}

Common weight name mapping

Value Common weight name
100 Thin (Hairline)
200 Extra Light (Ultra Light)
300 Light
400 Normal (Regular)
500 Medium
600 Semi Bold (Demi Bold)
700 Bold
800 Extra Bold (Ultra Bold)
900 Black (Heavy)
950 Extra Black (Ultra Black)

Formats

All major browsers support WOFF/WOFF2 (Web Open Font Format versions 1 and 2).

If you need to work with legacy browsers, you should provide EOT (Embedded Open Type), TTF (TrueType Font), and SVG web fonts for download.

Fallback font

Usually I use the sans-serif font as a fallback for web.

body {
    font-family: 'SomeFont', sans-serif;
}

Get detailed info about a font file

open_in_new https://fontdrop.info

Font sources

Paid fonts:

Free fonts:

Mixed:

code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward
Next Article

Grunt task runner: Gruntfile.js, plugins, and build automation

arrow_forward