CSS @font-face
- type
- at-rule
- applies to
- the whole stylesheet
- inherits
- n/a
- common values
- font-family, src: url(), font-weight, font-display
Where it goes
At the top of the stylesheet, before any rule that uses the family. Use woff2, add font-display: swap so text shows in a fallback font while the file loads, and declare only the weights you use. Every file is a download.
Example
@font-face {
font-family: 'Inter';
src: url(/fonts/inter-regular.woff2) format('woff2');
font-weight: 400;
font-display: swap;
}
body { font-family: 'Inter', system-ui, sans-serif; }Common mistakes
- Naming the family differently in font-family than in @font-face. The names must match exactly, quotes and case included, or the fallback font shows.
- Loading one weight and using several. The browser fakes bold and italic by smearing the letters, which looks muddy. Declare a block for each weight you use.
- Skipping font-display. On a slow connection the text stays invisible until the font arrives. swap shows fallback text right away.