Font family utilities let you quickly change the style of text by choosing different fonts. This helps make your website look nice and easy to read.
Font family utilities in Tailwind
Start learning this pattern below
Jump into concepts and practice - no test required
font-sans font-serif font-mono
These classes apply different font families: font-sans for sans-serif fonts, font-serif for serif fonts, and font-mono for monospace fonts.
You add these classes to your HTML elements to change their font style.
<p class="font-sans">This text uses a sans-serif font.</p><h1 class="font-serif">This heading uses a serif font.</h1><code class="font-mono">Code looks like this with monospace font.</code>This example shows three text blocks each using a different font family utility from Tailwind CSS. The heading uses serif, the paragraph uses sans-serif, and the code block uses monospace.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Font Family Utilities Example</title> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="p-6"> <h1 class="font-serif text-3xl mb-4">Serif Font Heading</h1> <p class="font-sans text-base mb-4">This paragraph uses a sans-serif font for easy reading.</p> <pre class="font-mono bg-gray-100 p-4 rounded">const x = 10; console.log(x);</pre> </body> </html>
Tailwind's font family utilities use system fonts by default for fast loading and good readability.
You can customize fonts in your Tailwind config if you want special fonts.
Always check font readability on different screen sizes for best user experience.
Font family utilities let you quickly change text fonts using simple classes.
Use font-sans, font-serif, or font-mono to style text.
They help make your website look good and easy to read without writing custom CSS.
Practice
Solution
Step 1: Understand font family classes in Tailwind
Tailwind providesfont-sansfor sans-serif fonts,font-seriffor serif fonts, andfont-monofor monospace fonts.Step 2: Identify the class for sans-serif
The classfont-sansapplies a sans-serif font style to text.Final Answer:
font-sans -> Option BQuick Check:
Sans-serif font class = font-sans [OK]
- Confusing font-serif with sans-serif
- Using font-bold which controls weight, not font family
- Choosing font-mono which is monospace, not sans-serif
Solution
Step 1: Recall monospace font class in Tailwind
Tailwind usesfont-monoto apply monospace fonts, which have equal spacing for each character.Step 2: Confirm the correct class
font-monois the correct class to apply monospace fonts, while others apply serif, sans-serif, or font weight.Final Answer:
font-mono -> Option CQuick Check:
Monospace font class = font-mono [OK]
- Choosing font-serif or font-sans instead of font-mono
- Confusing font-light (weight) with font family
- Missing the monospace meaning of font-mono
<p class="font-serif">Hello World</p>
Solution
Step 1: Identify the class used in the paragraph
The paragraph uses the classfont-serif, which applies a serif font family.Step 2: Understand what serif font means
Serif fonts have small decorative lines at the ends of letters, different from sans-serif or monospace fonts.Final Answer:
Serif font -> Option DQuick Check:
font-serif class = Serif font [OK]
- Thinking font-serif applies sans-serif
- Confusing font-serif with font-mono
- Assuming font-bold changes font family
<h1 class="font-sans-serif">Welcome</h1>
Solution
Step 1: Check the class name validity
The classfont-sans-serifis not a valid Tailwind font family class. Tailwind usesfont-sansfor sans-serif fonts.Step 2: Identify correct class for sans-serif
The correct class to apply a sans-serif font isfont-sans, notfont-sans-serif.Final Answer:
font-sans-serifis not a valid Tailwind class -> Option AQuick Check:
Valid font family classes are font-sans, font-serif, font-mono [OK]
- Adding extra words like '-serif' to font-sans
- Confusing font weight classes with font family
- Assuming font-mono is default for headings
<code class="?">console.log('Hello')</code>Solution
Step 1: Choose monospace font class for code
Code blocks are best styled with monospace fonts, so usefont-mono.Step 2: Select a small readable text size for small screens
Usetext-smfor smaller but readable text size on small devices.Final Answer:
font-mono text-sm -> Option AQuick Check:
Monospace + small text = font-mono text-sm [OK]
- Using font-serif or font-sans for code blocks
- Choosing too large text size for small screens
- Mixing font weight classes instead of font family
