Sub topic 9
Line height (leading) and letter spacing (tracking)
This chapter assumes you know how Tailwind's font size utilities such as text-xl work, including the default line height each one sets. It also assumes you can read a class list like text-sm font-medium. Here you will learn how to override the vertical rhythm of text with leading-* and the horizontal rhythm with tracking-*.
Two names for two CSS properties
Tailwind uses typographers' terms for these utilities:
| Term | CSS property | Utility prefix |
|---|---|---|
| Leading | `line-height` | `leading-*` |
| Tracking | `letter-spacing` | `tracking-*` |
Leading is the distance from one baseline to the next. Tracking is the uniform space added between all characters. Neither one changes the font size.
Leading utilities
Tailwind offers two kinds of leading-* values: named ratios and fixed lengths.
Named, relative values
The named values are unitless multipliers. A unitless line-height is multiplied by the element's own font size, so the result scales when the text size changes.
| Class | CSS | Typical use |
|---|---|---|
| `leading-none` | `line-height: 1` | Single-line display text, badges |
| `leading-tight` | `line-height: 1.25` | Large headings |
| `leading-snug` | `line-height: 1.375` | Subheadings, short paragraphs |
| `leading-normal` | `line-height: 1.5` | Default body text |
| `leading-relaxed` | `line-height: 1.625` | Long-form reading |
| `leading-loose` | `line-height: 2` | Rare. Very airy text |
Fixed values
leading-3 through leading-10 set absolute line heights that do not depend on font size. In Tailwind v3 these are 0.75rem through 2.5rem in steps of 0.25rem, so leading-6 is 1.5rem. In v4 the number is multiplied by the spacing variable, so leading-6 is calc(var(--spacing) * 6), which is also 1.5rem by default.
<p class="text-sm leading-5">Fixed 1.25rem line height</p>
<p class="text-sm leading-relaxed">1.625 times the font size</p>At text-sm (0.875rem) the second paragraph computes to about 1.42rem. If you change it to text-lg, the relative value grows with the text and the fixed one stays put.
Why a fixed value can surprise you
A unitless line height inherits as a number. Each descendant multiplies that number by its own font size. A fixed line height inherits as a computed length. Every descendant gets the same length, whatever its font size.
<div class="leading-6">
<p>Body text inherits 1.5rem and looks fine.</p>
<h2 class="text-3xl">This heading also inherits 1.5rem</h2>
</div>The heading is 1.875rem tall in the default v3 scale, but its lines are only 1.5rem apart. A wrapped heading will have overlapping lines. Tailwind's text-* utilities avoid this because each one sets its own line height. A plain <h2> without a text-* class takes the value from Preflight (Tailwind's base reset), which sets line-height: inherit on headings.
Use these rules to avoid the problem:
- Put
leading-*on the same element as thetext-*class that sizes it. - Prefer named ratios on containers that hold mixed font sizes.
- Reserve fixed values for text where you control the size, such as buttons and form labels.
How leading interacts with font size classes
Every text-* size utility sets both font-size and a default line-height. In the default theme, text-sm pairs with 1.25rem and text-base with 1.5rem. A leading-* class overrides that default. Tailwind generates the leading-* rules after the text-* size rules, so the order of classes in your class attribute does not matter.
<h1 class="text-4xl leading-tight font-bold">Tight heading</h1>Here text-4xl supplies font-size: 2.25rem (v3) and leading-tight replaces its line height with 1.25.
You can also set both in one class with the slash shorthand:
<p class="text-base/7">16px text on a 1.75rem line</p>
<p class="text-sm/6">14px text on a 1.5rem line</p>The part after the slash accepts spacing-scale numbers and also named values such as text-lg/tight. It needs Tailwind v3.3 or later. Use the shorthand when you want the line height to travel with the size, for example inside a responsive variant: text-base/7 md:text-lg/8.
Tracking utilities
Tracking values are in em, so they scale with the element's font size. A tracking of 0.05em on 16px text adds 0.8px between letters. On 48px text it adds 2.4px.
| Class | CSS |
|---|---|
| `tracking-tighter` | `letter-spacing: -0.05em` |
| `tracking-tight` | `letter-spacing: -0.025em` |
| `tracking-normal` | `letter-spacing: 0em` |
| `tracking-wide` | `letter-spacing: 0.025em` |
| `tracking-wider` | `letter-spacing: 0.05em` |
| `tracking-widest` | `letter-spacing: 0.1em` |
Common patterns:
- Large headings often look better slightly tightened, with
tracking-tight. The default letter gaps in many fonts feel loose at display sizes. - Small uppercase labels look better opened up, with
uppercase tracking-widerortracking-widest. - Body text should stay at
tracking-normal. Adding positive tracking to lowercase paragraphs usually slows reading.
<div class="max-w-md p-6">
<p class="text-xs font-semibold uppercase tracking-widest text-gray-500">
Release notes
</p>
<h2 class="mt-2 text-4xl font-bold leading-tight tracking-tight">
What changed in version 2
</h2>
<p class="mt-4 text-base leading-relaxed text-gray-600">
A longer description that benefits from extra room between lines,
so the eye can find the start of each new line easily.
</p>
</div>Each text role has its own leading and tracking. The label is opened up, the heading is tightened, and the body has open leading with default tracking.
Choosing values
A rule of thumb is that the larger the text, the smaller the leading ratio. Small text needs more relative space between lines so the lines stay distinct. Large text already has big gaps in absolute terms.
Treat these as starting points and check them with your actual font. Fonts with a large x-height, which means tall lowercase letters, need more leading than fonts with a small one.
Responsive and state variants
Leading and tracking work with any variant. A common pattern is to loosen leading on larger screens, where lines are longer and the reader needs more help finding the next line:
<p class="text-base leading-normal md:text-lg md:leading-relaxed">
Text with more relaxed leading from the md breakpoint upward.
</p>Tracking can change the same way. A heading might use tracking-normal on small screens and md:tracking-tight once the type size grows.
Arbitrary values and theme changes
When the named scale lacks what you need, use square brackets:
<h1 class="text-5xl leading-[1.1] tracking-[-0.03em]">Custom display style</h1>
<p class="text-xs tracking-[0.2em] uppercase">Wide label</p>A unitless value like leading-[1.1] is a ratio. A value with a unit, like leading-[22px], is fixed, with the inheritance behavior described above. If you repeat the same arbitrary value in several places, add it to the theme instead.
In Tailwind v3, extend lineHeight and letterSpacing:
// tailwind.config.js (Tailwind v3)
module.exports = {
theme: {
extend: {
lineHeight: {
heading: '1.1',
},
letterSpacing: {
label: '0.15em',
},
},
},
}In Tailwind v4, define variables in @theme:
/* app.css (Tailwind v4) */
@import "tailwindcss";
@theme {
--leading-heading: 1.1;
--tracking-label: 0.15em;
}Both versions give you leading-heading and tracking-label. The later chapter on theme customization covers this in more detail.
Common errors
- Overlapping wrapped lines. A fixed
leading-*value is smaller than the font size on some descendant. Use a named ratio, or move the class to the element that sets the size. - Cut-off descenders. Combining
leading-noneor a very small ratio withline-clamp-*ortruncatecan clip letters such as g and y, because those utilities hide overflow. Use at leastleading-tightfor clamped text. - Leading seems ignored. The element has a
text-*/valueshorthand later in the same variant, or a more specific rule from your own CSS wins. Inspect the computedline-heightin your browser's dev tools. - Tracking looks different on each element. Tracking is in
em, so identical classes on different font sizes produce different pixel gaps. This is the intended behavior. - Mixed up with spacing.
leading-*does not add margin or padding. If you want more space between paragraphs, usemt-*orspace-y-*.
Exercises
Exercise
A container has class="leading-6". Inside it is <h2 class="text-4xl">A long heading that wraps</h2>. In Tailwind's default setup, which line height does the heading use, and why?
Show answer
The text-4xl class sets its own line height, so the heading uses that default (2.5rem in v3) and the container's leading-6 does not affect it. If the heading had no text-* class, Preflight's line-height: inherit would give it the container's fixed 1.5rem, and the wrapped lines would be too close.
Exercise
Write the classes for a label with 12px text, uppercase letters, and extra letter spacing of 0.1em, followed by a heading with text-3xl, a 1.25 line height, and slightly tightened letters.
Show answer
Label: text-xs uppercase tracking-widest. Heading: text-3xl leading-tight tracking-tight. tracking-widest is 0.1em, leading-tight is 1.25, and tracking-tight is -0.025em.