The CSS Fonts Level 4 specification ([CSS-FONTS-4]) describes the controls CSS provides for selecting and using fonts within documents, including support for variable fonts and color fonts. The ideas here are additions or modifications to the properties and rules defined in CSS Fonts Level 4.
This specification is currently a delta to the CSS Fonts Level 4 specification. Do not assume that if something is not here, it has been dropped.
1.1. Value DefinitionsThis 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.
2. Basic Font Properties 2.1. Font family: the font-family property 2.1.1. Generic font familiesIn addition to the CSS Fonts 4 § 2.1.5 Generic font families in CSS Fonts Level 4, the following new generic font families are also defined.
For any given font size, the apparent size and effective legibility of text varies across fonts as a function of their design. For example, for bicameral scripts such as Latin or Cyrillic that distinguish between upper and lowercase letters, the relative height of lowercase letters compared to their uppercase counterparts is a determining factor of legibility. In situations where font fallback occurs, fallback fonts might not share the same ratios as the desired font family for key typographic metrics, and will thus appear to be a different size and possibly be less readable.
TestsThe font-size-adjust property provides a way to preserve the readability and apparent size of text when font fallback occurs. It does this by adjusting the used font size so that the specified metric is the same regardless of the font used.
Values have the following meanings:
u = ( m / m′ ) s
where:
s = computed 'font-size!!property' value m = metric as specified by the 'font-size-adjust' property m′ = metric as specified in the actual font u = adjusted font-size to use
Negative values are invalid.
The style defined below defines Verdana as the desired font family, but if Verdana is not available Futura or Times will be used. One paragraph also has font-size-adjust specified.
p { font-family: Verdana, Futura, Times; } p.adj { font-size-adjust: 0.545; } <p>Lorem ipsum dolor sit amet, ...</p> <p class="adj">Lorem ipsum dolor sit amet, ...</p>
Verdana has a relatively high aspect value of 0.545, meaning lowercase letters are relatively tall compared to uppercase letters, so at small sizes text appears legible. Times has a lower aspect value of 0.447, and so if fallback occurs, the text will be less legible at small sizes than Verdana unless font-size-adjust is also specified.
Note: For text which uses diacritics, too large an x-height will actually decrease legibility as the diacritics become cramped.
How text rendered in each of these fonts compares is shown below, the columns show text rendered in Verdana, Futura and Times. The same font-size value is used across cells within each row and red lines are included to show the differences in x-height. In the upper half, each row is rendered in the same font-size value. The same is true for the lower half, but in this half the font-size-adjust property is also set to 0.545, so that the actual font size is adjusted to preserve the x-height of Verdana across each row. Note how small text remains relatively legible across each row in the lower half.
Text with and without the use of font-size-adjustThe value of font-size-adjust affects the used value of font-size but does not affect the computed value. Therefore it can affect the size of relative units that are based on font metrics such as ex
and ch
but does not affect the size of em
units. Since numeric values of line-height refer to the computed size of font-size, font-size-adjust also does not affect the used value of line-height.
Note: Since font-size-adjust does not factor into the line-height, specifying a line height too tightly can result in overlapping lines of text. For example, when a fallback font with a low aspect value is normalized to match one with a high aspect value, its ascenders and descenders are likely to extend outside the line box with line-height: 1.
The font-size-adjust adjustment applies to any font that is selected but in typical usage it would be based on the corresponding metric value of the first (most desired) font in the font-family list. If this is specified accurately, the ( m/m′ )
term in the adjustment formula will resolve to 1
for the first font and no adjustment occurs for that font; and the rest of the fonts will resolve to match. If the value is specified inaccurately, text rendered using the first font in the family list will display differently in older user agents that don’t support font-size-adjust.
Authors can calculate the
aspect valuefor a given font by comparing spans with the same content but different
font-size-adjustproperties. If the same font-size is used, the spans will match when the
font-size-adjustvalue is accurate for the given font.
Two spans with borders are used to determine the aspect value of a font. The font-size is the same for both spans but the font-size-adjust property is specified only for the right span. Starting with a value of 0.5, the aspect value can be adjusted until the borders around the two letters line up.
p { font-family: Futura; font-size: 500px; } span { border: solid 1px red; } .adjust { font-size-adjust: 0.5; } <p><span>b</span><span class="adjust">b</span></p>Futura with an aspect value of 0.5
The box on the right is a bit bigger than the one on the left, so the aspect value of this font is something less than 0.5. Adjust the value until the boxes align.
Note: If the specified metric has been overridden in @font-face, e.g. by size-adjust, then the overridden metric will be used in the font-size-adjust calculation. Consequently, applying font-size-adjust and size-adjust together means that size-adjust appears to have no effect.
3. Font Resources 3.1. The @font-face ruleNote: Descriptors are applied per-font rather than per-element. Multiple fonts can be used within an individual element e.g. for characters not supported by the first available font.
3.2. Font reference: the src descriptor 3.2.1. Parsing the src descriptorThe src descriptor value must be parsed according to section CSS Syntax 3 § 5.4.10 Parse a comma-separated list of component values. Then each component value is parsed according to this grammar:
<url> [ format(<font-format>)]? [ tech( <font-tech>#)]? | local(<family-name>)
<font-format>= [<string> | collection | embedded-opentype | opentype | svg | truetype | woff | woff2 ]
<font-tech>= [<font-features-tech> | <color-font-tech> | variations | palettes | incremental ]
<font-features-tech>= [features-opentype | features-aat | features-graphite]
<color-font-tech>= [color-COLRv0 | color-COLRv1 | color-SVG | color-sbix | color-CBDT ]
If a component value is parsed correctly and is a supported CSS Fonts 4 § 11.2 Font formats or CSS Fonts 4 § 11.1 Font tech, add it to the list of supported sources. If parsing a component value results in a parsing error or its format or tech are unsupported, do not add it to the list of supported sources.
If there are no supported entries at the end of this process, the value for the src descriptor is a parse error.
These parsing rules allow for graceful fallback of fonts for user agents which don’t support a particular font tech or font format.
For example, when incremental transfer is not supported, a woff2 compressed version of the font is supplied, for optimal performance. Then, for
incremental transfer, the raw uncompressed OpenType font is provided, portions of which will be loaded on demand.
@font-face { font-family: "MyIncrementallyLoadedWebFont"; src: url("FallbackURLForBrowsersWhichDontSupportIncrementalLoading.woff2") format("woff2"); src: url("MyIncrementallyLoadedWebFont.otf") format(opentype) tech(incremental); }3.3. Font property descriptors: the font-size
The size-adjust descriptor defines a multiplier for glyph outlines and metrics associated with this font, to allow the author to harmonize the designs of various fonts when rendered at the same font-size.
All metrics associated with this font—including glyph advances, baseline tables, and overrides provided by @font-face descriptors—are scaled by the given percentage, as are the rendered glyph images. Consequently, any values derived from font metrics (such as ex and ch units, or the from-font value of text-decoration-thickness) are also affected when sourced from this font. However, the computed font-size (and thus any values that derive from it, such as em units, percentages in text-underline-offset, etc.) remains unaffected.
Note: The size-adjust descriptor functions similarly to the font-size-adjust property, which essentially calculates an adjustment per font by matching ex heights, but likewise does not affect the computed font-size.
TestsThe ascent-override, descent-override, and line-gap-override descriptors specify the ascent metric, descent metric, and line gap metric of the font, respectively. The first value provides the value for the x axis, and the second value provides the value for the y axis (defaulting to normal if omitted).
@font-face
block.
Note: Since there are multiple sources of such metrics in some font formats, this can result in text layout that varies across UAs/platforms.
The font-size-adjust property is applied after the size-adjust descriptor.
Note: The consequence of applying font-size-adjust after size-adjust is that size-adjust appears to have no effect.
Note: None of these descriptors affect the computation of font-size, line-height, or font-relative lengths. They can, however, affect the behavior of line-height: normal and more generally the baseline alignment of inline-level content.
Note: Since these metrics are only applicable in the block axis, the y-axis value will only be used when typesetting upright in vertical typographic modes.
The percentage is resolved against different font sizes for different elements.
@font-face { font-family: overridden-font; ascent-override: 50%; ... } <span style="font-family: overridden-font; font-size: 20px;"> Outer span content <span style="font-size: 150%;">Inner span content</span> </span>
The outer span uses an ascent value of 10px, whereas the inner span uses 15px.
We may override the metrics of a local fallback font to match the primary font, which is a web font. This reduces layout shifting when switching from fallback to the primary font.
@font-face { font-family: cool-web-font; src: url("https://example.com/font.woff"); } @font-face { font-family: fallback-to-local; src: local(Some Local Font); /* Override metric values to match cool-web-font */ ascent-override: 125%; descent-override: 25%; line-gap-override: 0%; size-adjust: 96%; } <div style="font-family: cool-web-font, fallback-to-local">Title goes here</div> <img src="https://example.com/largeimage" alt="A large image that you don’t want to shift">
The image will not be shifted as much when the user agent finishes loading and switches to use the web font (assuming the override values are similar to the web font’s natural metrics).
3.6. Superscript and subscript metrics overrides: the superscript-position-override, subscript-position-override,superscript-size-override and subscript-size-override descriptorsThe superscript-position-override, subscript-position-override, superscript-size-override, and subscript-size-override descriptors specify the superscript offset, subscript offset, superscript size, and subscript size metrics of the font, respectively, which are used to synthesize glyphs when required by font-variant-position. The first value provides the value for the x axis, and the second value provides the value for the y axis (defaulting to the first value if omitted).
Note: Since these metrics are only applicable in the block axis, the y-axis value will only be used when typesetting upright in vertical typographic modes.
4. Font Feature Properties 4.1. Font language override: the font-language-override property 5. Font Feature and Variation Resolution 6. Font Variation Properties 6.1. Optical sizing control: the font-optical-sizing property 7. Font Technologies and Formats 7.1. Font techThis section expands upon CSS Fonts 4 § 11.1 Font tech.
The avar2 tech refers to support for version 2 of OpenType axis variations [avar2], for flexible variation axis remapping.
For example, a font using variation axis remapping is loaded only if supported:
@font-face { font-family: 'Roboto Flex'; src: url('RobotoFlex-VF-avar2.woff2') format(woff2) tech(variations, avar2); src: url('RobotoFlex-VF.woff2') format(woff2) tech(variations); font-weight: 100 1000; font-stretch: 25% 151%; }8. Object Model
This section expands upon CSS Fonts 4 § 12. Object Model.
The contents of @font-face and @font-feature-values rules can be accessed via the following extensions to the CSS Object Model.
Tests 8.1. TheCSSFontFaceRule
interface
The CSSFontFaceRule interface represents a <@font-face> rule.
[Exposed=Window] interface9. Security ConsiderationsCSSFontFaceDescriptors
: CSSStyleDeclaration { attribute [LegacyNullToEmptyString] CSSOMStringsrc
; attribute [LegacyNullToEmptyString] CSSOMStringfontFamily
; attribute [LegacyNullToEmptyString] CSSOMStringfont-family
; attribute [LegacyNullToEmptyString] CSSOMStringfontStyle
; attribute [LegacyNullToEmptyString] CSSOMStringfont-style
; attribute [LegacyNullToEmptyString] CSSOMStringfontWeight
; attribute [LegacyNullToEmptyString] CSSOMStringfont-weight
; attribute [LegacyNullToEmptyString] CSSOMStringfontStretch
; attribute [LegacyNullToEmptyString] CSSOMStringfont-stretch
; attribute [LegacyNullToEmptyString] CSSOMStringfontWidth
; attribute [LegacyNullToEmptyString] CSSOMStringfont-width
; attribute [LegacyNullToEmptyString] CSSOMStringfontSize
; attribute [LegacyNullToEmptyString] CSSOMStringfont-size
; attribute [LegacyNullToEmptyString] CSSOMStringsizeAdjust
; attribute [LegacyNullToEmptyString] CSSOMStringsize-adjust
; attribute [LegacyNullToEmptyString] CSSOMStringunicodeRange
; attribute [LegacyNullToEmptyString] CSSOMStringunicode-range
; attribute [LegacyNullToEmptyString] CSSOMStringfontFeatureSettings
; attribute [LegacyNullToEmptyString] CSSOMStringfont-feature-settings
; attribute [LegacyNullToEmptyString] CSSOMStringfontVariationSettings
; attribute [LegacyNullToEmptyString] CSSOMStringfont-variation-settings
; attribute [LegacyNullToEmptyString] CSSOMStringfontNamedInstance
; attribute [LegacyNullToEmptyString] CSSOMStringfont-named-instance
; attribute [LegacyNullToEmptyString] CSSOMStringfontDisplay
; attribute [LegacyNullToEmptyString] CSSOMStringfont-display
; attribute [LegacyNullToEmptyString] CSSOMStringfontLanguageOverride
; attribute [LegacyNullToEmptyString] CSSOMStringfont-language-override
; attribute [LegacyNullToEmptyString] CSSOMStringascentOverride
; attribute [LegacyNullToEmptyString] CSSOMStringascent-override
; attribute [LegacyNullToEmptyString] CSSOMStringdescentOverride
; attribute [LegacyNullToEmptyString] CSSOMStringdescent-override
; attribute [LegacyNullToEmptyString] CSSOMStringlineGapOverride
; attribute [LegacyNullToEmptyString] CSSOMStringline-gap-override
; attribute [LegacyNullToEmptyString] CSSOMStringsuperscriptPositionOverride
; attribute [LegacyNullToEmptyString] CSSOMStringsuperscript-position-override
; attribute [LegacyNullToEmptyString] CSSOMStringsubscriptPositionOverride
; attribute [LegacyNullToEmptyString] CSSOMStringsubscript-position-override
; attribute [LegacyNullToEmptyString] CSSOMStringsuperscriptSizeOverride
; attribute [LegacyNullToEmptyString] CSSOMStringsuperscript-size-override
; attribute [LegacyNullToEmptyString] CSSOMStringsubscriptSizeOverride
; attribute [LegacyNullToEmptyString] CSSOMStringsubscript-size-override
; }; [Exposed=Window] interfaceCSSFontFaceRule
: CSSRule { [SameObject, PutForwards=cssText] readonly attribute CSSFontFaceDescriptorsstyle
; };
No new security considerations have been reported on this specification.
10. Privacy ConsiderationsNo new privacy considerations have been reported on this specification.
11. AcknowledgmentsFirstly, the editors would like to thank all of the contributors to the previous level of this module.
Secondly, we would like to acknowledge Dave Crossland from Google, Bernhard Fey from RealObjects, Xiaocheng Hu from Google, Jonathan Kew from Mozilla, and Laurence Penney for their contributions to the improvements in this Level 5.
12. Changes 12.1. Changes since the WD of 6 February 2024Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.
All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]
Examples in this specification are introduced with the words “for example” or are set apart from the normative text with class= "example"
, like this:
Informative notes begin with the word “Note” and are set apart from the normative text with class= "note"
, like this:
Note, this is an informative note.
Advisements are normative sections styled to evoke special attention and are set apart from other normative text with <strong class= "advisement" >
, like this: UAs MUST provide an accessible alternative.
A style sheet is conformant to this specification if all of its statements that use syntax defined in this module are valid according to the generic CSS grammar and the individual grammars of each feature defined in this module.
A renderer is conformant to this specification if, in addition to interpreting the style sheet as defined by the appropriate specifications, it supports all the features defined by this specification by parsing them correctly and rendering the document accordingly. However, the inability of a UA to correctly render a document due to limitations of the device does not make the UA non-conformant. (For example, a UA is not required to render color on a monochrome monitor.)
An authoring tool is conformant to this specification if it writes style sheets that are syntactically correct according to the generic CSS grammar and the individual grammars of each feature in this module, and meet all other conformance requirements of style sheets as described in this module.
So that authors can exploit the forward-compatible parsing rules to assign fallback values, CSS renderers must treat as invalid (and ignore as appropriate) any at-rules, properties, property values, keywords, and other syntactic constructs for which they have no usable level of support. In particular, user agents must not selectively ignore unsupported component values and honor supported values in a single multi-value property declaration: if any value is considered invalid (as unsupported values must be), CSS requires that the entire declaration be ignored.
Once a specification reaches the Candidate Recommendation stage, non-experimental implementations are possible, and implementors should release an unprefixed implementation of any CR-level feature they can demonstrate to be correctly implemented according to spec.
To establish and maintain the interoperability of CSS across implementations, the CSS Working Group requests that non-experimental CSS renderers submit an implementation report (and, if necessary, the testcases used for that implementation report) to the W3C before releasing an unprefixed implementation of any CSS features. Testcases submitted to W3C are subject to review and correction by the CSS Working Group.
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