Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between line-height:1.5 and line-height:150% in css?

Tags:

css

Anyone knows about it?

like image 284
user198729 Avatar asked Jan 11 '10 09:01

user198729


People also ask

What is the difference between height and line height in CSS?

Height is the vertical measurement of the container, for example, height of a div. Line-height is a CSS property to specify the line height i.e. the distance from the top of the first line of text to the top of the second. It is the space between the lines of two paragraphs.

How many pixels is 1.5 line height?

Google runs a 1.5 line height for its body there, or 16px font size and a line-height of 24px.

What does line height 1.4 mean?

The line-height property in CSS controls the space between lines of text. It is often set in a unitless value (e.g. line-height: 1.4; ) so that it is proportional to the font-size. It's a vital property for typographic control.

What is a good line height CSS?

While there is no perfect line height, a good rule of thumb is to set it at approximately 150% of the font size. While there is no perfect line height, a good rule of thumb is to set it at approximately 150% of the font size.


1 Answers

Short version: line-height: 150% is static, line-height: 1.5 is dynamic. The effect is more evident on inheriting elements. An example:

HTML

<div style="font-size: 12px">
    <span style="font-size: 24px">test</span>
</div>

This CSS

div { line-height: 150%; } /* Computed line-height: 18px (150% * 12px) */
span { }                   /* Computed line-height: 18px (inherited directly) */

As opposed to this:

div { line-height: 1.5 }   /* Computed line-height: 18px (1.5 * 12px) */
span { }                   /* Computed line-height: 36px (1.5 * 24px) */

You may read more at the CSS2 specs page

like image 65
K Prime Avatar answered Sep 23 '22 03:09

K Prime