Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: Understanding and adjusting leading / line-height of fonts

A very similar question was asked here but the really answered sufficiently...

The CSS line-height property controls the amount of white space above the letters. Making it bigger/smaller spaces rows of text farther/closer together. But if you set the line height to the exact same value as the font-size, the text will still have white space above them.

So this DOESN'T quite work...

div { height: 80px; }
span { font-size : 80px; line-height : 80px; }
<div>
<span>Foo</span>
</div>

http://jsfiddle.net/s_d_p/yMHVs/

The degree to which the enclosed text actually matches the container height seems to differ from font to font.

So my question is two parts:

  1. What are we actually adjusting when we set line-height?

  2. Is there a way to remove it entirely so that letter fit precisely inside their container?

like image 403
emersonthis Avatar asked Nov 28 '13 14:11

emersonthis


People also ask

How are CSS used in changing font text size and line height?

If your font size is 10px, your line height will be 10px, 18px, and 20px, respectively. Sets line height as a percentage of the font size of the element. If your font size is 10px, your line height will be 3px, 5px, and 11px respectively. Alternatively, you can specify the “normal” keyword.

How do I change the height of a font in CSS?

Set Font Size With Em 1em is equal to the current font size. The default text size in browsers is 16px. So, the default size of 1em is 16px.

Does line height affect font size?

It's important to stress that line height is not the space between lines of text—as it is often mistakenly thought of—but the space from the baseline of one line of text to the baseline of the next line of text. So, a font size of 16px would require a line height of 24px or higher.

How do you increase line height in CSS?

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. On non-replaced inline elements, it specifies the height that is used to calculate line box height.


1 Answers

Note that the remaining/extra space is typically a symptom of the font being used, as designated by its designer.

Thus, the 80px includes the allocated white space above and/or below. Additional white space above is typically provided to allow for accented characters, which would otherwise require the letter itself to be compressed- producing an inconsistent typeface.

See here & here for further information.

Line height refers to the total height of the typeface, inclusive of any allocated whitespace.

like image 108
SW4 Avatar answered Sep 20 '22 03:09

SW4