# Typography Utilities

> Style text hierarchies with Tailwind font sizes, line height leading, letter spacing tracking, font weights, and line clamping.

Subject: Tailwind CSS | Lesson 7 of 16 | 5 min read
Interactive lesson: https://codewithanimation.in/tailwind/typography-utilities
Previous: [Positioning & Z-Index](https://codewithanimation.in/tailwind/positioning-and-z-index.md) | Next: [Hover, Focus & Active States](https://codewithanimation.in/tailwind/hover-focus-active.md)

## What Typography Utilities in Tailwind are

Typography utilities in Tailwind provide standardized atomic classes for styling body copy, subheadings, hero titles, and UI captions.

Instead of writing custom CSS rules for font sizes and line heights, you compose utilities like `text-2xl`, `font-bold`, `leading-tight`, and `tracking-tight` directly on your headings.

Tailwind v4 also introduces the slash syntax (`text-base/6`), allowing you to set font size and line height together in a single compact token.

## Why standardized typography tokens matter

Unconstrained typography creates visual noise and reduces readability across a web application:

1. **Consistent Hierarchy**: Pre-defined font sizes (`text-xs` through `text-5xl`) enforce visual harmony across pages.

2. **Proportional Line Height**: `leading-tight` and `leading-relaxed` prevent text lines from colliding on mobile screens or spreading too far apart.

3. **Clean Truncation**: Utilities like `truncate` and `line-clamp-2` handle text overflow gracefully without manual JavaScript string slicing.

## How to compose typographic hierarchy

Building typographic scale follows three simple patterns:

1. **Hero Headings**: Combine large size, bold weight, tight leading, and negative tracking: `text-4xl font-extrabold leading-tight tracking-tight text-slate-100`.

2. **Body Copy**: Combine base font size with comfortable line height and crisp contrast: `text-base/relaxed text-slate-200`.

3. **Card Summaries**: Use `line-clamp-2 text-sm text-slate-300` to truncate multi-line descriptions cleanly after two lines.

## Common mistake: The Mismatched Heading Line-Height Mistake

When developers increase font size to `text-4xl` or `text-5xl` without adjusting line height, headings often inherit a default browser line height of 1.5.

This creates huge, ugly gaps between lines of multi-line titles on mobile screens.

Always pair large heading font sizes with `leading-tight` or `leading-none` (or use v4 slash notation like `text-4xl/10`) to keep title lines tightly and gracefully grouped.

## Tip: Leverage Tailwind v4 Slash Modifier Notation

Simplify class strings by combining font size and line height using Tailwind v4's slash notation.

Writing `text-lg/7` sets `font-size: 1.125rem` and `line-height: 1.75rem` in one single token, replacing `text-lg leading-7` and keeping your markup clean.

## Try it: Typographic Specimen Showcase

Examine how Tailwind typography tokens compose font size, line height leading, tracking, and multi-line clamping into clean text hierarchies.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/tailwind/typography-utilities

## Check yourself

### Question 1

In Tailwind CSS v4, what does the class `text-lg/8` configure on a text element?

- A. font-size: 1.125rem (lg) and line-height: 2rem (8)
- B. font-size: 1.125rem and letter-spacing: 8px
- C. font-size: 18px with 8% opacity

Correct answer: A

In Tailwind v4, slash notation after a font size utility (text-lg/8) sets line-height to the specified scale value (leading-8).

- Why not B: The slash modifier sets line-height, not letter-spacing (which uses tracking-*).
- Why not C: Color opacity uses slash notation on colors (text-white/80); on font sizes it sets line height.

### Question 2

What is the primary difference between `truncate` and `line-clamp-2`?

- A. truncate clips text on a single line with an ellipsis; line-clamp-2 allows text to wrap up to two lines before truncating
- B. truncate hides overflow completely without an ellipsis
- C. line-clamp-2 works only in Safari browsers

Correct answer: A

truncate forces single-line white-space: nowrap with ellipsis, while line-clamp-2 allows content to span two full lines before truncating.

- Why not B: truncate includes text-overflow: ellipsis.
- Why not C: line-clamp utilities are cross-browser standard CSS.

### Question 3

Which Tailwind utility family controls CSS `letter-spacing`?

- A. tracking-* (e.g., tracking-tight, tracking-wide)
- B. leading-* (e.g., leading-tight, leading-loose)
- C. spacing-* (e.g., spacing-wide)

Correct answer: A

tracking-* utilities manage letter-spacing (from tracking-tighter to tracking-widest).

- Why not B: leading-* controls line-height.
- Why not C: spacing controls margin/padding scales, not letter-spacing.

## Remember this

- Use text-* for font sizes and font-* for font weights.
- Use leading-* for line height and tracking-* for letter spacing.
- Tailwind v4 slash notation (text-lg/7) combines size and line height in one token.
- Use truncate for 1-line text clipping and line-clamp-2 for card descriptions.
