--- title: font-variation-settings slug: Web/CSS/font-variation-settings tags: - font-variation-settings - 可变字体 translation_of: Web/CSS/font-variation-settings ---
font-variation-settings
CSS属性提供了对 variable font 特征的低级控制,通过指定要更改的特征的四个字母轴名称及其值。
font-variation-settings
will always override those set using the corresponding basic font properties, e.g. font-weight
, no matter where they appear in the cascade. In some browsers, this is currently only true when the @font-face
declaration includes a font-weight
range./* Use the default settings */ font-variation-settings: normal; /* Set values for variable font axis names */ font-variation-settings: "XHGT" 0.7; /* Global values */ font-variation-settings: inherit; font-variation-settings: initial; font-variation-settings: unset;
This property's value can take one of two forms:
normal
<string> <number>
<string>
has more or fewer characters or contains characters outside the U+20 - U+7E codepoint range, the whole property is invalid. The <number>
can be fractional or negative, depending on the value range available in your font, as defined by the font designer.{{csssyntax}}
Variable font axes come in two types: registered and custom.
Registered axes are the most commonly encountered — common enough that the authors of the specification felt they were worth standardizing. Note that this doesn't mean that the author has to include all of these in their font.
Here are the registered axes along with their corresponding CSS properties:
Axis Tag | CSS Property |
---|---|
"wght" | {{cssxref("font-weight")}} |
"wdth" | {{cssxref("font-stretch")}} |
"slnt" (slant) | {{cssxref("font-style")}}: oblique + angle |
"ital" | {{cssxref("font-style")}}: italic |
"opsz" |
{{cssxref("font-optical-sizing")}} |
Custom axes can be anything the font designer wants to vary in their font, for example ascender or descender heights, the size of serifs, or anything else they can imagine. Any axis can be used as long as it is given a unique 4-character axis. Some will end up becoming more common, and may even become registered over time.
Note: Registered axis tags are identified using lower-case tags, whereas custom axes should be given upper-case tags. Note that font designers aren't forced follow this practice in any way, and some won't. The important takeaway here is that axis tags are case-sensitive.
See below for interactive examples demonstrating the registered axes. You can find a number of other variable fonts examples at our Variable fonts guide, v-fonts.com, and axis-praxis.org.
Warning: In order to use variable fonts on your operating system, you need to make sure that it is up to date. For example Linux OSes need the latest Linux Freetype version, and macOS prior to 10.13 does not support variable fonts. If your operating system is not up to date, you will not be able to use variable fonts in web pages or the Firefox Developer Tools.
The following live example's CSS can be edited to allow you to play with font weight values.
The following live example's CSS can be edited to allow you to play with font slant/oblique values.
Specification | Status | Comment |
---|---|---|
{{SpecName('CSS4 Fonts', '#low-level-font-variation-settings-control-the-font-variation-settings-property', 'font-variation-settings')}} | {{Spec2('CSS4 Fonts')}} | Initial definition |
{{cssinfo}}
{{Compat("css.properties.font-variation-settings")}}