.ttf
Example
@font-face {
font-family: 'Inter';
src: url('/fonts/Inter.ttf');
}@font-face {
font-family: 'Inter';
src: url('/fonts/Inter.woff2') format('woff2');
font-display: swap;
}WOFF2 compresses the same TrueType data much smaller, and font-display: swap keeps text visible while it loads.
Common mistakes
- Serving desktop
.ttffiles on the web, which are larger than needed. - Shipping the full font with every language when the site uses one script.
Key points
@font-faceloads a.woff2file, not a raw.ttf, for web pages.- The
format()hint matches the file: 'woff2' for.woff2, 'truetype' for.ttf. - The font license allows web embedding before the file is self-hosted.
Interview questions
TTF vs OTF: what is the difference?
TTF uses TrueType outlines, while OTF usually uses CFF outlines and often more features. For screens and the web the difference is small.
How do I convert TTF to WOFF2?
Use a font tool such as fonttools or the woff2_compress utility. Subset the font at the same time to cut its size further.