Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line-height without units

I saw people using line height without specifying a unit, like this: line-height: 1.5;

What does the number represents? I'm guessing it's a ratio so is it like em?

like image 334
ilyo Avatar asked Sep 06 '12 15:09

ilyo


People also ask

What is Unitless line height?

Unitless line heightsA number value can be any number, including a decimal-based number, as is used in the first code example on this page. Unitless line heights are recommended due to the fact that child elements will inherit the raw number value, rather than the computed value.

How do you calculate line height?

For the optimal readability and accessibility, you should go with140 – 180% line height (this is the space around a line of text). This means if your font size is 16pt, your line height should be at least 16 x 1.4 = 22.4pt (140%), or 16 x1. 8= 28.8pt (180%) maximum value.

What is 150% line height?

line-height: 150% will take 150% of the element's computed font size to compute the line height, which is equivalent to multiply it by 1.5 .

How do you find the height of a line in text?

Leading is the distance between the bottom of a line of text and the top of the line of text underneath it. Line-height is the distance between half of the leading above a line and half the leading below it. To convert leading to line height: font size + (leading / 2) = line-height.


1 Answers

Yes, it is a ratio: 1.5 means 1.5 times the font size of the element. So it means the same as 1.5em or 150%, but with one important exception: in inheritance, when a pure number is used, the number is inherited, not the computed value.

So if you have an element with font size 24pt, line-height: 1.5 sets the line height to 36pt. But if the element has a child, i.e. an inner element, with font size of 10pt, and without any line height set on it, then the child inherits the line-height value of 1.5, which means 15pt for that element. If, on the other hand, the line height were set to 1.5em or 150%, then the child would inherit the computed value of 36pt, creating grotesque line spacing.

Technically, this is hidden under a formulation that says. for a pure number used as line-height value: “The computed value is the same as the specified value.” So, nominally, the child inherits the “computed” value of 1.5, which will then be interpreted in the context of the child (1.5 times its font size).

like image 165
Jukka K. Korpela Avatar answered Oct 17 '22 03:10

Jukka K. Korpela