Setting font properties will be among the most common uses of style sheets. Unfortunately, there exists no well-defined and universally accepted taxonomy for classifying fonts, and terms that apply to one font family may not be appropriate for others. E.g. 'italic' is commonly used to label slanted text, but slanted text may also be labeled as being Oblique, Slanted, Incline, Cursive or Kursiv. Therefore it is not a simple problem to map typical font selection properties to a specific font.
CSS1 defines the properties 'font-family', 'font-style', 'font-variant' and 'font-weight', 'font-size', 'font'.
Because there is no accepted, universal taxonomy of font properties, matching of properties to font faces must be done carefully. The properties are matched in a well-defined order to insure that the results of this matching process are as consistent as possible across Uesr Agents (assuming that the same library of font faces is presented to each of them).
(The above algorithm can be optimized to avoid having to revisit the CSS1 properties for each character.)
The per-property matching rules from (2) above are as follows:
|
Value
|
[[<family-name> | <generic-family>],]* [<family-name> | <generic-family>] Netscape 4.0, Internet Explorer 3.0 |
|---|---|
|
Initial
|
User Agent specific |
|
Applies to
|
all elements |
|
Inherited
|
yes |
|
Percentage Values
|
N/A |
The value is a prioritized list of font family names and/or generic family names. Unlike most other CSS1 properties, values are separated by a comma to indicate that they are alternatives:
BODY { font-family: gill, helvetica, sans-serif }
<p style="font-family: arial, 'lucida console', sans-serif"> |
There are two types of list values:
<family-name> The name of a font family of choice. In the last example, "gill" and "helvetica" are font families.
<generic-family> In the example above, the last value is a generic family name. The following generic families are defined:
Style sheet designers are encouraged to offer a generic font family as a last alternative.
Font names containing whitespace should be quoted:
BODY { font-family: "new century schoolbook", serif }
|
If quoting is omitted, any whitespace characters before and after the font name are ignored and any sequence of whitespace characters inside the font name is converted to a single space.
|
Value
|
normal | italic | oblique normal, italic: Netscape 4.0, Internet Explorer 3.0 |
|---|---|
|
Initial
|
normal |
|
Applies to
|
all elements |
|
Inherited
|
yes |
|
Percentage Values
|
N/A |
The 'font-style' property selects between normal (sometimes referred to as "roman" or "upright"), italic and oblique faces within a font family.
A value of 'normal' selects a font that is classified as 'normal' in the UA's font database, while 'oblique' selects a font that is labeled 'oblique'. A value of 'italic' selects a font that is labeled 'italic', or, if that is not available, one labeled 'oblique'.
The font that is labeled 'oblique' in the UA's font database may actually have been generated by electronically slanting a normal font.
Fonts with Oblique, Slanted or Incline in their names will typically be labeled 'oblique' in the UA's font database. Fonts with Italic, Cursive or Kursiv in their names will typically be labeled 'italic'.
H1, H2, H3 { font-style: italic }
H1 EM { font-style: normal }
|
In the example above, emphasized text within 'H1' will appear in a normal face.
| Examples: This line has <font style="font-style: normal">...</font> This line has <font style="font-style: italic">...</font> This line has <font> style="font-style: oblique">...</font> |
|
Value
|
normal | small-caps Netscape 6.0, Internet Explorer 4.0 |
|---|---|
|
Initial
|
normal |
|
Applies to
|
all elements |
|
Inherited
|
yes |
|
Percentage Values
|
N/A |
Another type of variation within a font family is the small-caps. In a small-caps font the lower case letters look similar to the uppercase ones, but in a smaller size and with slightly different proportions. The 'font-variant' property selects that font.
A value of 'normal' selects a font that is not a small-caps font, 'small-caps' selects a small-caps font. It is acceptable (but not required) in CSS1 if the small-caps font is a created by taking a normal font and replacing the lower case letters by scaled uppercase characters. As a last resort, uppercase letters will be used as replacement for a small-caps font.
| Examples: This line has <font style="font-variant: normal">...</font> This line has <font style="font-variant: small-caps">...</font> |
The following example results in an 'H3' element in small-caps, with emphasized words in oblique small-caps:
H3 { font-variant: small-caps }
EM { font-style: oblique }
Example:Header 3 with font-variant: small-caps and EM with font-style: oblique |
There may be other variants in the font family as well, such as fonts with old-style numerals, small-caps numerals, condensed or expanded letters, etc. CSS1 has no properties that select those.
CSS1 core: insofar as this property causes text to be transformed to uppercase, the same considerations as for 'text-transform' apply.
|
Value
|
normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 normal, bold: Netscape 4.0, Internet Explorer 3.0 bolder, lighter, 100, 200, ... , 900: Netscape 4.0, Internet Explorer 4.0 100, 200, ... , 900: Defines from thin to thick characters. 400 is the same as normal, and 700 is the same as bold |
|---|---|
|
Initial
|
normal |
|
Applies to
|
all elements |
|
Inherited
|
yes |
|
Percentage Values
|
N/A |
The 'font-weight' property selects the weight of the font. The values '100' to '900' form an ordered sequence, where each number indicates a weight that is at least as dark as its predecessor. The keyword 'normal' is synonymous with '400', and 'bold' is synonymous with '700'. Keywords other than 'normal' and 'bold' have been shown to be often confused with font names and a numerical scale was therefore chosen for the 9-value list.
P { font-weight: normal } /* 400 */
H1 { font-weight: 700 } /* bold */
|
The 'bolder' and 'lighter' values select font weights that are relative to the weight inherited from the parent:
STRONG { font-weight: bolder }
|
| Examples: This line has <font style="font-weight: normal">...</font> This line has <font style="font-weight: bold">...</font> This line has <font style="font-weight: bolder">...</font> This line has <font style="font-weight: lighter">...</font> This line has <font style="font-weight: 100">...</font> This line has <font style="font-weight: 200">...</font> This line has <font style="font-weight: 300">...</font> This line has <font style="font-weight: 400">...</font> This line has <font style="font-weight: 500">...</font> This line has <font style="font-weight: 600">...</font> This line has <font style="font-weight: 700">...</font> This line has <font style="font-weight: 800">...</font> This line has <font style="font-weight: 900">...</font> |
Child elements inherit the resultant weight, not the keyword value.
Fonts (the font data) typically have one or more properties whose values are names that are descriptive of the "weight" of a font. There is no accepted, universal meaning to these weight names. Their primary role is to distinguish faces of differing darkness within a single font family. Usage across font families is quite variant; for example a font that you might think of as being bold might be described as being Regular, Roman, Book, Medium, Semi- or DemiBold, Bold, or Black, depending on how black the "normal" face of the font is within the design. Because there is no standard usage of names, the weight property values in CSS1 are given on a numerical scale in which the value '400' (or 'normal') corresponds to the "normal" text face for that family. The weight name associated with that face will typically be Book, Regular, Roman, Normal or sometimes Medium.
The association of other weights within a family to the numerical weight values is intended only to preserve the ordering of darkness within that family. However, the following heuristics tell how the assignment is done in typical cases:
The following two examples illustrate the process. Assume four weights in the "Example1" family, from lightest to darkest: Regular, Medium, Bold, Heavy. And assume six weights in the "Example2" family: Book, Medium, Bold, Heavy, Black, ExtraBlack. Note how in the second example it has been decided not to assign "Example2 ExtraBlack" to anything.
| Available faces | Assignments | Filling the holes |
|---|---|---|
| "Example1 Regular" | 400 | 100, 200, 300 |
| "Example1 Medium" | 500 | |
| "Example1 Bold" | 700 | 600 |
| "Example1 Heavy" | 800 | 900 |
| Available faces | Assignments | Filling the holes |
|---|---|---|
| "Example2 Book" | 400 | 100, 200, 300 |
| "Example2 Medium" | 500 | |
| "Example2 Bold" | 700 | 600 |
| "Example2 Heavy" | 800 | |
| "Example2 Black" | 900 | |
| Example2 ExtraBlack" | (none) |
Since the intent of the relative keywords 'bolder' and 'lighter' is to darken or lighten the face within the family and because a family may not have faces aligned with all the symbolic weight values, the matching of 'bolder' is to the next darker face available on the client within the family and the matching of 'lighter' is to the next lighter face within the family. To be precise, the meaning of the relative keywords 'bolder' and 'lighter' is as follows:
There is no guarantee that there will be a darker face for each of the 'font-weight' values; for example, some fonts may have only a normal and a bold face, others may have eight different face weights. There is no guarantee on how a UA will map font faces within a family to weight values. The only guarantee is that a face of a given value will be no less dark than the faces of lighter values.
|
Value
|
<absolute-size> | <relative-size> | <length> | <percentage> <absolute-size>: [ xx-small | x-small | small | medium | large | x-large | xx-large ]: Netscape 4.0, Internet Explorer 3.0 <relative-size>: [ larger | smaller ]: Netscape 4.0, Internet Explorer 4.0 length: Sets the font-size to a fixed size. Examples: 10px, 10pt. Netscape 4.0, Internet Explorer 3.0 percentage: Sets the font-size to a % of the parent element. Netscape 4.0, Internet Explorer 3.0 Note in IE 4.0+:
Notes in Netscape 4.0+:
|
|---|---|
|
Initial
|
medium |
|
Applies to
|
all elements |
|
Inherited
|
yes |
|
Percentage Values
|
relative to parent element's font size |
<absolute-size>: An <absolute-size> keyword is an index
to a table of font sizes computed and kept by the UA. Possible values are: [
xx-small | x-small | small | medium | large | x-large | xx-large ]. On a computer
screen a scaling factor of 1.5 is suggested between adjacent indexes; if the
'medium' font is 10pt, the 'large' font could be 15pt. Different media may need
different scaling factors. Also, the UA should take the quality and availability
of fonts into account when computing the table. The table may be different from
one font family to another.
<relative-size>: A <relative-size> keyword is interpreted relative to the table of font sizes and the font size of the parent element. Possible values are: [ larger | smaller ]. For example, if the parent element has a font size of 'medium', a value of 'larger' will make the font size of the current element be 'large'. If the parent element's size is not close to a table entry, the UA is free to interpolate between table entries or round off to the closest one. The UA may have to extrapolate table values if the numerical value goes beyond the keywords.
Length and percentage values should not take the font size table into account when calculating the font size of the element.
Negative values are not allowed.
On all other properties, 'em' and 'ex' length values refer to the font size of the current element. On the 'font-size' property, these length units refer to the font size of the parent element.
Note that an application may reinterpret an explicit size, depending on the context. E.g., inside a VR scene a font may get a different size because of perspective distortion.
Examples:
P { font-size: 12pt; }
BLOCKQUOTE { font-size: larger }
EM { font-size: 150% }
EM { font-size: 1.5em }
|
If the suggested scaling factor of 1.5 is used, the last three declarations are identical.
| Examples: This line has <font style="font-size: xx-small ">...</font> This line has <font style="font-size: x-small">...</font> This line has <font style="font-size: small">...</font> This line has <font style="font-size: medium">...</font> This line has <font style="font-size: large">...</font> This line has <font style="font-size: x-large">...</font> This line has <font style="font-size: xx-large">...</font> This line has <font style="font-size: larger">...</font> This line has <font style="font-size: smaller">...</font> This line has <font style="font-size: 10pt">...</font> (small font) This line has <font style="font-size: 12.5pt">...</font> This line has <font style="font-size: 15pt">...</font> (medium font) This line has <font style="font-size: 10px">...</font> This line has <font style="font-size: 15px">...</font> This line has <font style="font-size: 20px">...</font> This line has <font style="font-size: 1.0em">...</font> This line has <font style="font-size: 1.25em">...</font> This line has <font style="font-size: 1.5em">...</font> This line has <font style="font-size: 3.0em">...</font> This line has <font style="font-size: 50%">...</font> This line has <font style="font-size: 100%">...</font> This line has <font style="font-size: 200%">...</font> |
|
Value
|
none | <number> |
|---|---|
|
Initial
|
none |
|
Applies to
|
all elements |
|
Inherited
|
yes |
|
Percentage Values
|
N/A |
The ratio between the height of the "font-size" and the height of the font's lowercase letter "x" is called a font's aspect value. If the aspect value is high, the font will be legible when it is set to a smaller size. For example: Verdana has an aspect value of 0.58 (means that when font size is 100 px, its x-height is 58 px). Times New Roman has an aspect value of 0.46. This means that Verdana is more legible at smaller sizes than Times New Roman.
The font-size-adjust property specifies an aspect value for an element that will preserve the x-height of the first-choice font.
| h2 { font-size-adjust: 0.58 } |
| Examples: This line has <font style="font-size-adjust: none ">...</font> This line has <font style="font-size-adjust: 0.50 ">...</font> This line has <font style="font-size-adjust: 0.80 ">...</font> This line has <font style="font-size-adjust: 1.50 ">...</font> |
|
Value
|
normal: Sets the scale of condensation or expansion to normal wider: Sets the scale of expansion to the next expanded value narrower: Sets the scale of condensation to the next condensed value ultra-condensed | extra-condensed | condensed | semi-condensed | semi-xpanded
| expanded | extra-expanded | ultra-expanded : |
|---|---|
|
Initial
|
normal |
|
Applies to
|
all elements |
|
Inherited
|
yes |
|
Percentage Values
|
N/A |
The font-stretch property condenses or expands the current font-family.
Note: The font-family are condensed or expanded horizontally only.
| h2 { font-stretch: ultra-condensed } |
| Examples: This line has <font style="font-stretch: normal ">...</font> This line has <font style="font-stretch: wider ">...</font> This line has <font style="font-stretch: narrower ">...</font> This line has <font style="font-stretch: ultra-condensed ">...</font> This line has <font style="font-stretch: extra-condensed ">...</font> This line has <font style="font-stretch: condensed ">...</font> This line has <font style="font-stretch: semi-condensed ">...</font> This line has <font style="font-stretch: semi-xpanded ">...</font> This line has <font style="font-stretch: xpanded ">...</font> This line has <font style="font-stretch: extra-xpanded ">...</font> This line has <font style="font-stretch: ultra-xpanded ">...</font> |
|
Value
|
[ <font-style> || <font-variant> || <font-weight> ]? <font-size> [ / <line-height> ]? <font-family> Netscape 4.0, Internet Explorer 4.0 The following values are not in the CSS1 specification: caption: Defines the font that are used by captioned controls (like buttons, drop-downs, etc.). Internet Explorer 4.0 icon: Defines the fonts that are used by icon labels. Internet Explorer 4.0 menu: Defines the fonts that are used by dropdown menus. Internet Explorer 4.0 message-box: Defines the fonts that are used by dialog boxes small-caption status-bar: Defines the fonts that are used by window status bars Note in Netscape 4.0+: The "font-variant" value in this declaration does not work |
|---|---|
|
Initial
|
not defined for shorthand properties |
|
Applies to
|
all elements |
|
Inherited
|
yes |
|
Percentage Values
|
allowed on <font-size> and <line-height> |
The 'font' property is a shorthand property for setting 'font-style' 'font-variant' 'font-weight' 'font-size', 'line-height' and 'font-family' at the same place in the style sheet. The syntax of this property is based on a traditional typographical shorthand notation to set multiple properties related to fonts.
p |
For a definition of allowed and initial values, see the previously defined properties. Properties for which no values are given are set to their initial value.
P { font: 12pt/14pt sans-serif }
P { font: 80% sans-serif }
P { font: x-large/110% "new century schoolbook", serif }
P { font: bold italic large Palatino, serif }
P { font: normal small-caps 120%/120% fantasy }
|
In the second rule, the font size percentage value ('80%') refers to the font size of the parent element. In the third rule, the line height percentage refers to the font size of the element itself.
In the first three rules above, the 'font-style', 'font-variant' and 'font-weight' are not explicitly mentioned, which means they are all three set to their initial value ('normal'). The fourth rule sets the 'font-weight' to 'bold', the 'font-style' to 'italic' and implicitly sets 'font-variant' to 'normal'.
The fifth rule sets the 'font-variant' ('small-caps'), the 'font-size' (120% of the parent's font), the 'line-height' (120% times the font size) and the 'font-family' ('fantasy'). It follows that the keyword 'normal' applies to the two remaining properties: 'font-style' and 'font-weight'.