The @font-face at-rule lets you load custom font files into your website. Define a family name, point to the font file, then use that name in font-family like any other font.
01
Custom fonts
Load your own.
02
font-family
Name the font.
03
src url()
Font file path.
04
WOFF2
Best format.
05
font-display
Loading behavior.
06
Fallbacks
Backup fonts.
Fundamentals
Introduction
The @font-face at-rule in CSS lets web developers load custom font files on their websites. Without it, you are limited to fonts already installed on the user’s device or generic families like serif and sans-serif.
Definition and Usage
@font-face is not a CSS property — it is an at-rule, like @media or @charset. It registers a font family name and links it to one or more font files. Once registered, you reference that name in the font-family property on any selector.
This is how brand fonts, icon fonts, and downloadable typefaces reach every visitor consistently — regardless of what is installed on their computer or phone.
💡
Beginner Tip
Think of @font-face as “installing” a font for your webpage. You declare it once, then use the family name everywhere you would normally write font-family.
Foundation
📝 Syntax
The basic syntax defines a font family name and where to find the font file:
If Lato cannot load, system-ui or a local sans-serif is used instead.
How It Works
The browser tries Lato first. If the file is missing or blocked, it moves to system-ui, then sans-serif.
Tips
💬 Usage Tips
Prefer WOFF2 — Smaller files and excellent browser support for modern sites.
Use font-display: swap — Avoid invisible text while fonts download.
Load only what you need — Include just the weights and styles your design uses.
Quote family names — Use quotes when the name contains spaces: 'Open Sans'.
Host fonts correctly — Place files in a fonts/ folder and use relative paths in src.
Watch Out
⚠️ Common Pitfalls
Forgetting fallbacks — Without backup fonts, failed loads can leave text in an unexpected typeface.
Wrong file paths — A broken url() silently falls back; always verify paths in DevTools Network tab.
Fake bold — Browsers may stretch a regular file if you skip the bold @font-face block.
Loading too many weights — Each file adds download time; trim unused variants.
Confusing with font-family — @font-face registers the font; font-family applies it.
A11y
♿ Accessibility
Readable typefaces — Choose fonts with clear letter shapes for body text.
Adequate size and line-height — Custom fonts still need comfortable reading settings.
font-display: swap — Prevents long periods of invisible text (FOIT) that block reading.
Contrast — Font choice does not replace color contrast requirements.
Respect user preferences — Some users override fonts in browser settings; fallbacks help.
🧠 How @font-face Works
1
@font-face is parsed
The browser reads your @font-face block and registers the family name.
Register
2
Font file is downloaded
When an element uses that family, the browser fetches the file from src.
Download
3
font-display controls timing
With swap, fallback text shows immediately and updates when the font is ready.
Display
=
📝
Custom typography applied
Text renders in your chosen typeface across devices.
Compatibility
🖥 Browser Compatibility
The @font-face at-rule has universal support in all modern browsers. WOFF2 is supported in all current Chrome, Firefox, Safari, Edge, and Opera versions.
✓ Baseline · Universal support
@font-face + WOFF2
Custom web fonts work in every major browser. WOFF2 is the standard format for production sites.
100%@font-face rule
Google Chrome@font-face + WOFF2
Full support
Mozilla Firefox@font-face + WOFF2
Full support
Apple Safari@font-face + WOFF2
Full support
Microsoft Edge@font-face + WOFF2
Full support
OperaAll modern versions
Full support
@font-face at-rule100% supported
Bottom line:@font-face is safe for production. Use WOFF2 for file size and speed; keep WOFF only if you must support very old browsers.
Wrap Up
🎉 Conclusion
The @font-face at-rule is essential for custom typography on the web. Define your font once with font-family and src, apply it with font-family on your elements, and always include fallback fonts for reliability.
Prefer WOFF2, use font-display: swap, and load only the weights you need. With these habits, your pages look polished without sacrificing performance or readability.
Declare separate @font-face blocks per weight/style
Subset fonts to include only characters you need
❌ Don’t
Load every weight if you only use regular and bold
Forget to check font file paths in DevTools
Rely on browser-synthesized bold or italic
Confuse @font-face with the font-family property
Use unlicensed font files on public websites
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about @font-face
Use these points when loading custom fonts on your site.
5
Core concepts
@ff01
At-rule
Registers fonts.
Type
src02
Font file
url() or local().
Source
w203
WOFF2
Best format.
Format
swap04
font-display
Show text fast.
Loading
fb05
Fallbacks
Backup fonts.
Safety
❓ Frequently Asked Questions
The @font-face at-rule lets you load custom font files into a webpage. You give the font a family name, point to the font file with src, then use that name in the font-family property like any other font.
After @font-face registers a family name, apply it with font-family on any selector. Always include fallback fonts: font-family: 'MyFont', system-ui, sans-serif; so text stays readable if the file fails to load.
WOFF2 is the best choice for modern browsers — it is compressed and widely supported. You can list multiple src entries with different formats (woff2, woff) so older browsers have a fallback file.
font-display controls how text appears while a web font is loading. swap shows fallback text immediately and swaps to the custom font when ready — a good default for readable pages.
Yes. @font-face has been supported in all major browsers for many years. WOFF2 is supported in all current Chrome, Firefox, Safari, Edge, and Opera versions.