CSS line-height Property

The CSS line-height property sets the height of a line box, controlling the vertical spacing between lines of text.

It is an important typography property for improving readability, adjusting text density, and creating consistent spacing in paragraphs, headings, navigation, and other text elements. Line height can be specified using a keyword, unitless number, length, or percentage.

line-height Syntax

The line-height property accepts normal, a unitless number, a length, or a percentage.

Basic Syntax

selector {
  line-height: 1.5;
}

Available Values

.text {
  line-height: normal;
}
.text {
  line-height: 1.5;
}
.text {
  line-height: 24px;
}
.text {
  line-height: 1.5em;
}
.text {
  line-height: 150%;
}

CSS-Wide Keywords

.text {
  line-height: initial;
}
.text {
  line-height: inherit;
}
.text {
  line-height: unset;
}
.text {
  line-height: revert;
}
.text {
  line-height: revert-layer;
}

The initial value is normal. Negative values are invalid, while zero is permitted but generally unsuitable for readable text.

Property Values

Each value determines how the browser calculates the height of a line box.

Value Description
normal Uses a browser-determined line height based on the font and its metrics.
<number> Multiplies the element's font size by a unitless number to determine the used line height.
<length> Specifies a line height using a CSS length such as px, em, or rem.
<percentage> Calculates line height as a percentage of the element's font size.
initial Resets the property to normal.
inherit Uses the computed value from the parent element.
unset Uses the inherited value because the property is inherited.
revert Reverts the property according to cascade origin rules.
revert-layer Reverts the property according to cascade layer rules.

Property Characteristics

Characteristic Value
Initial value normal
Inherited Yes
Applies to All elements
Computed value Specified number, normal, or an absolute length for length and percentage values
Animation type Number or length, according to the value type
Percentages Relative to the element's font size
Negative values Not allowed
Primary purpose Control the height of line boxes

For most body text, unitless values are recommended because they scale naturally when descendant elements use different font sizes.

How It Works

The browser creates line boxes when inline content wraps across multiple lines. The line-height property influences the height of those line boxes and the spacing between text baselines.

Default Line Height

p {
  line-height: normal;
}

The browser calculates an appropriate line height using font metrics and its default behavior.

Increase Line Spacing

p {
  line-height: 1.8;
}

Each line receives more vertical space, making the paragraph appear more open.

Decrease Line Spacing

p {
  line-height: 1.2;
}

Lines appear closer together, which may be useful for large headings but can reduce readability in long paragraphs.

Important Consideration

Line height is not the same as the visible height of individual letters. Fonts contain ascender, descender, and other metrics that affect where glyphs appear inside line boxes.

normal Value

The normal value allows the browser to determine the line height using the font's metrics and its layout rules.

Basic Example

p {
  line-height: normal;
}

Default Heading

h2 {
  line-height: normal;
}

Different Fonts

.serif-text {
  font-family: Georgia, serif;
  line-height: normal;
}
.sans-serif-text {
  font-family: Arial, sans-serif;
  line-height: normal;
}

Different fonts may produce different line heights even when both elements use normal.

Important Consideration

Do not assume that normal always equals 1.2. The actual result depends on the browser and font.

Unitless Values

A unitless number multiplies the element's font size to determine its used line height.

Basic Example

p {
  font-size: 16px;
  line-height: 1.5;
}

The used line height is 24px because 16px × 1.5 = 24px.

Larger Text

h2 {
  font-size: 32px;
  line-height: 1.25;
}

The used line height is 40px.

Inheritance Advantage

.article {
  line-height: 1.5;
}
.article h2 {
  font-size: 32px;
}
.article p {
  font-size: 16px;
}

The heading and paragraph inherit the multiplier 1.5, allowing each element to calculate its line height using its own font size.

Important Consideration

Unitless values are usually the best choice for reusable typography rules because they avoid the inheritance problems associated with fixed or computed length values.

Length Values

A length value specifies line height using a CSS length unit.

Pixel Value

p {
  font-size: 16px;
  line-height: 24px;
}

em Value

p {
  font-size: 16px;
  line-height: 1.5em;
}

The computed line height is 24px.

rem Value

p {
  line-height: 1.5rem;
}

The line height is based on the root element's font size.

Inheritance Behavior

.article {
  font-size: 16px;
  line-height: 24px;
}
.article h2 {
  font-size: 32px;
}

The heading inherits the computed 24px line height unless another value is specified. This may be too small for the larger heading.

Important Consideration

Length values can be useful when a design requires precise line spacing, but unitless values are generally more adaptable for inherited typography.

Percentage Values

A percentage value calculates line height relative to the element's font size.

Basic Example

p {
  font-size: 16px;
  line-height: 150%;
}

The computed line height is 24px.

Larger Percentage

p {
  font-size: 16px;
  line-height: 180%;
}

The computed line height is 28.8px.

Percentage Inheritance

.article {
  font-size: 16px;
  line-height: 150%;
}
.article h2 {
  font-size: 32px;
}

The heading inherits the parent's computed line height of 24px, not the original 150% calculation.

Important Consideration

Percentages and unitless numbers can produce the same line height on the element where they are declared, but they behave differently when inherited.

Inheritance

The line-height property is inherited, but the type of value determines what descendants receive.

Unitless Inheritance

.container {
  line-height: 1.5;
}
.container h2 {
  font-size: 32px;
}

The heading inherits 1.5 and calculates a used line height of 48px.

Length Inheritance

.container {
  line-height: 24px;
}
.container h2 {
  font-size: 32px;
}

The heading inherits 24px.

Percentage Inheritance

.container {
  font-size: 16px;
  line-height: 150%;
}
.container h2 {
  font-size: 32px;
}

The heading inherits the computed line height of 24px.

Explicit Inheritance

.child {
  line-height: inherit;
}

Reset to Initial Value

.child {
  line-height: initial;
}

This resets the property to normal.

Important Consideration

For consistent typography across elements with different font sizes, prefer a unitless value on the parent container.

line-height and font-size

The font-size property controls the size of text, while line-height controls the height of its line boxes.

Small Text

.small-text {
  font-size: 14px;
  line-height: 1.5;
}

The used line height is 21px.

Body Text

.body-text {
  font-size: 16px;
  line-height: 1.6;
}

The used line height is 25.6px.

Large Heading

.heading {
  font-size: 40px;
  line-height: 1.2;
}

The used line height is 48px.

Important Consideration

As font size changes, a unitless line-height value automatically scales the used line height.

Leading and Line Boxes

In typography, leading refers to the space associated with the vertical separation of lines. CSS line height influences this spacing through the line box model.

Font Size and Line Height

p {
  font-size: 16px;
  line-height: 24px;
}

The specified line height is 8px greater than the font size. In the simplified CSS inline formatting model, this difference is distributed around the font's em box.

Tight Leading

h1 {
  font-size: 48px;
  line-height: 1.1;
}

Open Leading

p {
  font-size: 16px;
  line-height: 1.8;
}

Important Consideration

Actual glyph placement depends on font metrics. The visible distance between letters is not necessarily equal to the difference between line-height and font-size.

Typography and Readability

Line height affects how easily readers can follow text from one line to the next.

Body Paragraphs

article p {
  line-height: 1.6;
}

Long-Form Articles

.article-content {
  font-size: 1rem;
  line-height: 1.7;
}

Compact Interface Text

.toolbar-label {
  font-size: 0.875rem;
  line-height: 1.4;
}

Large Display Headings

.display-heading {
  font-size: 3rem;
  line-height: 1.1;
}

Important Consideration

There is no single ideal line-height value for every font or layout. Body text often benefits from more generous line spacing than large headings.

Headings and Paragraphs

Headings and paragraphs often need different line-height values because their font sizes and purposes differ.

Heading Styles

h1 {
  line-height: 1.15;
}
h2 {
  line-height: 1.25;
}
h3 {
  line-height: 1.3;
}

Paragraph Styles

p {
  line-height: 1.6;
}

Article Typography

.article {
  line-height: 1.6;
}
.article h2 {
  line-height: 1.25;
}
.article h3 {
  line-height: 1.3;
}

Spacing Between Elements

Use margin or padding to control spacing between headings and paragraphs. Increasing line-height primarily changes spacing within line boxes, not the intended separation between block elements.

Inline Elements

Inline elements participate in line box construction. Their font sizes, line heights, and vertical alignment can affect the resulting line box.

Inline Emphasis

<p>This paragraph contains <strong>important text</strong> within the same line.</p>

Different Inline Font Sizes

p {
  line-height: 1.5;
}
p strong {
  font-size: 1.25em;
}

Larger inline text can increase the height of a line box.

Inline Images

.inline-icon {
  width: 20px;
  height: 20px;
  vertical-align: middle;
}

Inline images and other replaced elements can affect line box dimensions.

Important Consideration

Setting line-height on a parent does not guarantee that every line box has exactly that height when its contents include larger inline elements.

Vertical Alignment

Line height is sometimes used to vertically center single-line text, but this technique has limitations.

Single-Line Button

.button {
  height: 40px;
  line-height: 40px;
}

This can visually center a single line of text when the font and box dimensions cooperate.

Limitation with Multiple Lines

If the text wraps, a fixed line-height equal to the container height produces excessive spacing and does not correctly center the text block.

Flexbox Alternative

.button {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1.4;
}

Important Consideration

Use Flexbox or Grid for general vertical alignment. Use line-height primarily to control text spacing.

Responsive Typography

Responsive designs can adjust line height to accommodate different font sizes and available widths.

Default Typography

.article-text {
  font-size: 1rem;
  line-height: 1.6;
}

Large Screens

@media (min-width: 992px) {
  .article-text {
    font-size: 1.125rem;
    line-height: 1.7;
  }
}

Responsive Heading

.page-title {
  font-size: clamp(1.75rem, 4vw, 3rem);
  line-height: 1.2;
}

Important Consideration

Unitless values adapt automatically when font sizes change. Media queries are useful when a different line-height ratio is needed for a particular layout.

Accessibility

Appropriate line spacing can improve readability for users with low vision, reading difficulties, or other visual needs.

Readable Body Text

body {
  line-height: 1.5;
}

Avoid Overly Tight Spacing

p {
  line-height: 1;
}

A line height equal to the font size can make multi-line paragraphs difficult to read, especially with fonts that have tall ascenders or descenders.

Support Text Spacing Adjustments

WCAG 2.2 Success Criterion 1.4.12 addresses the ability to increase text spacing without loss of content or functionality. For ordinary paragraphs, users must be able to increase line height to at least 1.5 times the font size without breaking the interface.

Avoid Fixed Heights on Text Containers

.content-box {
  min-height: 120px;
  height: auto;
}

Allowing containers to grow helps prevent text clipping when users increase line spacing.

Important Consideration

Use flexible layouts and test increased text spacing. A design should not depend on a fixed number of text lines fitting inside a rigid container.

line-height Example

This example compares three different line-height values using identical paragraphs.

HTML Example

<div class="line-height-demo">
  <div class="demo-item">
    <h3>line-height: 1.2</h3>
    <p class="demo-text tight">CSS line height controls the vertical spacing between lines of text. Adjusting this value can make paragraphs more compact or easier to read, depending on the font size and available width.</p>
  </div>
  <div class="demo-item">
    <h3>line-height: 1.5</h3>
    <p class="demo-text standard">CSS line height controls the vertical spacing between lines of text. Adjusting this value can make paragraphs more compact or easier to read, depending on the font size and available width.</p>
  </div>
  <div class="demo-item">
    <h3>line-height: 1.8</h3>
    <p class="demo-text spacious">CSS line height controls the vertical spacing between lines of text. Adjusting this value can make paragraphs more compact or easier to read, depending on the font size and available width.</p>
  </div>
</div>

CSS Example

.line-height-demo {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px;
}
.line-height-demo .demo-item {
  padding: 15px;
  border: 1px solid #cbd5e1;
  background-color: #f8fafc;
}
.line-height-demo h3 {
  margin: 0 0 12px;
  font-size: 1rem;
  line-height: 1.3;
}
.line-height-demo .demo-text {
  margin: 0;
  font-size: 16px;
}
.line-height-demo .tight {
  line-height: 1.2;
}
.line-height-demo .standard {
  line-height: 1.5;
}
.line-height-demo .spacious {
  line-height: 1.8;
}
Browser Result

line-height: 1.2

CSS line height controls the vertical spacing between lines of text. Adjusting this value can make paragraphs more compact or easier to read, depending on the font size and available width.

line-height: 1.5

CSS line height controls the vertical spacing between lines of text. Adjusting this value can make paragraphs more compact or easier to read, depending on the font size and available width.

line-height: 1.8

CSS line height controls the vertical spacing between lines of text. Adjusting this value can make paragraphs more compact or easier to read, depending on the font size and available width.

The first paragraph has tight line spacing, the second has moderate spacing, and the third has more generous spacing. Each paragraph uses the same font size.

Change to a Fixed Length

.line-height-demo .standard {
  line-height: 24px;
}

At a font size of 16px, this produces the same used line height as 1.5.

Change to a Percentage

.line-height-demo .standard {
  line-height: 150%;
}

This also produces a computed line height of 24px for the example paragraph.

Common Mistakes

Confusing line-height with font-size

font-size controls text size. line-height controls line box height.

Using Fixed Line Heights on Parent Elements

.article {
  line-height: 20px;
}

Descendants with larger fonts may inherit an unsuitable fixed line height.

Assuming Percentages Inherit Like Unitless Numbers

Percentages compute to lengths before inheritance. Unitless numbers retain their multiplier.

Using Negative Values

p {
  line-height: -1.5;
}

Negative line-height values are invalid.

Using Excessively Small Values

p {
  line-height: 0.8;
}

Very small values can cause lines of text to overlap.

Using line-height for Paragraph Spacing

Use margins to separate paragraphs. Line height controls spacing within line boxes.

Assuming normal Is a Fixed Multiplier

The browser determines normal using font metrics and layout rules.

Using line-height for General Vertical Centering

A fixed line height may center single-line text, but Flexbox or Grid is more reliable for multi-line content.

Ignoring Inline Content

Large inline text, images, and other inline elements can increase line box height.

Clipping Text with Fixed Heights

Containers with fixed heights and hidden overflow can clip text when line spacing increases.

Assuming Every Font Looks Identical

Fonts have different metrics, so the same line-height value may produce different visual spacing.

Important Considerations

Keep the following points in mind when using line-height:

  • The property controls the height of line boxes.
  • The initial value is normal.
  • The property is inherited.
  • It accepts normal, numbers, lengths, and percentages.
  • Negative values are invalid.
  • Zero is valid but can cause overlapping text.
  • Unitless values multiply the element's font size.
  • Unitless values retain their multiplier when inherited.
  • Length values compute to absolute lengths.
  • Percentage values compute relative to the element's font size.
  • Percentages inherit as computed lengths.
  • Unitless values are generally recommended for body typography.
  • The normal value depends on font metrics and browser behavior.
  • Line height does not change the font size.
  • Line height does not directly control paragraph margins.
  • Different fonts can produce different visual spacing.
  • Large inline elements may increase line box height.
  • Headings often use tighter line spacing than body paragraphs.
  • Long-form text may benefit from more generous line spacing.
  • Responsive typography can use unitless values and media queries.
  • Fixed line heights can create inheritance problems.
  • Very small line heights can cause text overlap.
  • Fixed-height containers may clip text when spacing increases.
  • Flexbox and Grid are preferable for general vertical alignment.
  • Accessible layouts should accommodate increased text spacing.
  • The property can be animated between compatible numeric or length values.
  • Test typography using the actual fonts and content on the page.

Browser Support

The CSS line-height property is widely supported across modern browsers, including Chrome, Edge, Firefox, Safari, and Opera.

Basic support for normal, unitless numbers, lengths, and percentages is well established. The exact appearance of normal can vary because of font metrics and browser text layout behavior.

For current compatibility information, visit Can I Use? and search for line-height.

Specifications

The line-height property is defined in the CSS Inline Layout Module Level 3 specification.

CSS Inline Layout Module Level 3: line-height

The specification defines line height, inline formatting, and how line boxes are constructed.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: line-height