Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is "line-height: normal;" a bad idea?

Tags:

css

I have observed some rather inconsistent HTML page rendering behavior when CSS line-height property is set to normal. I have also found a blog post by Eric Meyer where different inconsistencies of line-height: normal; are discussed, here is just one quote:

Here’s the punchline: the effects of declaring line-height: normal not only vary from browser to browser, which I had expected—in fact, quantifying those differences was the whole point—but they also vary from one font face to another, and can also vary within a given face.

In my case i observed that adding some Unicode symbols, for example the envelope symbol "✉", changes the line block height if line-height is set to normal. Setting line-height: 1.2; fixes the problem.

My question is: is there any reason at all to use line-height: normal;? It behaves so unpredictably.

like image 937
Alexey Avatar asked Jan 11 '13 12:01

Alexey


People also ask

What should my line height be?

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.

Why is line height important?

Line height matters because it makes text readable or unreadable. If line spacing is too large, there's too much white space. The text looks awkward. If line spacing is too small, letters appear all squished together.

What PX line height is normal?

If your font size is 10px, your line height will be 3px, 5px, and 11px respectively. Alternatively, you can specify the “normal” keyword. This keyword specifies the use of the browser default. This value is usually around 1.2, depending on what browser the viewer is using.

Can you have a negative line height?

The line-height property specifies the height of an inline block level element. The value of the line-height property cannot be negative.


2 Answers

In principle, a normal value for line-height (either via defaulting, or by explicit setting) is “normal”: browsers are expected to use a value that is suitable for the font being used. This variation should not be a surprise: it’s implied in the definition.

This is supposed to help with a problem like this: you declare font-family: a, b, c, d, sans-serif, but you don’t know which of the specific fonts (if any) is available in each computer, or what the default sans-serif font might be. These fonts might require different line heights, for good appearance. The browser knows which font it is using, so it can pick up a line height for it, from its internal table.

On the practical side, browsers might not select the value well; it tends to be generally a little too small. On the typography side, line height should be selected on the basis of several considerations, not just font face but also the type of text (e.g., texts with a lot of diacritic marks require larger line height) and especially the measure (column width, line length): long lines require larger line height.

So in general, it is best that the designer sets the line height, with due consideration of the different aspects.

This also avoids the problem you describe: when a line contains glyphs from different fonts, each font may have a different default line height associated with it. For example, the envelope symbol is included in a few fonts only, so the odds are that the browser is forced to pick it up from a font different from the one you have declared.

This is what causes uneven line spacing when you mix fonts. It’s not the height of the glyph that matters but the line height of its font. For example, adding a mere period “.” in Cambria Math font, when available, causes huge line spacing—unless you set line-height to a specific value.

like image 89
Jukka K. Korpela Avatar answered Sep 21 '22 01:09

Jukka K. Korpela


is there any reason at all to use line-height: normal;

Yes - the property is there so you can use it when you specifically have to reset line-height to browser default in case you've set it somewhere on parent element.

Why and when you would want to do that depends on what you are implementing and whether or not you care about crossbrowser pixel perfect designs or not.

like image 45
easwee Avatar answered Sep 23 '22 01:09

easwee