font-feature-settings
Control supported OpenType features with raw tags or named tokens.
Overview
| Class | Declarations |
|---|---|
font-feature-settings:normal | font-feature-settings: normal;
|
font-feature-settings:<value>,<font-feature> | font-feature-settings: <value>,<font-feature>;
|
font-feature-settings:'salt' | font-feature-settings: 'salt';
|
font-feature-settings:'tnum' | font-feature-settings: 'tnum';
|
Examples
Enable a font feature
A quoted four-character tag selects an OpenType feature. Here tnum gives each digit the same advance width in Geist. Compare the two equal-length strings; the feature must exist in the selected font.
<!-- Default proportional digits --><div id="target" class="font-feature-settings:normal font-3xl leading-sm"><span id="ones" class="inline-block">11111</span><br><span id="eights" class="inline-block">88888</span></div><!-- Raw feature · 'tnum' --><div id="target" class="font-feature-settings:'tnum' font-3xl leading-sm"><span id="ones" class="inline-block">11111</span><br><span id="eights" class="inline-block">88888</span></div>Reset features
font-feature-settings:normal removes an inherited raw feature request. It does not reset a separate font-variant-numeric declaration.
<!-- Raw tnum inherited, then reset --><div id="context" class="font-feature-settings:'tnum' font-3xl leading-sm"> <p class="m:0"><span id="inherited" class="inline-block">11111</span></p> <p id="target" class="m:0 font-feature-settings:normal"><span id="ones" class="inline-block">11111</span><br><span id="eights" class="inline-block">88888</span></p></div>Prefer semantic numeric utilities
Use tabular-nums for ordinary numeric formatting. Reserve raw feature settings for font-specific capabilities without a higher-level property.
<!-- font-feature-settings:'tnum' --><div id="target" class="font-feature-settings:'tnum' font-3xl leading-sm"><span id="ones" class="inline-block">11111</span><br><span id="eights" class="inline-block">88888</span></div><!-- tabular-nums --><div id="target" class="tabular-nums font-3xl leading-sm"><span id="ones" class="inline-block">11111</span><br><span id="eights" class="inline-block">88888</span></div>Use feature tokens
Name a repeated feature setting in @theme, then use the token through the same property.
@theme { --font-feature-data: 'tnum';}<!-- A project token for numeric data --><div id="target" class="font-3xl leading-sm font-feature-settings-data"><span id="ones" class="inline-block">11111</span><br><span id="eights" class="inline-block">88888</span></div>Apply conditionally
Hover or keyboard-focus the numeric sample. The raw tnum feature changes the advance widths while the content stays the same.
<!-- Compare proportional and tabular advances --><div id="target" tabindex="0" role="group" aria-label="Numeric feature sample" class="font-feature-settings:normal font-3xl leading-sm font-feature-settings:'tnum':hover font-feature-settings:'tnum':focus-visible"><span id="ones" class="inline-block">11111</span><br><span id="eights" class="inline-block">88888</span></div>