Sub topic 7
Font size utilities and their default line heights
This chapter assumes you know basic HTML, the CSS box model, and CSS units such as px and rem. It also assumes a project with Tailwind CSS installed. You will learn how the text-* size utilities work and why each one also sets a line height.
What a size utility sets
In Tailwind, text-lg does not set only font-size. Each size utility sets two declarations: a font size and a matching line height.
/* What text-lg generates (Tailwind v3 defaults) */
.text-lg {
font-size: 1.125rem;
line-height: 1.75rem;
}The pairing means a size change usually keeps the text readable without a second class. Sizes use rem, so they scale with the user's browser font size.
The default scale
| Class | Font size | Line height |
|---|---|---|
| `text-xs` | 0.75rem (12px) | 1rem (16px) |
| `text-sm` | 0.875rem (14px) | 1.25rem (20px) |
| `text-base` | 1rem (16px) | 1.5rem (24px) |
| `text-lg` | 1.125rem (18px) | 1.75rem (28px) |
| `text-xl` | 1.25rem (20px) | 1.75rem (28px) |
| `text-2xl` | 1.5rem (24px) | 2rem (32px) |
| `text-3xl` | 1.875rem (30px) | 2.25rem (36px) |
| `text-4xl` | 2.25rem (36px) | 2.5rem (40px) |
The scale continues up to text-9xl. Tailwind v4 uses the same sizes but expresses line heights as ratios, so the exact numbers can differ slightly. Check the docs for your version.
Overriding the default line height
The default line height is a starting point. To change it, add a line height utility after the size. In v3 this is a leading-* class, covered in a later chapter. For a one-off, you can also use the slash shorthand, which sets both values in one class (Tailwind v3.3 or later).
<h1 class="text-3xl font-bold leading-tight tracking-tight">Spacing and type</h1>
<p class="text-base/7 text-gray-600">Body copy with a 1.75 line height.</p>text-base/7 means font size base with a line height of 7 on the spacing scale, which is 1.75rem. A bare number like /7 refers to the spacing scale. A value such as /loose refers to a named line height.
How size and line height interact
A line height utility placed in the same class list replaces the line height that the size utility set. The order of classes in the HTML does not decide the winner. Tailwind orders its generated CSS so that leading-* utilities win over the line height that text-* utilities set.
Common errors
- Expecting
text-lgto set only the size. If you addtext-lgto text that had a custom line height from a parent, the line height changes too. Add aleading-*class if you need to keep the old value. - Confusing
text-*for color and size. Bothtext-lgandtext-gray-600use thetext-prefix. Tailwind tells them apart by the value, so one class sets size and the other sets color. - Using the slash shorthand on old versions.
text-base/7fails silently on Tailwind older than v3.3, because no CSS is generated for it. - Using fixed
pxvalues for sizes. Arbitrary values such astext-[18px]ignore the user's browser font size setting. Prefer the scale or aremvalue.
Exercise
A paragraph uses text-xl. You want the same font size but a line height of 2rem. Write the class list using the slash shorthand, and state what line height text-xl sets by default.
Show answer
Use text-xl/8, because 8 on the spacing scale is 2rem. By default text-xl sets a line height of 1.75rem (28px).