CSS fonts
The CSS fonts module defines font-related properties and how font resources are loaded. It lets you define the style of a font, such as its family, size and weight, and the glyph variants to use when multiple are available for a single character.
A font is a resource file containing the visual representation of characters, mapping character codes to glyphs that represent letters, numbers, punctuation and even emojis of a typeface. A font family is a group of fonts that share common design styles and font properties, with each member of the group providing different ways of displaying the glyphs, varying by stroke weight, slant, or relative width, among other attributes. A font typically represents a single style of a typeface, such as Helvetica that is Bold and Italic. A font family is the complete set of styles. Including such a font in a document or design is done by defining a separate @font-face
declaration for each font resource.
The properties, at-rules, and descriptors of the CSS fonts module enable the downloading of multiple variations of a font. They also define the font file to use for a particular font characteristic, along with fallback instructions in case a resource fails to load. The CSS font selection mechanism describes the process of matching a given set of CSS font properties to a single font face.
The CSS fonts module also supports variable fonts. Unlike regular fonts, where each style is implemented as a separate font file, variable fonts can contain all styles within a single file. By using a single @font-face
declaration, you can import a variable font that includes all the styles. Depending on the font, this can include a multitude of font variants. Variable fonts are a part of the OpenType font specification.
Reference
Properties
font
shorthandfont-family
font-feature-settings
font-kerning
font-language-override
font-optical-sizing
font-palette
font-size
font-size-adjust
font-stretch
font-style
font-weight
font-synthesis
shorthandfont-synthesis-small-caps
font-synthesis-style
font-synthesis-weight
font-variant
shorthandfont-variant-alternates
font-variant-caps
font-variant-east-asian
font-variant-emoji
font-variant-ligatures
font-variant-numeric
font-variant-position
font-variation-settings
At-rules and descriptors
- At-rule:
@font-face
-
Descriptors:
- At-rule:
@font-feature-values
-
Descriptor:
- At-rule:
@font-palette-values
-
Descriptors:
Data types
font-size
types:
font-family
type:
font-feature-settings
type:
font-format
type:
font-stretch
type:
font-tech
types:
font-variant
types:
font-variant-ligatures
types:
font-variant-numeric
types:
font-weight
type:
Interfaces
Guides
- Learn: Fundamental text and font styling
-
This beginner's learning article covers the basic fundamentals of text and font styling. It covers how to set the font weight, family, and style by using the
font
shorthand and how to align text and manage line and letter spacing. - Learn: Web fonts
-
This beginner's learning article explains how to use custom fonts on your web page to allow for more varied and custom text styling.
- OpenType font features guide
-
Font features or variants refer to different glyphs or character styles contained within an OpenType font. These include things like ligatures (special glyphs that combine characters like 'fi' or 'ffl'), kerning (adjustments to the spacing between specific letterform pairings), fractions, numeral styles, and a number of others. These are all referred to as OpenType Features, and are made available to use on the web via specific properties and a low-level control property —
font-feature-settings
. This article provides you with all you need to know about using OpenType font features in CSS. - Variable fonts guide
-
This article will help you get started with using variable fonts.
- Improving font performance
-
This article, part of the CSS performance guide, discusses font loading, loading only the required glyphs, and defining font display behavior with the
font-display
descriptor.
Related concepts
letter-spacing
CSS propertyline-height
CSS propertytext-transform
CSS property
Specifications
Specification |
---|
CSS Fonts Module Level 4 |
See also
- CSS font loading module
- CSS font loading API
- CSS text module
- CSS writing modes module