Fonts
font-size
font-size sets the size of text. Besides fixed px values, you can use em, rem and % relative to the parent or root text size, or keywords such as small and large.
Syntax
<absolute-size> | <relative-size> | <length-percentage [0,∞]> | mathPreview
Presets
Drag the bottom-right corner to resize
Code
.box {
font-size: 40px;
}Controls
font-size40px
About
Writing the value
- A length such as
16px: uses that size. emand%: relative to the parent element's text size.2emand200%both mean twice the parent. Nesting multiplies the sizes.rem: relative to the root (html) text size. Nesting does not change it, which makes it easy to keep text sizes consistent across a site.xx-smalltoxxx-large: fixed steps of size.mediumis the initial value, usually 16px.smallerandlarger: one step smaller or larger than the parent's text.
The preview on this page converts units assuming the parent text is 16px. In practice, % and em depend on the parent wherever the element is placed.
Respecting user settings
Some people enlarge text in their browser settings. Sizes in rem or em follow that setting. With fixed px sizes, page zoom still works, but the text size setting does not.