Към основното съдържание
← 📄 HTML & the platform·Модул A7 · Урок 4
ЗадачаAdd an @font-face for Inter from /inter.woff2 (woff2 format) with font-display: swap. Set body to use 'Inter', system-ui, sans-serif.

Зареждане на шрифт: размяна на дисплея на шрифта

100 XP7 min
Теория

Two evil acronyms: FOUT and FOIT

  • FOUT (Flash Of Unstyled Text) — text renders in the fallback font, then flips to your custom font. Looks awkward but content is readable.
  • FOIT (Flash Of Invisible Text) — text is INVISIBLE until your font downloads, sometimes seconds. Browser's default behavior.

You want FOUT, not FOIT. The fix is one CSS property:

@font-face {
  font-family: "Inter";
  src: url("/fonts/inter.woff2") format("woff2");
  font-display: swap;     /* fallback shown immediately; custom swapped in when ready */
  font-weight: 100 900;   /* variable font weight range */
}

body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
}

font-display values

ValueFirst paintAfter font loads
swapfallback visibleswap in custom (FOUT)
blockinvisible (3s timeout)swap in (FOIT)
fallbackfallback (100ms timeout)swap if loaded in 3s, else stay
optionalfallback (100ms timeout)use custom ONLY if instant (cached)

For body text: swap is the standard. For "branding" wordmark logos where you can't tolerate a fallback: maybe block (but consider an SVG instead).

Pair with preload

<link rel="preload" as="font" type="font/woff2" href="/inter.woff2" crossorigin />

Cuts the FOUT duration from ~300ms to ~50ms by starting the font download before CSS is even parsed.

🔒

Регистрирай се за да започнеш да кодираш

Теорията е отворена за всички. Редакторът, живият преглед и проверката се отключват с 7-дневен безплатен пробен период — нужна е карта.

Регистрация — безплатен пробен период →

Първите 10 урока във всеки път са безплатни. Без карта.

← НазадСледващ урок →

Един съвет за Python или уеб на ден — на имейл

Кратко, ръчно написано, без спам. Отписване с едно кликване.