Search code examples
cssfontsfont-sizepixeltypography

How is font size calculated?


I have a complex js function with an equation in which I actually need to understand how much space in pixels font sizes take up.

I have noticed that some font's sizes are different depending on the font.

How is a font's size calculated? If its set to 12px, in css, what does the 12px mean? Is that 12px wide? High? Or is it a diagonal pixel measurement?


Solution

  • See the spec:

    The font size corresponds to the em square, a concept used in typography.
    Note that certain glyphs may bleed outside their em squares.