Default unit for font-size?

前端 未结 1 1731
被撕碎了的回忆
被撕碎了的回忆 2021-01-04 18:26

Various texts on the net claim that \"pt\" is the default font-size unit when none is provided, however, my own testing seems to demonstrate otherwise. I have read many docu

1条回答
  •  感情败类
    2021-01-04 19:28

    Per the "CSS Fonts Module Level 3" the font-size property can have values that are:

    Value: | | |

    , , and are defined in the same spec, and are all either keywords (e.x. small, larger, etc) or have percentage units.

    being more generic is defined in "CSS Values and Units Module Level 3":

    Lengths refer to distance measurements and are denoted by in the property definitions. A length is a dimension. However, for zero lengths the unit identifier is optional (i.e. can be syntactically represented as the 0).

    What this means is that unitless numbers for font-size are invalid, with an explicit exception for 0.


    With that said, what size is

    20 size
    being rendered at?

    The rendered font-size of an element will depend on a lot of things. However, if we're able to assume that

    • the user hasn't customized their default font-size
    • the browser is using default styles
    • there are no parent elements that would otherwise change the font-size (e.x. , ,

      ...yes it would be invalid markup to have those elements as parents, but it would still change the font-size)

    Then the default font-size in every modern browser that I'm aware of currently is 16px.

    0 讨论(0)
提交回复
热议问题