CSS font-optical-sizing Property
The font-optical-sizing property controls whether a variable font automatically adjusts its letterforms to suit the displayed text size.
Optical sizing allows compatible fonts to use different design characteristics for small text and large headings. These adjustments may affect stroke contrast, proportions, spacing, and fine details. The property works with fonts that provide an optical size axis, identified by the OpenType tag opsz.
font-optical-sizing Syntax
The font-optical-sizing property accepts two values: auto and none.
Basic Syntax
selector {
font-optical-sizing: auto;
}
Enable Optical Sizing
selector {
font-optical-sizing: auto;
}
Disable Optical Sizing
selector {
font-optical-sizing: none;
}
CSS-Wide Keywords
.example {
font-optical-sizing: inherit;
}
.example {
font-optical-sizing: initial;
}
.example {
font-optical-sizing: unset;
}
.example {
font-optical-sizing: revert;
}
.example {
font-optical-sizing: revert-layer;
}
The property does not accept lengths, percentages, or numeric optical size values. To specify an optical size axis value directly, use font-variation-settings with the "opsz" axis.
Property Values
The two supported values determine whether optical size adjustments are selected automatically.
| Value | Description |
|---|---|
auto |
Enables automatic optical sizing when the selected font supports it. |
none |
Disables automatic optical sizing, leaving the optical size axis at its default unless explicitly controlled elsewhere. |
CSS-Wide Values
| Value | Description |
|---|---|
inherit |
Uses the computed value of the parent element. |
initial |
Restores the initial value, auto. |
unset |
Uses the inherited value because the property is inherited. |
revert |
Reverts the property according to CSS cascade origins. |
revert-layer |
Reverts the property according to CSS cascade layers. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | auto |
| Inherited | Yes |
| Applies to | All elements and text |
| Computed value | As specified |
| Animation type | Discrete |
| Percentages | Not applicable |
Optical sizing only produces a visible result when the selected font contains an optical size axis with designs that differ across its supported range.
How It Works
Some variable fonts contain multiple design variations intended for different text sizes. Instead of simply scaling the same letterforms, the font can adjust their shapes to improve their appearance at different sizes.
Step 1: Select a Compatible Font
.example {
font-family: "Example Variable Font", serif;
}
The selected font must provide an optical size axis for automatic optical sizing to have an effect.
Step 2: Specify the Font Size
.example {
font-family: "Example Variable Font", serif;
font-size: 18px;
}
Step 3: Enable Optical Sizing
.example {
font-family: "Example Variable Font", serif;
font-size: 18px;
font-optical-sizing: auto;
}
Step 4: Select an Optical Design
The browser uses the text size to select an appropriate position on the font's optical size axis, subject to the font's supported axis range.
Step 5: Render the Text
The font may adjust stroke contrast, character proportions, spacing, or other details to suit the selected size.
Important Consideration
The browser does not invent optical size variations. The selected font must contain the necessary variable font data.
The auto Value
The auto value enables automatic optical sizing when supported by the selected font.
Enable Optical Sizing
.example {
font-optical-sizing: auto;
}
Small Text
.small-text {
font-family: "Example Variable Font", serif;
font-size: 12px;
font-optical-sizing: auto;
}
At smaller sizes, a compatible font may use sturdier strokes, reduced contrast, or more open shapes to improve legibility.
Large Text
.large-text {
font-family: "Example Variable Font", serif;
font-size: 56px;
font-optical-sizing: auto;
}
At larger sizes, a compatible font may use finer details or different proportions intended for display typography.
Apply Optical Sizing Throughout a Page
body {
font-optical-sizing: auto;
}
Because the property is inherited, descendants generally receive the setting unless another rule overrides it.
Important Consideration
The auto value is the initial value. You generally do not need to declare it unless you want to make the intended behavior explicit or override an earlier none declaration.
The none Value
The none value disables automatic optical sizing.
Disable Optical Sizing
.example {
font-optical-sizing: none;
}
Disable Optical Sizing for a Heading
.heading {
font-family: "Example Variable Font", serif;
font-size: 48px;
font-optical-sizing: none;
}
Compare Both Values
.optical-enabled {
font-optical-sizing: auto;
}
.optical-disabled {
font-optical-sizing: none;
}
When Disabling Optical Sizing May Be Useful
Disabling automatic optical sizing can be useful when maintaining a particular font appearance across different text sizes or when comparing variable font designs.
Important Consideration
The none value disables automatic selection of the optical size axis. It does not prevent an explicit "opsz" value in font-variation-settings from controlling that axis.
The Optical Size Axis
Variable fonts use registered variation axes to control different aspects of their design. Optical sizing uses the registered OpenType axis opsz.
Common Variable Font Axes
| Axis | Purpose |
|---|---|
opsz |
Controls optical size adjustments. |
wght |
Controls font weight. |
wdth |
Controls font width. |
slnt |
Controls slant angle. |
ital |
Controls italic variation. |
Automatic Optical Size Selection
.example {
font-size: 24px;
font-optical-sizing: auto;
}
The browser determines the appropriate optical size axis value using the text size and the font's supported range.
Manual Optical Size Selection
.example {
font-optical-sizing: none;
font-variation-settings: "opsz" 24;
}
This requests a specific optical size axis value rather than relying on automatic selection.
Important Consideration
The supported optical size range varies by font. The opsz axis is expressed in typographic points, and automatic selection accounts for the conversion from CSS pixels to points.
Optical Sizing and font-size
The font-size property determines the size at which text is displayed. Optical sizing uses that size to select an appropriate font design.
Small Text Example
.caption {
font-size: 12px;
font-optical-sizing: auto;
}
Body Text Example
.body-text {
font-size: 16px;
font-optical-sizing: auto;
}
Display Text Example
.display-heading {
font-size: 64px;
font-optical-sizing: auto;
}
Comparison
| Property | Purpose |
|---|---|
font-size |
Controls the displayed size of text. |
font-optical-sizing |
Controls whether the font design adapts automatically to the displayed size. |
Important Consideration
Optical sizing does not replace font-size. It changes the design selected within a compatible font, not the CSS size assigned to the text.
Variable Font Requirements
Automatic optical sizing requires a font that provides an optical size variation axis.
Compatible Variable Font
.example {
font-family: "Example Optical Variable Font", serif;
font-optical-sizing: auto;
}
Font Without an Optical Size Axis
.example {
font-family: Arial, sans-serif;
font-optical-sizing: auto;
}
If the selected font does not provide an optical size axis, the property does not produce an optical size variation.
Loading a Variable Font
@font-face {
font-family: "Example Variable Font";
src: url("/fonts/example-variable.woff2") format("woff2");
font-weight: 100 900;
font-style: normal;
}
.example {
font-family: "Example Variable Font", sans-serif;
font-optical-sizing: auto;
}
This example illustrates how a variable font can be declared using @font-face. The font file must contain an optical size axis for optical sizing to work.
Font Documentation
Check the variable font's documentation or inspect its available axes to confirm that opsz is supported.
Important Consideration
Not all variable fonts support optical sizing. A font may provide weight or width variations without including an optical size axis.
Relationship with font-variation-settings
The font-optical-sizing property provides a high-level way to control optical size selection. The font-variation-settings property provides low-level access to individual variable font axes.
Automatic Optical Sizing
.example {
font-optical-sizing: auto;
}
Manual Optical Size Axis
.example {
font-optical-sizing: none;
font-variation-settings: "opsz" 18;
}
Multiple Variable Font Axes
.example {
font-optical-sizing: none;
font-variation-settings: "opsz" 24, "wght" 600;
}
This requests an optical size axis value of 24 and a weight axis value of 600, assuming the font supports both axes.
High-Level vs. Low-Level Control
| Property | Purpose |
|---|---|
font-optical-sizing |
Enables or disables automatic optical size selection. |
font-variation-settings |
Specifies numeric values for individual variable font axes. |
Important Consideration
An explicitly specified "opsz" value in font-variation-settings takes precedence over automatic optical sizing for that axis. Use the high-level property when automatic sizing is the intended behavior.
Optical Sizing vs. Kerning
Optical sizing and kerning can both improve typography, but they affect different aspects of font rendering.
Optical Sizing
.example {
font-optical-sizing: auto;
}
Optical sizing selects size-appropriate designs within a compatible variable font.
Kerning
.example {
font-kerning: normal;
}
Kerning applies font-defined spacing adjustments between particular glyph pairs.
Using Both Properties
.heading {
font-family: "Example Variable Font", serif;
font-size: 48px;
font-optical-sizing: auto;
font-kerning: normal;
}
Comparison
| Property | Purpose |
|---|---|
font-optical-sizing |
Selects size-appropriate font designs. |
font-kerning |
Controls spacing adjustments between specific glyph pairs. |
Important Consideration
Both properties depend on capabilities provided by the selected font. They can be used together when the font supports both optical sizing and kerning.
Inheritance
The font-optical-sizing property is inherited, allowing descendants to use the same setting unless another declaration overrides it.
Enable Optical Sizing for a Container
.article {
font-optical-sizing: auto;
}
Disable Optical Sizing for a Child
.article {
font-optical-sizing: auto;
}
.article .special-heading {
font-optical-sizing: none;
}
Explicit Inheritance
.child {
font-optical-sizing: inherit;
}
Reset to the Initial Value
.child {
font-optical-sizing: initial;
}
The initial value is auto.
Important Consideration
Inheritance controls whether automatic optical sizing is requested. Each text element can still use a different optical design because the selected value depends on its font size and font capabilities.
font-optical-sizing Example
This example compares automatic optical sizing with optical sizing disabled. It uses a variable font that provides an optical size axis so the difference can be observed in supporting browsers.
The example loads the variable version of Roboto Serif from Google Fonts. The selected font includes an optical size axis, allowing the browser to choose different designs for different text sizes.
HTML Example
<div class="optical-sizing-demo">
<p class="demo-label">Optical sizing enabled - 16px</p>
<p class="demo-small-auto">Readable typography at smaller sizes.</p>
<p class="demo-label">Optical sizing disabled - 16px</p>
<p class="demo-small-none">Readable typography at smaller sizes.</p>
<p class="demo-label">Optical sizing enabled - 40px</p>
<p class="demo-large-auto">Variable Fonts</p>
<p class="demo-label">Optical sizing disabled - 40px</p>
<p class="demo-large-none">Variable Fonts</p>
</div>
CSS Example
@import url("https://fonts.googleapis.com/css2?family=Roboto+Serif:opsz,wght@8..144,400&display=swap");
.optical-sizing-demo {
font-family: "Roboto Serif", Georgia, serif;
}
.optical-sizing-demo p {
margin: 0 0 12px;
}
.optical-sizing-demo .demo-label {
font: 600 13px/1.4 Arial, sans-serif;
}
.demo-small-auto {
font-size: 16px;
font-optical-sizing: auto;
}
.demo-small-none {
font-size: 16px;
font-optical-sizing: none;
}
.demo-large-auto {
font-size: 40px;
font-optical-sizing: auto;
}
.demo-large-none {
font-size: 40px;
font-optical-sizing: none;
}
Optical sizing enabled - 16px
Readable typography at smaller sizes.
Optical sizing disabled - 16px
Readable typography at smaller sizes.
Optical sizing enabled - 40px
Variable Fonts
Optical sizing disabled - 40px
Variable Fonts
With font-optical-sizing: auto, the browser requests optical designs appropriate for the specified font sizes. With none, automatic optical size selection is disabled.
The differences may include changes in stroke contrast, spacing, and letterform details. If the web font cannot load, the fallback font may not provide an optical size axis, and the examples may look identical.
Common Mistakes
Optical sizing is often confused with font size, font weight, or manual variable font axis control.
Using a Numeric Value
.example {
font-optical-sizing: 24;
}
This declaration is invalid. The property accepts auto or none, not a numeric optical size.
Using a Length Value
.example {
font-optical-sizing: 24px;
}
Lengths are not accepted. Use font-size to set the displayed text size.
Using an Unsupported Font
.example {
font-family: Arial, sans-serif;
font-optical-sizing: auto;
}
A font without an optical size axis cannot provide automatic optical size variations.
Assuming All Variable Fonts Support Optical Sizing
Some variable fonts provide only weight or width axes. The font must include an opsz axis for this property to produce an optical size variation.
Confusing Optical Sizing with Font Weight
Optical sizing can affect stroke appearance, but it is not a replacement for font-weight.
Confusing Optical Sizing with Kerning
Optical sizing selects size-appropriate font designs, while kerning adjusts spacing between particular glyph pairs.
Overriding Automatic Optical Sizing
.example {
font-optical-sizing: auto;
font-variation-settings: "opsz" 24;
}
The explicit "opsz" axis value takes precedence over automatic optical size selection. Remove the manual axis setting when automatic behavior is desired.
Expecting Identical Results Across Fonts
Different fonts implement optical size variations differently. The same CSS property can produce subtle changes in one font and more noticeable changes in another.
Important Considerations
Keep the following points in mind when using the font-optical-sizing property:
- Purpose: Controls automatic optical size selection in compatible variable fonts.
- Initial value:
auto. - Inheritance: The property is inherited.
- Applies to: All elements and text.
- Accepted values:
autoandnone. - auto: Enables automatic optical sizing when supported by the font.
- none: Disables automatic optical size selection.
- Variable font requirement: The font must provide an optical size axis.
- OpenType axis: Optical sizing uses the registered
opszaxis. - Font size: Automatic optical size selection depends on the displayed text size.
- Small text: Optical designs may improve legibility through sturdier strokes or adjusted proportions.
- Large text: Optical designs may provide finer details or different stroke contrast.
- Font dependency: The visual effect depends on the selected font's available variations.
- Manual control: Use
font-variation-settingsto specify an optical size axis value directly. - Axis precedence: Explicit
"opsz"values take precedence over automatic optical sizing. - Font weight: Use
font-weightto control weight independently. - Kerning: Use
font-kerningfor font-defined glyph spacing adjustments. - Fallback fonts: A fallback font without an optical size axis may show no difference.
- Animation: The property uses discrete animation behavior.
- Browser support: The property is widely supported in modern browsers.
Use font-optical-sizing: auto when working with variable fonts that provide optical size variations. It allows the browser to select size-appropriate font designs without manually specifying optical size axis values.
Browser Support
The CSS font-optical-sizing property is Widely available in modern browsers, including Chrome, Edge, Firefox, and Safari.
Support for the CSS property does not guarantee a visible change. The selected font must contain an optical size axis, and the browser must be able to use the font's variation data.
Supported Example
.example {
font-optical-sizing: auto;
}
Feature Detection
@supports (font-optical-sizing: auto) {
.example {
font-optical-sizing: auto;
}
}
The @supports rule checks whether the browser recognizes the declaration. It does not confirm that the selected font includes an opsz axis.
Compatibility Considerations
Test optical sizing with the actual variable fonts used on the website. When the selected font lacks an optical size axis, text continues rendering without automatic optical size variations.
For current compatibility information, visit Can I Use? and search for font-optical-sizing.
Specifications
The font-optical-sizing property is defined in the CSS Fonts Module, which describes automatic optical size selection and its relationship with variable font axes.
CSS Fonts Module Level 4: font-optical-sizing Property
Variable font axes, including the optical size axis, are defined in the OpenType specification.
OpenType Design-Variation Axis Tag Registry: opsz
For additional explanations and examples, see MDN Web Docs.
