XML technologies / CSS / Advanced websites with CSS / CSS property reference / font-size
(Excerpt from “CSS − Advanced websites with Cascading Stylesheets” by Rachel Andrew & Dan Shafer)
The property font-size defines an HTML element’s font size, either absolutely or relative to its parent. Absolute sizes use pixels, points or an absolute keyword such as x-small, representing a browser-dependent size such as small. Relative sizes use em height (em), percentages or relative keywords (for example, larger or smaller).
Inherited: yes. With relative sizes, the calculated value is inherited, not the factor.
See also: font
Values
The property font accepts several formats:
Absolute CSS measurements
A CSS length in pixels (px), points (pt), picas (pi), centimeters (cm), millimeters (mm) or inches (in).
Absolute size keywords
One of these keywords:
xx-smallx-smallsmallmediumlargex-largexx-large
The browser determines their exact sizes, generally smaller on Mac OS than Windows. Steps also depend on the browser; CSS suggests a 20% increase between successive values (large should be 20% larger than medium ).
Relative CSS measurements
A relative size in em height (em), x-height (ex) or percent (%). It calculates size relative to the parent element’s font size.
Relative size keywords
One of these keywords:
smallerlarger
Their exact interpretation is browser-dependent and generally smaller on Mac OS than Windows. Steps also vary; CSS suggests a 20% increase between successive sizes. Under this recommendation, smaller is approximately equivalent to 80% or 0.8em. The keyword larger therefore corresponds approximately to 120% or 1.2em.
Default value: medium (see also “Compatibility”).
Compatibility
CSS version: 1
Works in all CSS-capable browsers.
Internet Explorer for Windows through 6.0 uses the default size small instead of medium. The value medium therefore appears larger than the default. IE 6.0 fixes this in standards-compliant mode; earlier versions need a separate stylesheet when absolute size keywords are used.
Example
This rule sets every element’s default font size to eleven points. Since font-size is inherited, elements with no explicit font-size automatically receive this value:
body {
font-size: 11pt;
}Many older browsers do not support font-property inheritance for all elements, such as tables, so the rule should be more explicit:
body, p, blockquote, li, td, th, pre {
font-size: 11pt;
}This rule illustrates a common beginner’s error:
ul, ol {
font-size: 80%;
}With relative sizes, font-size inherits the parent’s calculated value, not the relative value itself. In this example, list text is 20% smaller than body, and nested lists shrink another 20% from their parent list. Across two nesting levels, text becomes 40% smaller than body and barely readable. Avoid this domino effect by controlling font-size inheritance in nested list items. With this additional rule, all lists, nested or not, use 80% of the font size of body:
ul ul, ul ol, ol ul, ol ol {
font-size: inherit;
}
Copyright © 2006 of the German translation, dpunkt.verlag GmbH
You may print the online version for your private use.
Otherwise, this chapter from “CSS − Anspruchsvolle Websites mit Cascading Stylesheets” is subject to the same conditions as the bound edition: the work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
dpunkt.verlag GmbH, Ringstraße 19, 69115 Heidelberg