@font-face
Embed This Widget
Add the script tag and a data attribute to embed this widget.
Embed via iframe for maximum compatibility.
<iframe src="https://fontfyi.com/iframe/glossary/font-face/" width="420" height="400" frameborder="0" style="border:0;border-radius:10px;max-width:100%" loading="lazy"></iframe>
Paste this URL in WordPress, Medium, or any oEmbed-compatible platform.
https://fontfyi.com/glossary/font-face/
Add a dynamic SVG badge to your README or docs.
[](https://fontfyi.com/glossary/font-face/)
Use the native HTML custom element.
A CSS at-rule that allows web designers to specify custom fonts for their web pages. The foundation of web typography.
The @font-face at-rule is the CSS mechanism for loading custom fonts — it registers a font family name and associates it with a source file, so that name can be used throughout your stylesheet. Every custom web font, whether self-hosted or served by Google Fonts or Adobe Fonts, arrives in your CSS through @font-face declarations.
Basic syntax:
@font-face {
font-family: 'Inter';
src: url('/fonts/inter-regular.woff2') format('woff2');
font-weight: 400;
font-style: normal;
font-display: swap;
}
Multiple weights and styles:
Each weight and style variant requires its own @font-face declaration with the same font-family name. The browser matches font-weight and font-style descriptors to select the correct file:
@font-face {
font-family: 'Inter';
src: url('/fonts/inter-regular.woff2') format('woff2');
font-weight: 400;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: 'Inter';
src: url('/fonts/inter-bold.woff2') format('woff2');
font-weight: 700;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: 'Inter';
src: url('/fonts/inter-italic.woff2') format('woff2');
font-weight: 400;
font-style: italic;
font-display: swap;
}
Variable fonts — one declaration replaces many:
@font-face {
font-family: 'Inter';
src: url('/fonts/inter-variable.woff2') format('woff2-variations');
font-weight: 100 900; /* Declares a range */
font-style: normal;
font-display: swap;
}
The font-display descriptor controls FOUT/FOIT behavior:
| Value | Behavior |
|---|---|
auto |
Browser default (usually block) |
block |
Invisible text until font loads (FOIT) |
swap |
Fallback immediately, swap when loaded (FOUT) |
fallback |
100ms block, then swap if loads within 3s |
optional |
100ms block, browser decides whether to swap |
font-display: swap is recommended for most use cases. optional is appropriate when you'd rather the user see system fonts consistently than experience a layout shift.
Unicode range for conditional loading:
@font-face {
font-family: 'MyFont';
src: url('/fonts/myfont-latin.woff2') format('woff2');
unicode-range: U+0000-00FF;
}
The font-family name you declare in @font-face is scoped to your CSS — it doesn't need to match the font's actual name. font-family: 'MyBrandFont' pointing to Inter's files is perfectly valid, though it creates maintenance confusion. By convention, use the font's actual name.
相关术语
相关工具
展示此概念的字体
了解更多
在 CSS 中使用可变字体的实用指南——加载、设置轴、为属性添加动画,以及浏览器支持方面的考量。
CSS 排版为 Tailwind CSS 添加 Google Fonts 或自定义字体——扩展 font-family 主题、高效加载字体,以及 Tailwind 排版的最佳实践。
CSS 排版自托管 Google Fonts 能让你完全掌控加载、隐私和缓存。从下载到部署的分步指南。
CSS 排版关于使用 CSS 的 @font-face 加载自定义字体的分步教程——语法、格式选择,以及可直接复制粘贴的实用示例。