Variable Fonts in CSS: One File, All Weights
Multiple font weights without multiple files
You loaded a separate font file for each weight (400, 500, 600, 700), so 4 or more HTTP requests. One variable font file covers the full range with font-weight: 100 900.
The old hack vs the modern fix
View demo@font-face {
font-family: "MyFont";
src: url("MyFont-Regular.woff2");
font-weight: 400;
}
@font-face {
font-weight: 700;
...
}
@font-face {
font-weight: 600;
...
}@font-face {
font-family: "MyVar";
src: url("MyVar.woff2");
font-weight: 100 900;
}<!-- Configure the variable font in @font-face or tailwind.config.js --><!-- Then use any weight — named utilities or arbitrary values --><p class="font-medium">500 weight</p><p class="font-bold">700 weight</p><!-- Intermediate weights only possible with variable fonts --><p class="font-[350]">Custom 350 weight</p>Font variation settings browser support
Live demo
Why the modern way wins
Fewer requests
One variable font file instead of four or more for Regular, Medium, SemiBold, Bold.
Any weight in range
Use font-weight: 350 or 627 if the font supports it. No need to add a new @font-face.
Smaller total size
One optimized file is often smaller than the sum of several static weight files.
- Requests
- 4+ → 1
- One file for full range
- Old Approach
- One @font-face per weight
- 4+ HTTP requests
- Modern Approach
- Variable font
- font-weight: 100 900
How it works
The old approach was one @font-face per weight: Regular (400), Medium (500), SemiBold (600), Bold (700). Each pointed at a different file, so the browser made 4 or more requests and you had to add a new @font-face whenever you needed another weight.
Variable fonts pack multiple weights (and sometimes width or other axes) into a single file. In @font-face you set font-weight: 100 900 (or the range the font supports). The browser downloads one file and you use any weight in that range with font-weight: 400, font-weight: 600, etc. Check the font's documentation for its actual range.