Menu

CSS Line Height: Unitless Values, px, em and Examples

line-height sets the height of each line of text, and so the space between lines. Learn why a unitless number is the right default, how px, em and % values inherit differently, and good values for body text and headings.

This page includes runnable editors - edit, run, and see output instantly.

What line-height does

line-height sets the height of each line of text. The difference between that height and the height the font itself needs is split in half and added above and below the letters, so it is how you control the space between lines.

All three paragraphs use a 16px font. The lines are 16px, 24px and 32px tall.

Values: unitless, length, percentage, normal

ValueExampleLine height for 16px textInherited by children as
Number1.524pxThe number (1.5), recomputed per element
Length24px, 1.5em, 1.5rem24pxThe computed length (24px)
Percentage150%24pxThe computed length (24px)
normalnormalFrom the font, often about 1.2normal

The first and second rows look the same on one element. The difference only shows when a child has a different font size, which is the next section.

Why unitless is the right default

A 1.5em or 150% line height is turned into pixels on the parent, and children inherit those pixels. A child with a bigger font then gets lines shorter than its letters. A unitless 1.5 is inherited as the number itself and multiplied by each child's own font size.

Both headings wrap to two lines. The first inherits 21px lines for 32px letters, so its lines overlap. The second gets 32 × 1.5 = 48px lines. Set line-height once on body as a number and most pages never need it again.

Try values yourself

Try 1, 2, 30px, 200% and normal. Chrome reports normal as the word itself rather than a pixel value, because its size comes from the font.

Good values for readable text

  • Body text: 1.4 to 1.6. Longer lines need more line height so the eye can find the start of the next line.
  • Headings: 1.1 to 1.3. Large text with 1.5 spacing looks like separate lines rather than one heading.
  • Buttons and single-line labels: 1 to 1.25, with padding for the height.

For accessibility, WCAG success criterion 1.4.12 requires that a page still works when a reader sets line height to 1.5 times the font size, so avoid fixed heights on text boxes that would clip it.

Centering one line of text vertically

When a box holds exactly one line, a line-height equal to the box height puts the text in its vertical middle, because the extra space is split evenly above and below:

It breaks as soon as the text wraps to two lines, because each line is then 40px tall. For anything that can wrap, center with flexbox instead, as shown on the center a div page.

The font shorthand

The font shorthand sets size and line height together with a slash:

body {
  font: 16px/1.5 system-ui, sans-serif; /* size 16px, line-height 1.5 */
}

The shorthand resets every font property it does not mention (including line-height to normal when you leave out the slash part), so write it before any individual font-* rules.

Common mistakes

  • Using em or % on a container. Children inherit a fixed length. Use a unitless number.
  • Fixed height on a text box. When the text wraps or the reader enlarges spacing, it overflows. Let the content set the height.
  • Too tight body text. line-height: 1 makes paragraphs hard to read. Start at 1.5.
  • Expecting line-height to add space between paragraphs. That is margin on the paragraphs.
  • Relying on normal. It changes from font to font, so layouts shift when the font changes.

Frequently Asked Questions

What does line-height do in CSS?

It sets the height of each line box of text. The extra space beyond the font's own height is split evenly above and below the letters, so a bigger line-height means more space between lines.

Should line-height have a unit?

Usually no. A unitless value like 1.5 is multiplied by each element's own font size, so it stays proportional in children with a different size. A value with a unit is computed once and inherited as a fixed length.

What is a good line-height for body text?

Between 1.4 and 1.6 for paragraphs, and around 1.1 to 1.3 for large headings. WCAG's AAA guidance asks for at least 1.5 in paragraphs.

What is line-height: normal?

The default. The browser uses a value from the font's own metrics, typically around 1.2 but different for each font, so it is not predictable across fonts.

How do I change line spacing in HTML?

HTML has no line spacing attribute. Use the CSS property, for example <p style="line-height: 2;"> for double spacing.

Coddy programming languages illustration

Learn to code with Coddy

GET STARTED