What does unitless line-height do differently from a length value?
Quick answer
A unitless line-height is a multiplier: each element uses it with that element’s own font size. A length such as 30px computes to an absolute length on the parent and is inherited as that length. So a smaller child can get proportionally tighter spacing with the unitless value, but retain the parent’s line height with the length. Unitless values are usually the safer default when descendants have different font sizes. [S1]
The question, the details, the next step.
A practical checklist
Identify the parent and child font sizes you are comparing.
For a unitless value, multiply the number by each element’s own font size.
For a length, check whether the child inherits the parent’s absolute line-height.
Compare the parent and child results in the component before settling on a value.
Use a unitless multiplier as the usual starting point for mixed-size descendants.
A few more useful answers
Does `1.5` mean 1.5 pixels?
No. It is a unitless multiplier, not a length. Each element applies it to its own font size. [S1]
Will a length always be wrong for a child with smaller text?
No. It can be intentional when you want the child to inherit the same absolute line-height. Check whether that fixed spacing suits the smaller text. [S1]
Which value is the better default when font sizes vary?
A unitless value is generally the safer starting point because descendants can scale the line-height with their own font sizes. [S1]
Sources
References used for this guide.
- [S1] MDN: line-height values and inheritance developer.mozilla.org · Checked
