Performance: Font family utilities
This affects page load speed and rendering performance by controlling which font files are downloaded and how text is painted.
Jump into concepts and practice - no test required
<div class="font-sans">Text</div><div class="font-serif font-mono font-sans">Text</div>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Multiple font-family utilities on same element | No extra DOM nodes | Multiple reflows due to font swaps | High paint cost due to font decoding | [X] Bad |
| Single font-family utility per element | No extra DOM nodes | Single reflow | Low paint cost | [OK] Good |
| Custom font without font-display | No extra DOM nodes | Reflow blocked until font loads | High paint cost, blocks LCP | [X] Bad |
| Custom font with font-display: swap | No extra DOM nodes | Reflow occurs after fallback paint | Lower paint cost, faster LCP | [OK] Good |
font-sans for sans-serif fonts, font-serif for serif fonts, and font-mono for monospace fonts.font-sans applies a sans-serif font style to text.font-mono to apply monospace fonts, which have equal spacing for each character.font-mono is the correct class to apply monospace fonts, while others apply serif, sans-serif, or font weight.<p class="font-serif">Hello World</p>
font-serif, which applies a serif font family.<h1 class="font-sans-serif">Welcome</h1>
font-sans-serif is not a valid Tailwind font family class. Tailwind uses font-sans for sans-serif fonts.font-sans, not font-sans-serif.font-sans-serif is not a valid Tailwind class -> Option A<code class="?">console.log('Hello')</code>font-mono.text-sm for smaller but readable text size on small devices.