Definition
font-familylists fonts by preference, and the browser chooses per character: each is drawn with the first available font in the list that has it, so a word can mix two fonts.- When no listed font has a character, the browser searches the device's installed fonts, and results vary between browsers; when no font has it, a missing-glyph symbol shows instead.
- While a web font loads,
font-displaysets what shows: invisible text during the block period, then a fallback font during the swap period until the web font arrives. If the web font fails, the fallback stays.
Why it matters
- A fallback font has other letter shapes, widths and line heights, so lines wrap elsewhere and buttons resize, and each device has its own Arabic fonts.
- The generic family at the end of the list is the browser's last resort, and MDN advises always including one, such as
sans-serif. - The swap from the fallback to the web font can shift the layout;
size-adjustin an@font-facefor the fallback font can bring its size closer to the web font's.
Example
A web font for Arabic, an installed Arabic font after it, and a generic family last:
css
@font-face {
font-family: 'Brand Arabic';
src: url('/fonts/brand-arabic.woff2') format('woff2');
font-display: swap;
}
body {
font-family: 'Brand Arabic', 'Noto Naskh Arabic', system-ui, sans-serif;
}With swap, the text shows at once in a fallback, then changes to Brand Arabic when it arrives.
Common mistakes
- A list with the web font alone, and no generic family at the end.
- A fallback chosen for the Latin design and never tried with Arabic text.
- A web font that fails unnoticed: a wrong path, a font on another domain without an
Access-Control-Allow-Originheader, or a format the browser cannot read.