1. Introduction
This specification includes and expands on the basic font features described in the CSS3 Fonts specification ([CSS-FONTS-3]).
1.1. Value Definitions
This specification follows the CSS property definition conventions from [CSS2] using the value definition syntax from [CSS-VALUES-3]. Value types not defined in this specification are defined in CSS Values & Units [CSS-VALUES-3]. Combination with other CSS modules may expand the definitions of these value types.
In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept the CSS-wide keywords as their property value. For readability they have not been repeated explicitly.
1.2. Interaction With Font-Relative Units
The following properties defined in this specification are font-affecting properties:
-
All longhands of the font shorthand
-
All longhands of the font-synthesis shorthand
-
All longhands of the font-variant shorthand
2. Basic Font Properties
The particular font face used to render a character is determined by the font family and other font properties that apply to a given element. This structure allows settings to be varied independently of each other.
2.1. Font family: the font-family property
| Name: | font-family |
|---|---|
| Value: | [ <font-family-name> | <generic-font-family> ]# |
| Initial: | depends on user agent |
| Applies to: | all elements and text |
| Inherited: | yes |
| Percentages: | n/a |
| Computed value: | list, each item a string and/or <generic-font-family> keywords |
| Canonical order: | per grammar |
| Animation type: | discrete |
Tests
- font-family-name-000.xht (live test) (source)
- font-family-name-001.xht (live test) (source)
- font-family-name-002.xht (live test) (source)
- font-family-name-003.xht (live test) (source)
- font-family-name-004.xht (live test) (source)
- font-family-name-005.xht (live test) (source)
- font-family-name-006.xht (live test) (source)
- font-family-name-007.xht (live test) (source)
- font-family-name-008.xht (live test) (source)
- font-family-name-009.xht (live test) (source)
- font-family-name-010.xht (live test) (source)
- font-family-name-011.xht (live test) (source)
- font-family-name-012.xht (live test) (source)
- font-family-name-013.xht (live test) (source)
- font-family-name-014.xht (live test) (source)
- font-family-name-015.xht (live test) (source)
- font-family-name-016.xht (live test) (source)
- font-family-name-017.xht (live test) (source)
- font-family-name-018.xht (live test) (source)
- font-family-name-019.xht (live test) (source)
- font-family-name-020.xht (live test) (source)
- font-family-name-021.xht (live test) (source)
- font-family-name-022.xht (live test) (source)
- font-family-name-023.xht (live test) (source)
- font-family-name-024.xht (live test) (source)
- font-family-name-025.html (live test) (source)
- generic-family-keywords-003.html (live test) (source)
- standard-font-family-10.html (live test) (source)
- standard-font-family-11.html (live test) (source)
- standard-font-family-12.html (live test) (source)
- standard-font-family-13.html (live test) (source)
- standard-font-family-14.html (live test) (source)
- standard-font-family-15.html (live test) (source)
- standard-font-family-16.html (live test) (source)
- standard-font-family-17.html (live test) (source)
- standard-font-family-18.html (live test) (source)
- standard-font-family-19.html (live test) (source)
- standard-font-family-2.html (live test) (source)
- standard-font-family-20.html (live test) (source)
- standard-font-family-3.html (live test) (source)
- standard-font-family-4.html (live test) (source)
- standard-font-family-5.html (live test) (source)
- standard-font-family-6.html (live test) (source)
- standard-font-family-7.html (live test) (source)
- standard-font-family-8.html (live test) (source)
- standard-font-family-9.html (live test) (source)
- standard-font-family.html (live test) (source)
- test_font_family_parsing.html (live test) (source)
- system-fonts.html (live test) (source)
- font-family-computed.html (live test) (source)
- font-family-invalid.html (live test) (source)
- font-family-valid.html (live test) (source)
This property specifies a prioritized list of font family names or generic family names. A font family defines a set of faces that vary in weight, width or slope. CSS uses the combination of a family name with other font properties to select an individual face. Using this selection mechanism, rather than selecting a face via the style name as is often done in design applications, allows some degree of regularity in textual display when fallback occurs.
Component values are a comma-separated list indicating alternatives. A user agent iterates through the list of family names until it matches an available font that contains a glyph for the character to be rendered. (See § 5.3 Cluster matching.) This allows for differences in available fonts across platforms and for differences in the range of characters supported by individual fonts.
body{ font-family : Helvetica, Verdana, sans-serif; }
If Helvetica is available, it will be used when rendering. If neither Helvetica nor Verdana is present, then the generic font-family sans-serif font will be used.
There are three types of font family names, two of which may be used with this property:
- <font-family-name>
-
The name of a font family, such as Helvetica or Verdana in the previous example.
This might be a locally-instaled font, or might be a web font.
- <generic-font-family>
-
Each <generic-font-family> keyword represents
a generic font choice,
and behaves as a potential alias for one or more locally-installed fonts
belonging to the specified generic font category.
A <generic-font-family> can thus be used as a fallback
for when an author’s more specific font choices are not available.
There are three types of generic family:
-
Generics which apply to all Unicode characters and will always match a locally installed font. For example, monospace.
-
Generics which apply to all Unicode characters but may not match to a locally installed font on some systems. For example, ui-rounded.
-
Generics which are writing-system specific, only apply to a subset of Unicode characters, and may not match to a locally installed font on some systems. For example, generic(fangsong).
Authors are encouraged to append a generic font family as a last alternative for improved robustness, and to use a more specific generic font family, if applicable, to prefer a specific style even if the individual named font family is not available.
Note that <generic-font-family> keywords cannot be quoted (otherwise they are interpreted as a <font-family-name>).
The set of generic family keywords is defined in § 2.1.5 Generic font families.
-
- <system-font-family-name>
-
A locally installed system font, whose use is subject to certain constraints.
In particular, it may not be used with the font-family property,
but can be used with the font shorthand.
The following values refer to system fonts:
- caption
- The font used for captioned controls (e.g., buttons, drop-downs, etc.).
- icon
- The font used to label icons.
- menu
- The font used in menus (e.g., dropdown menus and menu lists).
- message-box
- The font used in dialog boxes.
- small-caption
- The font used for labeling small controls.
- status-bar
- The font used in window status bars.
2.1.1. Syntax of <font-family-name>
<font-family-name> = <string> | <custom-ident>+
Font family names other than generic families or system font families must either be given quoted as <string>s, or unquoted as a sequence of one or more <custom-ident>.
Note: This means most punctuation characters and digits at the start of each token must be escaped in unquoted font family names.
font-family : Red/Black, sans-serif; font-family : "Lucida" Grande, sans-serif; font-family : Ahem!, sans-serif; font-family : test@foo , sans-serif; font-family : #POUND, sans-serif; font-family : Hawaii5 - 0 , sans-serif;
Any identifier which could be misinterpreted as a pre-defined keyword in the font-family value definition, or the CSS-wide keywords, is not allowed.
Note: this means that if you really have a font whose name is the same as one of the <generic-font-family> names, or the system font names, or the CSS-wide keywords, it must be quoted.
font-family : "sans-serif" , sans-serif; font-family : "default" , sans-serif; font-family : "initial" , sans-serif; font-family : "inherit" , sans-serif;
If a sequence of identifiers is given as a <font-family-name>, the computed value is the name converted to a string by joining all the identifiers in the sequence by single spaces.
To avoid mistakes in escaping, it is recommended to quote font family names that contain white space, digits, or punctuation characters other than hyphens:
body{ font-family : "New Century Schoolbook" , serif} <body style="font-family: '21st Century', fantasy" >
Font family names that happen to be the same as a font-family keyword value (e.g. CSS-wide keywords such as inherit, or <generic-font-family> keywords such as serif) must be quoted to prevent confusion with the keywords of the same names. UAs must not consider these keywords as matching the <font-family-name> type.
2.1.2. Syntax of <generic-font-family>
<generic-font-family> = <generic-font-script-specific>| <generic-font-complete> | <generic-font-incomplete> <generic-font-script-specific> =generic ( fangsong) |generic ( kai) |generic ( khmer-mul) |generic ( nastaliq) <generic-font-complete> = serif | sans-serif | system-ui | cursive | fantasy | math | monospace <generic-font-incomplete> = ui-serif | ui-sans-serif | ui-monospace | ui-rounded
To make the syntax less succeptible to clashes, more recently defined generic font families are identified using a functional syntax.
body{ font-family : "Adobe Fangsong Std R" , generic ( fangsong), serif}
The first choice in this example is a specific, named font, in Fang Song (仿宋) style. The family name is enclosed in quotes as it contains space characters. The second is a recently added script-specific generic font; it is unicode-range specific and so may not match to an actual installed font on some systems; but if it exists it will be an example of the requested style. The third is a universal generic font, which is guaranteed to match on all systems.
2.1.3. Syntax of <system-font-family-name>
<system-font-family-name> = caption | icon | menu | message-box | small-caption | status-bar
2.1.4. Relationship Between Faces and Families
A font family name only specifies a name given to a set of font faces; it does not specify an individual face.
Note: The CSS definition of font attributes used for selection are explicitly not intended to define a font taxonomy. A type designer’s idea of a family can often extend to a set of faces that vary along axes other than just the standard axes of weight (font-weight), width (font-width), and slant (font-style). A family can vary along axes that are unique to that family. The CSS font selection mechanism merely provides a way to determine the “closest” match when substitution is necessary.
Note: The precise way a set of fonts are grouped into font families varies depending upon the platform font management APIs. For example, the Windows GDI API only allows four faces to be grouped into a family, while the DirectWrite API, Core Text API, and other platforms support font families with a variety of weights, widths, and slopes (see Appendix A: Mapping platform font properties to CSS properties for more details).
See § 5.1 Localized name matching below for information on how font-family names are matched.
2.1.5. Generic font families
A generic font family is a font family which has a standard name (as defined by CSS), but which is an alias for an existing installed font family present on the system. However, a single generic font family may be a composite face combining different typefaces based on such things as the Unicode range of the character, the content language of the containing element, user preferences, system settings, etc. Different generic font families may map to the same used font.
Tests
Note: Generic font families are intended to be widely implemented on many platforms, unlike arbitrary <font-family-name>s which are usually platform-specific names. They are expected to map to different fonts on different platforms. Authors may specify these generic family names if they desire their text to follow a particular design on many platforms, and are not particular about which specific font is chosen on those platforms.
User agents should provide reasonable default choices for the generic font families, that express the characteristics of each family as well as possible, within the limits allowed by the underlying technology. User agents are encouraged to allow users to select alternative faces for the generic font families.
- serif
-
Serif fonts represent
glyphs that have finishing strokes,
flared or tapering ends,
or have actual serifed endings (including slab serifs).
Serif fonts are typically proportionately-spaced.
They often display a greater variation between thick and thin strokes
than fonts from the sans-serif generic font family.
Note: serif and sans-serif only apply to a small handful of writing scripts. Their use as generic font families in CSS is historical, and reflects the Latin-centric nature of early Web development. Better and more widely applicable names would have been, for example, "modulated" and "monoline". However, for reasons of Web compatibility, these names cannot be changed.
CSS uses the term "serif" to apply to a font for any script, although other names might be more familiar for particular scripts, such as Mincho (Japanese), Sung or Song (Chinese), Batang (Korean). For Arabic, the Naskh style would correspond to serif.
serif must always map to at least one matched font face.
Note: No guarantee is placed on the character coverage of that font face. Therefore, the font serif is mapped to may not end up being used for all content.
Sample serif fonts - sans-serif
-
Glyphs in sans-serif fonts,
as the term is used in CSS,
are generally low contrast
(vertical and horizontal stems have the close to the same thickness)
and have stroke endings that are plain
(without any flaring, cross stroke, or other ornamentation).
Sans-serif fonts are typically proportionately-spaced.
They often have little variation between thick and thin strokes,
compared to fonts from the serif family.
CSS uses the term "sans-serif" to apply to a font for any script,
although other names might be more familiar for particular scripts,
such as Gothic (Japanese),
Hei (Chinese),
or Gulim (Korean).
sans-serif must always map to at least one matched font face.
Note: No guarantee is placed on the character coverage of that font face. Therefore, the font sans-serif is mapped to may not end up being used for all content.
Sample sans-serif fonts - cursive
-
Glyphs in cursive fonts generally use a script style,
and the result looks more like handwritten pen or brush writing than printed letterwork.
CSS uses the term "cursive" to apply to a font for any script,
although other names such as Chancery, Brush, Swing and Script are also used in font names.
Sample cursive fonts - fantasy
-
Fantasy fonts are primarily decorative or expressive fonts
that contain decorative or expressive representations of characters.
These do not include Pi or Picture fonts which do not represent actual characters.
Sample fantasy fonts - monospace
-
The sole criterion of a monospace font is that all glyphs have the same fixed width.
This is often used to render samples of computer code.
monospace must always map to at least one matched font face.
Note: No guarantee is placed on the character coverage of that font face. Therefore, the font monospace is mapped to may not end up being used for all content.
Sample monospace fonts - system-ui
-
This generic font family lets text render with the default user interface font
(which, as with all § 2.1.5 Generic font families, may be a composite font)
on the platform on which the UA is running.
A cross-platform UA should use different fonts on its different supported platforms.
The purpose of system-ui is to allow web content
to integrate with the look and feel of the native OS.
This is useful for hybrid, web or cross-platform applications.
Tests
- system-ui-ar.html (live test) (source)
- system-ui-ja-vs-zh.html (live test) (source)
- system-ui-ja.html (live test) (source)
- system-ui-mixed.html (live test) (source)
- system-ui-ur-vs-ar.html (live test) (source)
- system-ui-ur.html (live test) (source)
- system-ui-zh.html (live test) (source)
- system-ui.html (live test) (source)
The precise font(s) used will depend on factors such as platform support, platform language, locale settings, user preferences, Unicode coverage and the content language. UA may optionally choose to use the text rendering engine provided by the platform when using system-ui to match the appearance of the default user interface more closely.
As with other generic font families, the substitution of specific installed fonts for system-ui does not affect the computed style.<div id=
"system-text" style="font-family: system-ui" ></div> ... window.getComputedStyle ( document.getElementById ( "system-text" )