Line height and spacing
Definition and purpose
Line height controls line-box spacing; letter-spacing and word-spacing adjust spacing within text. Unitless line height is often useful because descendants multiply it by their own font size.
Unitless inheritance
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> #a { font-size: 16px; line-height: 1.5; } #b { font-size: 24px; } </style> </head> <body> <div id="a"> Parent <span id="b">Child</span> </div> </body></html>The child uses its own size with the inherited ratio.
Syntax and mental model
line-height: 1.5 at 20px gives a used 30px line height. A fixed line-height: 24px inherits as a length, not a ratio. Letter spacing in joined scripts needs care; do not force Latin typography assumptions onto Persian.
Fixed line height
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> #a { line-height: 24px; } #b { font-size: 20px; letter-spacing: 1px; word-spacing: 3px; } </style> </head> <body> <div id="a"> <span id="b">Two words</span> </div> </body></html>The child inherits a fixed length and requests extra spacing.
Common mistakes
Avoid clipping text with fixed-height boxes. Test user spacing overrides and larger text; WCAG spacing requirements concern content surviving overrides, not requiring every page to use those exact defaults.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Font size, weight and style. Next lesson: Alignment and decoration.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Line height and spacing — knowledge check
Five questions on line height and spacing.
At 20px, line-height 1.5 resolves to?
What inherits from unitless line-height?
Which adds word spacing?
What can clip enlarged text?
Should Latin letter spacing be forced on Persian?