1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
---
title: font-variation-settings
slug: Web/CSS/font-variation-settings
tags:
- font-variation-settings
- 可变字体
translation_of: Web/CSS/font-variation-settings
---
<div>{{CSSRef}}</div>
<p><strong><code>font-variation-settings</code></strong> CSS属性提供了对 <a href="/en-US/docs/Web/CSS/CSS_Fonts/Variable_Fonts_Guide">variable font</a> 特征的低级控制,通过指定要更改的特征的四个字母轴名称及其值。</p>
<div>{{EmbedInteractiveExample("pages/css/font-variation-settings.html")}}</div>
<div class="note"><strong>Note</strong>: This property is a low-level mechanism designed to set variable font features where no other way to enable or access those features exist. You should only use it when no basic properties exist to set those features (e.g. {{cssxref("font-weight")}}, {{cssxref("font-style")}}).</div>
<div class="note"><strong>Note</strong>: font characteristics set using <code>font-variation-settings</code> will always override those set using the corresponding basic font properties, e.g. <code>font-weight</code>, no matter where they appear in the cascade. <span class="zhc-markdown-block zhc-markdown-block--html">In some browsers, this is currently only true when the <code>@font-face</code> declaration includes a <code>font-weight</code> range.</span></div>
<h2 id="Syntax">Syntax</h2>
<pre class="brush:css no-line-numbers">/* 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;
</pre>
<h3 id="Values">Values</h3>
<p>This property's value can take one of two forms:</p>
<dl>
<dt><code>normal</code></dt>
<dd>Text is laid out using default settings.</dd>
<dt><code><string> <number></code></dt>
<dd>When rendering text, the list of variable font axis names is passed to the text layout engine to enable or disable font features. Each setting is always one or more pairs consisting of a {{cssxref("<string>")}} of 4 ASCII characters followed by a {{cssxref("number")}} indicating the axis value to set. If the <code><string></code> has more or fewer characters or contains characters outside the U+20 - U+7E codepoint range, the whole property is invalid. The <code><number></code> can be fractional or negative, depending on the value range available in your font, as defined by the font designer.</dd>
</dl>
<h3 id="Formal_syntax">Formal syntax</h3>
{{csssyntax}}
<h2 id="Registered_and_custom_axes">Registered and custom axes</h2>
<p>Variable font axes come in two types: <strong>registered</strong> and <strong>custom</strong>.</p>
<p>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.</p>
<p>Here are the registered axes along with their corresponding CSS properties:</p>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Axis Tag</th>
<th scope="col">CSS Property</th>
</tr>
</thead>
<tbody>
<tr>
<td>"wght"</td>
<td>{{cssxref("font-weight")}}</td>
</tr>
<tr>
<td>"wdth"</td>
<td>{{cssxref("font-stretch")}}</td>
</tr>
<tr>
<td>"slnt" (slant)</td>
<td>{{cssxref("font-style")}}: <code>oblique + angle</code></td>
</tr>
<tr>
<td>"ital"</td>
<td>{{cssxref("font-style")}}: <code>italic</code></td>
</tr>
<tr>
<td>"opsz"</td>
<td>
<p>{{cssxref("font-optical-sizing")}}</p>
</td>
</tr>
</tbody>
</table>
<p>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.</p>
<div class="note">
<p><strong>Note</strong>: 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.</p>
</div>
<h2 id="Examples">Examples</h2>
<p>See below for interactive examples demonstrating the registered axes. You can find a number of other variable fonts examples at our <a href="/en-US/docs/Web/CSS/CSS_Fonts/Variable_Fonts_Guide">Variable fonts guide</a>, <a class="external external-icon" href="https://v-fonts.com/" rel="noopener">v-fonts.com</a>, and <a class="external external-icon" href="https://www.axis-praxis.org/" rel="noopener">axis-praxis.org</a>.</p>
<div class="warning">
<p><strong>Warning</strong>: 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.</p>
</div>
<h3 id="Weight_wght">Weight (wght)</h3>
<p>The following live example's CSS can be edited to allow you to play with font weight values.</p>
<div>{{EmbedGHLiveSample("css-examples/variable-fonts/weight.html", '100%', 520)}}</div>
<h3 id="Slant_slnt">Slant (slnt)</h3>
<p>The following live example's CSS can be edited to allow you to play with font slant/oblique values.</p>
<div>{{EmbedGHLiveSample("css-examples/variable-fonts/slant.html", '100%', 520)}}</div>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('CSS4 Fonts', '#low-level-font-variation-settings-control-the-font-variation-settings-property', 'font-variation-settings')}}</td>
<td>{{Spec2('CSS4 Fonts')}}</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<p>{{cssinfo}}</p>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{Compat("css.properties.font-variation-settings")}}</p>
<h2 id="See_also">See also</h2>
<ul>
<li><a href="/en-US/docs/Web/CSS/CSS_Fonts/Variable_Fonts_Guide">Variable fonts guide</a></li>
<li><a href="https://www.microsoft.com/typography/otspec180/otvaroverview.htm">OpenType Font Variations Overview</a></li>
<li><a href="https://www.microsoft.com/typography/otspec/dvaraxisreg.htm">OpenType Design-Variation Axis Tag Registry</a></li>
</ul>
<div id="gtx-trans" style="position: absolute; left: 589px; top: 119px;">
<div class="gtx-trans-icon"></div>
</div>
|