I have a non standarnd font file that font weight values are variable from 38 to 682 and any value in this range can be used.
When in css I write font-weight: bold;
by default it change to font-weight: 700;
and because it is over 682 it is Ultra bold.
Is there any way to tell css that change font-weight: bold;
to something like font-weight: 249;
? We don’t want to use 249 directly in css in case font change later.
This is how font defined:
@font-face {
font-family: "Font Name";
src: url("Font-Name-Variable.woff2") format("woff2 supports variations");
font-weight: 38 682;
font-style: normal;
font-display: swap;
}
2
Answers
When using a variable font, you can specify the integer values as font-weight property values. E.g.,
See https://www.w3.org/TR/css-fonts-4/#font-weight-prop for specific details.
You could map specific font-weights to a specific weight-axis value by adding a
font-variation-settings
property to you@font-face
rule.Unfortunately, only Firefox currently supports
font-variation-settings
in font-face – they are well supported in element style rules (See caniuse record).The above example maps the regular weight to
font-variation-settings: "wght" 720
and bold to"wght" 150
.So to this date you need to write adjust your style rules and add the specific axis values or weights.