When setting CSS font-size in pixels, does the value refer to the width or height of a letter?

前端 未结 3 365
终归单人心
终归单人心 2020-12-15 17:10

Does the pixel value of a font-size refer to the height of the font or the width of the font?

CSS:

.sixteen {
  font-size: 16px;
}

3条回答
  •  遥遥无期
    2020-12-15 17:31

    The font-size property specifies the size of the font, no matter what unit is used. The size of a font can be characterized as the height of the font, but even this is just a loose and pragmatic description; characters may extend above and below the levels defined by the size of the font. The size is a more or less abstract property, and it should not be expected to correspond to the height (still less the width) of any character.

    In particular, it would be all wrong to design a font where the letter “a” occupies the full height of the font. The height of “a” is typically about half of the font size, but this surely varies by font (try testing with “a” in Times New Roman and in Verdana, using the same font size).

提交回复
热议问题