Skip to main content
TailwindCSS Basics
CHAPTER 04 Beginner

Tailwind CSS Typography and Text Utilities

Updated: May 12, 2026
20 min read

# Chapter 4: Tailwind CSS Typography and Text Utilities

Typography is the foundation of web design. How text looks, flows, and scales dictates the readability and overall aesthetic of your website. Tailwind CSS provides a comprehensive set of typography utilities that make it incredibly easy to create beautiful, readable text.

In this chapter, we will explore how to control font sizes, weights, alignment, colors, and line heights using Tailwind's utility classes.

---

1. Introduction

Tailwind approaches typography with carefully curated default scales. Instead of guessing pixel values for font sizes and line heights, you use classes like text-xl or leading-relaxed which are professionally designed to look harmonious.

Tailwind's typography utilities cover everything from the font family to letter spacing, allowing you to construct complex typographic hierarchies directly in your HTML.

2. Learning Objectives

By the end of this chapter, you will be able to:

  • Change text sizes using the text-{size} scale.
  • Adjust font weights using font-{weight} utilities.
  • Control text alignment and text transformation (uppercase, lowercase).
  • Apply text colors and opacities.
  • Manage line-height (leading) and letter-spacing (tracking).

3. Beginner-Friendly Explanations

Font Size and Line Height pairing

In standard CSS, when you increase font size, you often have to manually adjust the line height (line-height) so the text doesn't overlap. Tailwind is smart: when you use a font-size utility like text-3xl, it automatically applies a proportional line-height behind the scenes!

The Naming Conventions

  • Size: Think of t-shirt sizes: sm (small), base (default), lg (large), xl, 2xl, up to 9xl.
  • Weight: Think of standard font weights: light, normal, semibold, bold, extrabold.
  • Line Height: In typography, this is called "leading" (pronounced ledding). So Tailwind uses leading-tight, leading-loose, etc.
  • Letter Spacing: In typography, this is called "tracking". Tailwind uses tracking-tight, tracking-wide.

4. Syntax Explanation

Here are the most common typography scales:

Font Sizes:

  • text-xs (0.75rem / 12px)
  • text-sm (0.875rem / 14px)
  • text-base (1rem / 16px) - *Browser default*
  • text-lg (1.125rem / 18px)
  • text-xl (1.25rem / 20px)
  • text-2xl to text-9xl

Font Weights:

  • font-light (300)
  • font-normal (400)
  • font-medium (500)
  • font-semibold (600)
  • font-bold (700)
  • font-extrabold (800)

Text Alignment:

  • text-left, text-center, text-right, text-justify

5. Real-World Examples

If you look at the header of a modern blog (like Medium or Hashnode), the title is usually large, bold, and tightly spaced. The paragraph text is smaller, lighter, and has a wider line-height for easy reading. <h1 class="text-4xl font-extrabold tracking-tight text-gray-900">...</h1> <p class="text-lg text-gray-600 leading-relaxed">...</p>

6. Multiple Code Examples

Let's explore typography utilities in action.

Example 1: Basic Font Sizes

html
1234567
<!-- TailwindCSS Example -->
<div class="space-y-2">
  <p class="text-xs">Extra small text</p>
  <p class="text-base">Base text (default 16px)</p>
  <p class="text-2xl">2 Extra large text</p>
  <p class="text-4xl">4 Extra large text</p>
</div>

Example 2: Font Weights

html
1234567
<!-- TailwindCSS Example -->
<div class="space-y-2 text-xl">
  <p class="font-light">The quick brown fox (Light)</p>
  <p class="font-normal">The quick brown fox (Normal)</p>
  <p class="font-semibold">The quick brown fox (Semibold)</p>
  <p class="font-extrabold">The quick brown fox (Extrabold)</p>
</div>

Example 3: Text Alignment

html
123456
<!-- TailwindCSS Example -->
<div class="w-64 bg-gray-100 p-4 space-y-4">
  <p class="text-left bg-white border">Left aligned text</p>
  <p class="text-center bg-white border">Centered text</p>
  <p class="text-right bg-white border">Right aligned text</p>
</div>

Example 4: Text Colors

html
1234567
<!-- TailwindCSS Example -->
<div>
  <p class="text-blue-500">Primary Blue Text</p>
  <p class="text-emerald-600">Success Green Text</p>
  <p class="text-red-500">Danger Red Text</p>
  <p class="text-gray-400">Muted Gray Text</p>
</div>

Example 5: Letter Spacing (Tracking)

html
1234567
<!-- TailwindCSS Example -->
<div>
  <p class="tracking-tighter">Tighter letter spacing</p>
  <p class="tracking-normal">Normal letter spacing</p>
  <p class="tracking-widest">Widest letter spacing</p>
  <p class="tracking-[0.2em]">Arbitrary letter spacing</p>
</div>

Example 6: Line Height (Leading)

html
12345
<!-- TailwindCSS Example -->
<div class="w-64 space-y-4">
  <p class="leading-none bg-yellow-100">Line height equal to font size. Very tight. Line height equal to font size. Very tight.</p>
  <p class="leading-relaxed bg-green-100">Relaxed line height. Great for reading long paragraphs on blogs.</p>
</div>

Example 7: Text Decoration

html
123456
<!-- TailwindCSS Example -->
<div class="space-x-4">
  <a href="#" class="underline decoration-blue-500 decoration-2 underline-offset-4">Styled Link</a>
  <span class="line-through text-gray-500">$99.00</span>
  <span class="no-underline">No underline</span>
</div>

Example 8: Text Transformation

html
123456
<!-- TailwindCSS Example -->
<div class="space-y-2">
  <p class="uppercase">this becomes uppercase</p>
  <p class="lowercase">THIS BECOMES LOWERCASE</p>
  <p class="capitalize">this becomes capitalized</p>
</div>

Example 9: Truncating Text (Ellipsis)

If text is too long for its container, Tailwind has a magical truncate class.

html
123456
<!-- TailwindCSS Example -->
<div class="w-48 bg-gray-100 p-2 border">
  <p class="truncate text-gray-800 font-medium">
    This is a very long email subject line that will be cut off with an ellipsis.
  </p>
</div>

Example 10: Font Families

Tailwind provides three default font stacks: Sans (default), Serif, and Mono.

html
123456
<!-- TailwindCSS Example -->
<div>
  <p class="font-sans">Standard sans-serif (Inter, Arial, etc.)</p>
  <p class="font-serif">Serif font (Times New Roman, Georgia)</p>
  <p class="font-mono">Monospace (Courier, Consolas)</p>
</div>

7. Output Explanations

In Example 7, we created a highly customized link. The underline utility adds the line. decoration-blue-500 changes the line's color independently of the text color. decoration-2 makes the underline 2 pixels thick. underline-offset-4 pushes the underline further down away from the text. This creates a very modern, custom link style often seen on premium sites.

8. Common Mistakes

  1. 1. Using heading tags for sizing: Don't use an <h1> just because you want big text. Use semantic HTML (e.g., <p>) and style it with text-4xl.
  1. 2. Ignoring Line Height on custom sizes: If you use an arbitrary font size like text-[40px], Tailwind does *not* automatically apply a line height. You must add it: text-[40px] leading-[48px].
  1. 3. Contrast Issues: Be careful using light text colors (e.g., text-gray-300) on white backgrounds. It creates accessibility/readability issues.

9. Best Practices

  • Hierarchy: Use larger, bolder text for headings (text-2xl font-bold text-gray-900) and standard text with relaxed leading for body paragraphs (text-base text-gray-600 leading-relaxed).
  • Muted Text: Instead of making secondary text smaller, often it looks better to make it a lighter color (text-gray-500).
  • Uppercase aesthetics: When using uppercase, always add letter spacing (tracking-wider or tracking-widest) to make it readable and elegant.

10. Exercises

  1. 1. Create a heading element that is uppercase, bold, has wide letter spacing, and is colored indigo.
  1. 2. Create a paragraph of text restricted to max-w-md that has a relaxed line height.
  1. 3. Use the truncate class on a long string of text inside a small w-32 box.

11. Mini Project: Blog Typography Layout

Let's build a beautiful, readable blog post header and opening paragraph using typographic hierarchy.

html
12345678910111213141516171819202122232425262728293031323334
<!-- TailwindCSS Example: Blog Typography -->
<article class="max-w-2xl mx-auto mt-12 p-6 bg-white rounded-lg shadow-sm border border-gray-100">
  
  <!-- Category Tag -->
  <p class="text-sm font-bold tracking-widest text-indigo-500 uppercase mb-3">
    Web Development
  </p>
  
  <!-- Title -->
  <h1 class="text-4xl md:text-5xl font-extrabold text-slate-900 tracking-tight leading-tight mb-4">
    Mastering Tailwind CSS Typography
  </h1>
  
  <!-- Author Meta -->
  <div class="flex items-center gap-3 mb-8 pb-8 border-b border-gray-100">
    <div class="w-10 h-10 bg-indigo-100 rounded-full flex items-center justify-center text-indigo-700 font-bold">
      JD
    </div>
    <div>
      <p class="text-sm font-semibold text-slate-800">Jane Doe</p>
      <p class="text-xs text-slate-500">Published on Oct 24, 2024</p>
    </div>
  </div>
  
  <!-- Content -->
  <div class="prose prose-slate">
    <p class="text-lg text-slate-600 leading-relaxed mb-6 font-medium">
      Typography is arguably the most critical aspect of user interface design. Even if your layout is perfect, poor typographic choices can ruin the user experience.
    </p>
    <p class="text-base text-slate-600 leading-relaxed">
      In traditional CSS, managing font sizes, line heights, and letter spacing across different screen sizes can be a nightmare. Tailwind&#039;s utility-first approach simplifies this by providing an expertly crafted scale right out of the box. You no longer have to guess what line height pairs well with a 24px font.
    </p>
  </div>
</article>

Output Explanation: Notice how we use text-slate-900 for the main title (very dark, high contrast) but text-slate-600 for the paragraph (softer, easier on the eyes for long reading). The category tag uses uppercase and tracking-widest to look like a premium badge.

12. Coding Challenges

Challenge: Create a "Quote of the Day" component. Use a large, serif font for the quote, make it italic, and use a small, bold sans-serif font for the author's name.

13. MCQs with Answers

Question 1

Which class gives text an ellipsis (...) when it overflows its container?

Question 2

In Tailwind typography, what does leading refer to?

14. Interview Questions

Q: Explain the difference between tracking and leading in Tailwind CSS. *Answer:* tracking controls the CSS letter-spacing property, which dictates the horizontal space between individual characters (e.g., tracking-wide). leading controls the CSS line-height property, which dictates the vertical space between multiple lines of text (e.g., leading-loose).

15. FAQs

Q: Can I add my own custom font (like Google Fonts) to Tailwind? A: Absolutely! You import the font in your HTML or CSS as usual, and then map it to a utility class (like font-custom) inside the theme.extend.fontFamily section of your tailwind.config.js file.

16. Summary

Tailwind's typography utilities provide a complete toolkit for crafting text. By combining text-{size}, font-{weight}, text-{color}, and leading-{size}, you can create sophisticated, readable hierarchies. Using these constrained scales ensures your design remains consistent and visually pleasing without requiring deep knowledge of typographic design principles.

17. Next Chapter Recommendation

Now that our text looks great, it's time to add life to our designs with color. In Chapter 5: Tailwind CSS Colors and Backgrounds, we will dive into Tailwind's massive default color palette, learn how to set background colors, control opacity, and even create modern background gradients.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·