Font Family

    Utilities for controlling the font family of an element.

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


    Hover, focus, and other states

    Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use 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 documentation.

    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. </p>

    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

    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. }

    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. 'sans': ['Exo\\ 2', ...],
    7. }

    Learn more about customizing the default theme in the documentation.

    Providing default font settings

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

    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. <!-- ... -->

    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. }

    You can also customize the default font used in your project by that sets the property explicitly:

    main.css