liveBook · Manning

Unitless number

As explained in CSS in Depth, Second Edition

A unitless number is a CSS numeric value written without a unit and interpreted according to the property that receives it.

A unitless number is a CSS numeric value without a unit. Its meaning depends on the property receiving it: line-height treats 1.2 as a multiplier, while z-index and font-weight use numbers directly. A unitless 0 can replace a length or percentage value, but not an angle or time value. section 2.5

Unitless line-height is especially useful because the declared number is inherited and recalculated against each descendant’s local font size. With line-height: 1.2 and a 32px paragraph, the result is 38.4px. A unit-based value such as 1.2em can pass a computed length to children and cause overlapping text when their font sizes differ. section 2.5

Responsive paragraph spacing

Set body { line-height: 1.2; } and give .about-us { font-size: 2em; }. The paragraph inherits the multiplier, so its line height adapts locally instead of receiving a fixed computed length.

Design specifications can be converted into unitless line-height values: convert points to pixels by multiplying by 1.333, then divide by the font size. For example, 18pt becomes 24px, which becomes 1.5 with a 16px font. section 12.6.1

How CSS in Depth, Second Edition covers it

How deep it goes
Explains inheritance, local line-height calculation, zero-value limits, and a points-to-pixels conversion, stopping short of broader numeric CSS syntax.
Examples
Demonstrates body line-height, an enlarged paragraph, overlapping unit-based text, and conversion of 18pt leading to 1.5.
What it assumes
Assumes basic CSS properties, inheritance, font sizes, and common units such as px, em, rem, and percentages.
What you can do after
Apply unitless line-height and distinguish safe zero values from unsupported angular and time-based uses.
How it connects
Connects unitless numbers to line-height, inheritance, font-size, length units, percentages, z-index, and font-weight.

Also explained in

Compare how 2 books explain unitless number →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of CSS in Depth, Second Edition. The section links point to the parts of the book it draws on.