Aabestfontgenerator.
THE TYPE NOTEBOOK

CSS @font-face: Load a Web Font and Match Its Styles

Load a local web font with CSS @font-face, match the declared weight to the file and troubleshoot fallback text.

Load a local web font with CSS @font-face, match the declared weight to the file and troubleshoot fallback text.

Sources reviewed .

01

Register the file and use the family

Declare an @font-face rule with a family name and a source such as url('/fonts/article-regular.woff2') format('woff2'). Apply the same name in the element’s font-family list and include a generic fallback. Start with a file you have permission to serve and check that its URL is reachable from the page. Test with the actual headline and body copy.

02

Describe which weight the file supplies

For a static regular file, use font-weight: 400 in its rule. Declare another face for a separate bold file under the same family with the bold weight. When the file is variable, describe the range that it actually supports. The CSS font weight guide explains how the weight property requests a style, while the font format guide helps identify the file.

03

Diagnose a fallback in the browser

Inspect the network request for the font, then inspect the affected text to check the rendered family. Compare a plain paragraph and a bold heading. An invalid path, a blocked cross-origin request or a mismatched family name can lead to fallback. If using font-display: swap, inspect the layout during the transition from fallback to the loaded font. For a separate caption that must paste into an app as plain text, use the copyable text styles instead of assuming CSS travels with the words.

GOOD QUESTIONS

Your questions, answered.

Is @font-face enough to apply a font to an element?

Register the face with the rule, then use its declared family in the element’s font-family list.

Can one @font-face rule cover multiple weights?

A variable file can be declared with its supported range. For separate static files, declare faces with the corresponding weights and styles.

Sources & background

Sources supporting this page’s explanations. Practical examples are our editorial suggestions.