Syntax
line-height: number | length | %;Examples
Unitless vs Fixed Line Height
Why unitless values are the recommended approach.
.good {
font-size: 16px;
line-height: 1.5; /* scales to 24px - stays proportional if font-size changes */
}
.risky {
font-size: 16px;
line-height: 24px; /* fixed - breaks proportionally if a child changes font-size */
}Tighter Line Height for Headings
Large headings typically need a tighter line-height than body text.
body { line-height: 1.6; } /* comfortable reading for paragraphs */
h1, h2, h3 { line-height: 1.2; } /* tighter, since large text has more natural spacing already */Parameters and values
- line-height (number | length | %): Vertical space per line; unitless numbers are recommended
Best practices
- Prefer unitless line-height values (like 1.5) over fixed pixel values, so it scales correctly if font-size changes anywhere down the tree
- Use a larger line-height (1.5-1.7) for body copy to improve readability, and a tighter one (1.1-1.3) for large headings
- Set a sensible default line-height on body and let individual elements override it only when needed
- Remember line-height also affects the height of inline elements and can influence vertical centering of single lines of text
At a glance
- Purpose
- Presentation and layout
- File extension
- .css
- Runs in
- Web browsers
- Usually used with
- HTML and JavaScript
Specifications & further reading
Related CSS documentation
Font Properties
Core typography properties control how text is displayed. font-family sets the typeface (with fallbacks), font-size controls size, font-weight controls boldness, font-style controls italics, and the font shorthand can set several of these at once. Well-chosen typography is one of the highest-impact, lowest-effort improvements you can make to a design.Text Properties
Beyond font selection, CSS offers properties to control text alignment, decoration, spacing, and casing. text-align positions text horizontally, text-decoration adds underlines/strikethroughs, text-transform changes casing, and letter-spacing/word-spacing adjust character and word gaps.List Styling
list-style controls how list markers (bullets or numbers) appear on <ul>/<ol> elements. list-style-type sets the marker style, list-style-position controls whether markers sit inside or outside the content box, and list-style: none is the standard way to remove markers entirely, commonly used when repurposing a list for navigation.Flexbox
Flexbox (Flexible Box Layout) is a powerful one-dimensional layout system in CSS that makes it easy to design flexible and responsive layouts. It provides an efficient way to distribute space and align items in a container, even when their sizes are unknown or dynamic. Flexbox is particularly useful for creating navigation bars, card layouts, and centering content.
Core typography properties control how text is displayed. font-family sets the typeface (with fallbacks), font-size controls size, font-weight controls boldness, font-style controls italics, and the font shorthand can set several of these at once. Well-chosen typography is one of the highest-impact, lowest-effort improvements you can make to a design.Text Properties
Beyond font selection, CSS offers properties to control text alignment, decoration, spacing, and casing. text-align positions text horizontally, text-decoration adds underlines/strikethroughs, text-transform changes casing, and letter-spacing/word-spacing adjust character and word gaps.List Styling
list-style controls how list markers (bullets or numbers) appear on <ul>/<ol> elements. list-style-type sets the marker style, list-style-position controls whether markers sit inside or outside the content box, and list-style: none is the standard way to remove markers entirely, commonly used when repurposing a list for navigation.Flexbox
Flexbox (Flexible Box Layout) is a powerful one-dimensional layout system in CSS that makes it easy to design flexible and responsive layouts. It provides an efficient way to distribute space and align items in a container, even when their sizes are unknown or dynamic. Flexbox is particularly useful for creating navigation bars, card layouts, and centering content.