Support0

CSS line-height playground

Explore line-height with controls for comparing normal, unitless values, rem lengths, and percentages on a real text block.

Ask AI

CSS line-height playground

Response generated with openai/gpt-5.4-nano. AI can make mistakes. Always review the result.

BaselineLab lets you compare line-height with real text, long lines and a block narrow enough to reveal changes in vertical rhythm. Try normal, unitless numbers, rem lengths and percentages before copying the CSS.

HTML
<p class="line-height-sample">
  BaselineLab lets you compare line-height with real text,
  long lines and a block narrow enough to reveal changes in vertical rhythm.
  Try normal, unitless numbers, rem lengths and percentages before copying the CSS.
</p>
Tailwind CSS
Examples for Tailwind CSS 4.3 with the default theme. Custom values keep arbitrary classes when there is no equivalent utility. Changing the theme can change utility values.
<p class="max-w-xl text-lg leading-normal">
  BaselineLab lets you compare line-height with real text,
  long lines and a block narrow enough to reveal changes in vertical rhythm.
  Try normal, unitless numbers, rem lengths and percentages before copying the CSS.
</p>
CSS
.line-height-sample {
  max-inline-size: 36rem;
  font-size: 1.125rem;
  line-height: 1.5;
}

Educational guide to line-height

Give each line room

Compare factors, percentages, and lengths. Follow the inherited value and let text grow without clipping.

Mental model

line-height contributes to line box size. In horizontal writing it controls their height; in vertical writing, their width. It does not change nominal letter size or equal the visible empty space between letters.

  1. Font and size

    font-size scales the font; accents, ascenders, and descenders can occupy different heights across families.

  2. Room for the line

    In a text block, line-height contributes a minimum height to each horizontal line. Inline content can make it grow.

  3. Lines inside the block

    More lines or larger line spacing make an automatically sized block grow. margin and padding handle spacing outside and inside its box.

Static diagram of a line of textA line brings together letters and aligned inline boxes. Its final size also depends on the content and font metrics, rather than just a number declared on the paragraph.

normal, factors, and lengths

normal leaves calculation to the browser and font: it is not a constant equal to 1.2. A unitless number multiplies the element’s font-size. A percentage or em also starts from that font size but computes to a length; rem uses the root.

The same font with five values

normal

Trees and pages
to keep reading

1.5

Trees and pages
to keep reading

150%

Trees and pages
to keep reading

1.5em

Trees and pages
to keep reading

1.5rem

Trees and pages
to keep reading

With a 16 px root, 1.25rem letters have a nominal size of 20 px. 1.5, 150%, and 1.5em give 30 px line spacing; 1.5rem gives 24 px. normal depends on the browser and font. Narrow screens may produce more than two lines.
The same font with five values
<div class="line-height-guide-values">
  <div>
    <p class="label">normal</p>
    <p class="sample normal">Trees and pages<br>to keep reading</p>
  </div>
  <div>
    <p class="label">1.5</p>
    <p class="sample number">Trees and pages<br>to keep reading</p>
  </div>
  <div>
    <p class="label">150%</p>
    <p class="sample percent">Trees and pages<br>to keep reading</p>
  </div>
  <div>
    <p class="label">1.5em</p>
    <p class="sample em">Trees and pages<br>to keep reading</p>
  </div>
  <div>
    <p class="label">1.5rem</p>
    <p class="sample rem">Trees and pages<br>to keep reading</p>
  </div>
</div>
.line-height-guide-values {
  display: grid;
  gap: 1.5rem;
  overflow-wrap: anywhere;

  .label {
    margin-block: 0 0.5rem;
    font-size: 1rem;
    line-height: 1.5;
  }

  .sample {
    margin: 0;
    font-size: 1.25rem;
  }

  .normal {
    line-height: normal;
  }

  .number {
    line-height: 1.5;
  }

  .percent {
    line-height: 150%;
  }

  .em {
    line-height: 1.5em;
  }

  .rem {
    line-height: 1.5rem;
  }
}

px and other lengths are valid too, but keep a computed distance when inherited. Numbers, lengths, and percentages accept zero and positive values, not negatives. A valid value can be too small to read without overlap.

What actually inherits

1.5 inherits as a factor, applied to each child’s size. 150% and 1.5em compute where they are declared; descendants inherit that length. Explicitly using inherit preserves this behavior.

A 1.125rem parent and a 1.5rem child

1.5 · Parent font

Child text
to keep reading

150% · Parent font

Child text
to keep reading

1.5em · Parent font

Child text
to keep reading

1.5rem · Parent font

Child text
to keep reading

With a 16 px root, the parent font is 18 px and the child font is 24 px. The child inherits 1.5 and uses 36 px; with 150% or 1.5em it inherits 27 px; with 1.5rem it inherits 24 px. No child redeclares the original factor or percentage.
A 1.125rem parent and a 1.5rem child
<div class="line-height-guide-inheritance">
  <div class="parent number">
    <p>1.5 · Parent font</p>
    <p class="child">Child text<br>to keep reading</p>
  </div>
  <div class="parent percent">
    <p>150% · Parent font</p>
    <p class="child">Child text<br>to keep reading</p>
  </div>
  <div class="parent em">
    <p>1.5em · Parent font</p>
    <p class="child">Child text<br>to keep reading</p>
  </div>
  <div class="parent rem">
    <p>1.5rem · Parent font</p>
    <p class="child">Child text<br>to keep reading</p>
  </div>
</div>
.line-height-guide-inheritance {
  display: grid;
  gap: 1.5rem;
  overflow-wrap: anywhere;

  .parent {
    font-size: 1.125rem;
  }

  p {
    margin-block: 0 1rem;
    line-height: inherit;
  }

  .child {
    font-size: 1.5rem;
  }

  .number {
    line-height: 1.5;
  }

  .percent {
    line-height: 150%;
  }

  .em {
    line-height: 1.5em;
  }

  .rem {
    line-height: 1.5rem;
  }
}

Declaring 150% directly on the child calculates it from that child’s font and changes the result. Unlike font-size: 150%, a line-height percentage uses the font of the element where it is declared. A unitless factor is usually more predictable for components with several text sizes.

The line box can grow

A larger word, an inline image, or different alignment can enlarge a line. The paragraph’s line-height does not fix every line’s total height or clip ink that extends beyond the metrics.

A larger word on the first line

Uniform text

Tree and text on the same line
to keep reading

A larger span

Tree and text on the same line
to keep reading

Both paragraphs have a 1rem font and 1.5 line-height. In the second, the span uses 2em and line-height: 1; its contribution can enlarge the first line. Borders mark the entire block, not individual line boxes or glyph outlines.
A larger word on the first line
<div class="line-height-guide-inline">
  <div>
    <p class="label">Uniform text</p>
    <p class="sample">Tree and text on the same line<br>to keep reading</p>
  </div>
  <div>
    <p class="label">A larger span</p>
    <p class="sample"><span class="large">Tree</span> and text on the same line<br>to keep reading</p>
  </div>
</div>
.line-height-guide-inline {
  display: grid;
  gap: 1.5rem;
  font-size: 1rem;
  line-height: 1.5;
  overflow-wrap: anywhere;

  .label {
    margin-block: 0 0.5rem;
  }

  .sample {
    margin: 0;
    border-block: 1px solid currentColor;
  }

  .large {
    font-size: 2em;
    line-height: 1;
  }
}

The explicit break makes comparison easier, but text may wrap earlier on mobile. Do not assume a paragraph’s height equals line count × line-height when it mixes sizes, fonts, or inline elements. Test the fallback font too.

Reading and user preferences

For paragraphs, start with a unitless factor of at least 1.5 and adjust it to the font, size, and line length. Paragraph spacing is controlled separately. A box that can grow preserves content when spacing increases.

A block that grows with its text

Reading at a steady pace means distinguishing one line from the next. Proportional line spacing helps you follow the words when text runs across several lines.

Space between paragraphs signals a new idea. Let the box grow when letter size or available width changes.

Read the WCAG text spacing criterion
Body text uses line-height: 1.6, a maximum width of 60ch, and margins between paragraphs. There is no fixed height or clipping. Enlarging text or changing spacing keeps the link after all the content.
A block that grows with its text
<div class="line-height-guide-reading">
  <p>Reading at a steady pace means distinguishing one line from the next. Proportional line spacing helps you follow the words when text runs across several lines.</p>
  <p>Space between paragraphs signals a new idea. Let the box grow when letter size or available width changes.</p>
  <a href="https://www.w3.org/WAI/WCAG22/Understanding/text-spacing.html">Read the WCAG text spacing criterion</a>
</div>
.line-height-guide-reading {
  max-inline-size: 60ch;
  font-size: 1rem;
  line-height: 1.6;
  overflow-wrap: anywhere;

  p {
    margin-block: 0 1em;
  }
}

WCAG 2.2, 1.4.12 requires content and functionality to remain available when the user jointly sets line height to 1.5 times the font size, paragraph spacing to 2 times, letter spacing to 0.12 times, and word spacing to 0.16 times. It does not require these as the design’s initial values or require custom controls. Setting line-height: 1.5 alone does not establish conformance.

Clipping and the relationship with text-box

If a heading leaves space above capitals or below its last line, reducing line-height also affects the rhythm between lines. text-box can adjust the block’s outer edges to chosen metrics while retaining spacing between its interior lines.

line-height: 1 or 0 does not magically remove font metrics. It can leave accents and descenders outside the box or bring lines too close together. Clipping overflow or a fixed height can hide that ink and additional content.

Allow automatic height and wrapping, and check text at 200%, reflow at 320 CSS pixels, and custom spacing. Review accents, descenders, translations, and fallback fonts. The text-box guide offers a specific comparison and explains its separate support.

See line spacing and block edges in the text-box guide

Common pitfalls

A subheading inherits cramped lines

Expected result
Line spacing follows each text size.
Cause
A percentage or length was computed from the parent’s smaller font and inherited without recalculation.
Solution
Use a unitless factor on the ancestor or declare the relative value directly on the element whose size changes.

Letters on neighboring lines overlap

Expected result
Accents and descenders remain distinct from the neighboring line.
Cause
A value that is too low reserves less room than that font’s ink needs.
Solution
Increase line spacing and review real text. For aligning a heading’s outer edges, see text-box and its fallback.

Custom spacing hides the end

Expected result
All text and links remain available.
Cause
A fixed height or clipping limits the block as line count and spacing increase.
Solution
Let content grow and remove clipping that hides it; check size and spacing together.

Support and compatibility

The line-height values used here are Baseline Widely Available. normal does not promise the same result across fonts, systems, or browsers. text-box support is assessed separately.

Examples show real browser layout without measuring or simulating lines with JavaScript. A computed-style reading does not certify readability, unclipped ink, or user preferences: also check the visual result and navigation.