Performance: Custom font integration
This affects page load speed and visual stability by controlling how fonts load and render on the page.
@font-face { font-family: 'MyFont'; src: url('/fonts/myfont.woff2') format('woff2'); font-display: swap; }@font-face { font-family: 'MyFont'; src: url('/fonts/myfont.woff2') format('woff2'); font-display: auto; }| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| font-display: auto | Minimal | Multiple reflows on font swap | High paint cost due to invisible text and repaint | [X] Bad |
| font-display: swap | Minimal | Single reflow on font swap | Lower paint cost with immediate fallback text | [OK] Good |
@font-face in Tailwind CSS when integrating a custom font?@font-face@font-face is a CSS rule that lets you load a custom font file into your website.@font-face to Tailwind usage@font-face, you extend Tailwind's fontFamily to use that font in your classes.@font-face loads fonts = D [OK]@font-face loads fonts, not styles [OK]@font-face changes font sizefontFamily in tailwind.config.js to add a custom font named 'MyFont'?fontFamily: { key: ['FontName', 'fallback'] }.custom as key and an array with 'MyFont' and 'sans-serif'. Others misuse keys or values.fontFamily: { custom: ['MyFont', 'sans-serif'] }<p class="font-custom">Hello</p>
font-custom applies the font family named 'custom' from Tailwind config.@font-face, it will be used first, with 'sans-serif' as fallback.@font-face { font-family: 'MyFont'; src: url('/fonts/MyFont.woff2'); }font-custom class still shows default font. What is the likely mistake?@font-face, so the font file is available.fontFamily in tailwind.config.js, the class font-custom won't apply the new font.fontFamily in tailwind.config.js -> Option Btailwind.config.js and your CSS to use font-boldcustom and font-lightcustom classes for them?@font-face rules@font-face with unique font-family names like 'MyFontBold' and 'MyFontLight'.fontFamilytailwind.config.js, add keys 'boldcustom' and 'lightcustom' pointing to these font-family names so you can use font-boldcustom and font-lightcustom classes.Pass the test and this pattern moves unknown