Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are pros and cons to add line-height to body { }?

Tags:

css

xhtml

Is it good to add line-height in body{line-height:1.5} or it would be better if i add separately for tag by tag like p{ line height:1em} etc.

Edit:

body {line-height:in em} create problem with if we put image with float inside

Edit: 24 April 2010:

If i have to add different line heights to elements

like

p {line-height: 1.4}

h1 {line-height:1.6}

h2 {line-height:1.2}

ul li {line-height:1.1}

then shouldn't i use line height in body {line-height:1.4}

if body {line-height:1.4} and h1 {line-height:1.6} then what would be line height for h1?

like image 862
Jitendra Vyas Avatar asked Nov 04 '09 05:11

Jitendra Vyas


People also ask

What does line height do?

The line-height CSS property sets the height of a line box. It's commonly used to set the distance between lines of text. On block-level elements, it specifies the minimum height of line boxes within the element.

What is the best line height?

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.

What is the difference between height and line height?

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 much is line height normal?

Body text (your normal paragraph text) should have a line-height of 1.4–1.6, give or take.


2 Answers

It just depends. If you put it in the body then you get to be lazy and not worry about ever doing it again, but your going to lose control because everything on the page will have the line-height set to 1.5. Whereas if you declared it in each tag, you gain lots of control, but will have to do more work.

Personally I would go for the tag-by-tag solution, but I'm a control freak, so...

like image 53
Kredns Avatar answered Sep 27 '22 20:09

Kredns


A word of caution on putting line-height on the body tag:

If you specify a height in percent, you would intuitively expect to enlargen / shrink all line-heights (e.g. 50% shrink to half, 200% duplicate space, 100% nothing happens).

body {
  line-height: 120%
}

This is not the case. For paragraphs and normal-sized text it works fine. But for headings it's a disaster, since the same line-height as for normal text gets applied... See what happens here: https://jsfiddle.net/11jgwzzu/ .

It works, if you use for example 1.5 instead of 150%.

With this in mind, I think it's quite okay to use something like this:

body {
  line-height: 1.61 // Golden Ratio
}

to make the entire page a bit more spacious. You can still overwrite this behaviour for some specific elements if you want to, but I often find I don't even have to overwrite it since I think line-height: 1.61 looks pretty good everywhere.

like image 34
bersling Avatar answered Sep 27 '22 20:09

bersling