font-family

Các tiện ích để kiểm soát font family của một phần tử.

ClassStyles
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>;

Ví dụ

Ví dụ cơ bản

Sử dụng các tiện ích như font-sansfont-mono để đặt font family của một phần tử:

font-sans

The quick brown fox jumps over the lazy dog.

font-serif

The quick brown fox jumps over the lazy dog.

font-mono

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>

Sử dụng giá trị tùy chỉnh

Use the font-[<value>] syntax to set the font family based on a completely custom value:

<p class="font-[Open_Sans] ...">  Lorem ipsum dolor sit amet...</p>

For CSS variables, you can also use the font-(family-name:<custom-property>) syntax:

<p class="font-(family-name:--my-font) ...">  Lorem ipsum dolor sit amet...</p>

This is just a shorthand for font-[family-name:var(<custom-property>)] that adds the var() function for you automatically.

Responsive design

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 ...">  Lorem ipsum dolor sit amet...</p>

Learn more about using variants in the variants documentation.

Tùy chỉnh theme của bạn

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>

Bạn cũng có thể cung cấp các giá trị mặc định font-feature-settingsfont-variation-settings cho một font family:

@theme {  --font-display: "Oswald", sans-serif;  --font-display--font-feature-settings: "cv02", "cv03", "cv04", "cv11";   --font-display--font-variation-settings: "opsz" 32; }

Nếu cần, hãy sử dụng at-rule @font-face để tải các phông chữ tùy chỉnh:

@font-face {  font-family: Oswald;  font-style: normal;  font-weight: 200 700;  font-display: swap;  src: url("/fonts/Oswald.woff2") format("woff2");}

Nếu bạn đang tải phông chữ từ một dịch vụ như Google Fonts, hãy đảm bảo đặt @import ở ngay đầu file CSS của bạn:

@import url("https://fonts.googleapis.com/css2?family=Roboto&display=swap");@import "tailwindcss";@theme {  --font-roboto: "Roboto", sans-serif; }

Các trình duyệt yêu cầu các câu lệnh @import phải đứng trước bất kỳ quy tắc nào khác, vì vậy các import URL cần phải nằm trên các import như @import "tailwindcss", vốn được inline trong CSS đã biên dịch.

Learn more about customizing your theme in the theme documentation.

Copyright © 2025 Tailwind Labs Inc.·Chính sách thương hiệu