Typography

Font Family

Utilities for controlling the font family of an element.

Quick reference

Class
Properties
font-sansfont-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, “Segoe UI”, Roboto, “Helvetica Neue”, Arial, “Noto Sans”, sans-serif, “Apple Color Emoji”, “Segoe UI Emoji”, “Segoe UI Symbol”, “Noto Color Emoji”;
font-seriffont-family: ui-serif, Georgia, Cambria, “Times New Roman”, Times, serif;
font-monofont-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, “Liberation Mono”, “Courier New”, monospace;

Basic usage

Setting the font family

You can control the typeface of text using the font family utilities.

Font Family - 图1

  1. <p class="font-sans ...">The quick brown fox ...</p>
  2. <p class="font-serif ...">The quick brown fox ...</p>
  3. <p class="font-mono ...">The quick brown fox ...</p>

Applying conditionally

Hover, focus, and other states

Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:font-serif to only apply the font-serif utility on hover.

  1. <p class="font-sans hover:font-serif">
  2. <!-- ... -->
  3. </p>

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

Breakpoints and media queries

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:font-serif to apply the font-serif utility at only medium screen sizes and above.

  1. <p class="font-sans md:font-serif">
  2. <!-- ... -->
  3. </p>

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.


Using custom values

Customizing your theme

By default, Tailwind provides three font family utilities: a cross-browser sans-serif stack, a cross-browser serif stack, and a cross-browser monospaced stack. You can change, add, or remove these by editing the theme.fontFamily section of your Tailwind config.

tailwind.config.js

  1. module.exports = {
  2. theme: {
  3. fontFamily: {
  4. 'sans': ['ui-sans-serif', 'system-ui', ...],
  5. 'serif': ['ui-serif', 'Georgia', ...],
  6. 'mono': ['ui-monospace', 'SFMono-Regular', ...],
  7. 'display': ['Oswald', ...],
  8. 'body': ['"Open Sans"', ...],
  9. }
  10. }
  11. }

Font families can be specified as an array or as a simple comma-delimited string:

  1. {
  2. // Array format:
  3. 'sans': ['Helvetica', 'Arial', 'sans-serif'],
  4. // Comma-delimited format:
  5. 'sans': 'Helvetica, Arial, sans-serif',
  6. }

Note that Tailwind does not automatically escape font names for you. If you’re using a font that contains an invalid identifier, wrap it in quotes or escape the invalid characters.

  1. {
  2. // Won't work:
  3. 'sans': ['Exo 2', ...],
  4. // Add quotes:
  5. 'sans': ['"Exo 2"', ...],
  6. // ...or escape the space:
  7. 'sans': ['Exo\\ 2', ...],
  8. }

Learn more about customizing the default theme in the theme customization documentation.

Providing default font-feature-settings

You can optionally provide default font-feature-settings for each font in your project using a tuple of the form [fontFamilies, { fontFeatureSettings }] when configuring custom fonts.

tailwind.config.js

  1. module.exports = {
  2. theme: {
  3. fontFamily: {
  4. sans: [
  5. "Inter var, sans-serif",
  6. { fontFeatureSettings: '"cv11", "ss01"' },
  7. ],
  8. },
  9. },
  10. }

Arbitrary values

If you need to use a one-off font-family value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value.

  1. <p class="font-['Open_Sans']">
  2. <!-- ... -->
  3. </p>

Learn more about arbitrary value support in the arbitrary values documentation.

Customizing the default font

For convenience, Preflight sets the font family on the html element to match your configured sans font, so one way to change the default font for your project is to customize the sans key in your fontFamily configuration:

tailwind.config.js

  1. const defaultTheme = require('tailwindcss/defaultTheme')
  2. module.exports = {
  3. theme: {
  4. extend: {
  5. fontFamily: {
  6. 'sans': ['Proxima Nova', ...defaultTheme.fontFamily.sans],
  7. },
  8. }
  9. }
  10. }

You can also customize the default font used in your project by adding a custom base style that sets the font-family property explicitly:

main.css

  1. @tailwind base;
  2. @tailwind components;
  3. @tailwind utilities;
  4. @layer base {
  5. html {
  6. font-family: Proxima Nova, system-ui, sans-serif;
  7. }
  8. }

This is the best approach if you have customized your font family utilities to have different names and don’t want there to be font-sans utility available in your project.