Typography
Utilities for controlling the font family of an element.
Class | Styles |
---|---|
font-sans | font-family: var(--font-sans); /* ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji' */ |
font-serif | font-family: var(--font-serif); /* ui-serif, Georgia, Cambria, 'Times New Roman', Times, serif */ |
font-mono | font-family: var(--font-mono); /* ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace */ |
font-(family-name:<custom-property>) | font-family: var(<custom-property>); |
font-[<value>] | font-family: <value>; |
Use utilities like font-sans
and font-mono
to set the font family of an element:
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
<p class="font-sans ...">The quick brown fox ...</p><p class="font-serif ...">The quick brown fox ...</p><p class="font-mono ...">The quick brown fox ...</p>
Use the font-[<value>]
syntax to set the font family based on a completely custom value:
<p class="font-[Open_Sans] ..."> <!-- ... --></p>
For CSS variables, you can also use the font-(family-name:<custom-property>)
syntax:
<p class="font-(family-name:--my-font) ..."> <!-- ... --></p>
This is just a shorthand for font-[family-name:var(<custom-property>)]
that adds the var()
function for you automatically.
Prefix a font-family
utility with a breakpoint variant like md:
to only apply the utility at medium screen sizes and above:
<p class="font-sans md:font-serif ..."> <!-- ... --></p>
Learn more about using variants in the variants documentation.
Use the --font-*
theme variables to customize the font family utilities in your project:
@theme { --font-display: "Oswald", "sans-serif"; }
Now the font-display
utility can be used in your markup:
<div class="font-display"> <!-- ... --></div>
You can also provide default font-feature-settings
and font-variation-settings
values for a font family:
@theme { --font-display: "Oswald", "sans-serif"; --font-display--font-feature-settings: "cv02", "cv03", "cv04", "cv11"; --font-display--font-variation-settings: "opsz" 32; }
If needed, use the @font-face at-rule to load custom fonts:
@font-face { font-family: Oswald; font-style: normal; font-weight: 200 700; font-display: swap; src: url("/fonts/Oswald.woff2") format("woff2");}
If you're loading a font from a service like Google Fonts, make sure to put the @import
at the very top of your CSS file:
@import url("https://fonts.googleapis.com/css2?family=Roboto&display=swap");@import "tailwindcss";@theme { --font-roboto: "Roboto", sans-serif; }
Browsers require that @import
statements come before any other rules, so URL imports need to be above imports like @import "tailwindcss"
which are inlined in the compiled CSS.
Learn more about customizing your theme in the theme documentation.
Tailwind CSS 中文网(本网站)的目标是为中文开发者提供准确、及时的 Tailwind CSS 中文文档
Tailwind CSS 中文文档由本网站维护人员共同翻译,采用 MIT 开源协议发布
本网站与 tailwindcss.com 及 Tailwind Labs Inc. 并无从属关系
Tailwind 商标由 Tailwind Labs Inc. 所有
京ICP备15031610号-8