@font-face CSS Reference
The @font-face rule lets you load custom fonts. Here is the complete syntax and format comparison.
Complete @font-face Syntax
@font-face {
font-family: 'CustomFont';
src: url('fonts/CustomFont.woff2') format('woff2'),
url('fonts/CustomFont.woff') format('woff');
font-weight: 400;
font-style: normal;
font-display: swap;
}
/* Multiple weights */
@font-face {
font-family: 'CustomFont';
src: url('fonts/CustomFont-Bold.woff2') format('woff2'),
url('fonts/CustomFont-Bold.woff') format('woff');
font-weight: 700;
font-style: normal;
font-display: swap;
}
/* Usage */
body {
font-family: 'CustomFont', sans-serif;
}Font Format Comparison
| Format | Extension | Compression | Support |
|---|---|---|---|
| WOFF2 | .woff2 | Best (~30% smaller) | All modern browsers |
| WOFF | .woff | Good | IE9+, all modern |
| TTF/OTF | .ttf / .otf | None | Broad, larger files |
| EOT | .eot | Moderate | IE only (legacy) |
| SVG | .svg | None | Legacy iOS Safari |
font-weight Values
| Value | Common name |
|---|---|
100 | Thin / Hairline |
200 | Extra Light |
300 | Light |
400 | Regular / Normal |
500 | Medium |
600 | Semi Bold |
700 | Bold |
800 | Extra Bold |
900 | Black / Heavy |
font-display Strategies
/* swap — show fallback immediately, swap when loaded (recommended) */
font-display: swap;
/* block — hide text briefly, then show custom font */
font-display: block;
/* fallback — short block period, then fallback if not loaded */
font-display: fallback;
/* optional — browser decides, may skip custom font on slow connections */
font-display: optional;Performance Tips
- 1.Use WOFF2 + WOFF only — skip TTF, EOT, SVG unless you need IE support
- 2.Set
font-display: swapto prevent invisible text (FOIT) - 3.Preload critical fonts:
<link rel="preload" href="font.woff2" as="font" crossorigin> - 4.Subset fonts to include only characters you need (Latin, Latin Extended, etc.)
- 5.Load max 2-3 font weights — each weight is a separate file download
Other tools: Clip Path Studio, Gradient Studio, URL Encoder