font-size sets the font size of the text inside the element to which it is applied, and that of its descendants. You can size text using absolute measurements, or measurements relative to the affected element’s parent or root elements. CSS Text Styling Fundamentals provides an overview.
Overview tablemedium
fontSize
font-size: absolute keywords
font-size: inherit
font-size: length
font-size: percentage
font-size: relative keywords
inherit
keyword causes the element to adopt its parent element’s font size.
A selection of examples showing some typical uses of the font-size property.
<p class="example-one">Example One: We ♥ WebPlatform Docs!</p>
<p class="example-two">Example Two: Lorem ipsum dolor sit amet, consectetur adipisicing elit. Officiis, eos, dicta nihil aliquid quia dolores labore nesciunt unde consectetur blanditiis ex eius consequatur qui incidunt voluptatem inventore fugit quos amet!</p>
<p class="example-three">Example Three: Eius, earum unde eum distinctio ex accusamus rem eligendi optio mollitia deleniti? Iure, accusamus, fuga ipsa quas doloremque enim velit sed est earum pariatur ab optio quia molestiae repellendus non.</p>
.example-one {
font-size: 1.2em;
}
.example-two {
font-size: small;
}
.example-three {
font-size: 28px;
}
A redefinition of the typical 16px browser default font size medium value as 10px, followed by a resizing of the text that follows proportionate to that.
html { font-size: 62.5%; }
.example-one { font-size: 3.6rem }
.example-two { font-size: 2.4rem }
.example-three { font-size: 1.4rem }
Usage
Keywords such as large and medium, or relative em or percentage units, are generally safer to use than pixel measurements, especially for mobile web browsers that adjust their set of default font sizes for legibility. Use of percentage values, or values in ems, leads to more robust and cascadable style sheets.
Otherwise, pixels offer the safest way to specify measurements, since CSS pixels are adjusted for variations in display pixel density.
While the initial medium size applies widely, browsers apply a default style sheet that modifies it for various semantic elements, boosting the size of headings, for example. Browsers also automatically resize fonts when zooming the page, stepping by values that may not correspond exactly to the zoom factor. Unless disabled using text-size-adjust, fonts also resize when tipping between portrait and landscape orientations on mobile browsers. For an overview of the issue, see The Mobile Viewport and Orientation.
The value of font-size also affects the value of line-height when using its default or relative measurements.
Along with many other CSS properties, font-size can also be applied directly as an SVG attribute:
<text x="12px" y="12px" font-family="sans-serif" font-size="120%"/>
Related specifications
font-size
font-size
font-size
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4