Variable fonts and font features
Definition and purpose
A variable font can describe a continuous range along axes such as weight (wght) and width (wdth). The actual ranges and supported axes come from the font, not CSS alone. Standard font-weight and font-stretch controls are preferable for registered axes when available; font-variation-settings is a low-level override.
Request a weight axis
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #a { font-variation-settings: "wght" 650; font-weight: 600; } </style> </head> <body> <p id="a">Variable type sample 123</p> </body></html>The computed axis override is 650; the computed font-weight remains 600. A compatible face is required for the override to affect glyphs.
Syntax and mental model
Each axis tag is a case-sensitive four-character string followed by a numeric value. An axis setting may be ignored by a face that does not implement it. OpenType features are different: font-variant-numeric: tabular-nums requests equal-width figures, while font-feature-settings: "tnum" 1 requests that feature directly. These examples verify CSS selection, not the actual variation or figure widths of an installed font.
Request tabular numerals
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #a { font-variant-numeric: tabular-nums; } </style> </head> <body> <p id="a">Variable type sample 123</p> </body></html>The property requests tabular figures; the actual font may lack them.
Common mistakes
Do not infer the appearance of a variable font from computed settings alone. Check its axis metadata and use appropriate fallback fonts. Avoid unnecessary low-level overrides when high-level properties express the intent.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Font face and loading strategy. Next lesson: Font palettes and feature values.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Variable fonts and font features — knowledge check
Five questions on variable fonts and font features.
What defines supported axis ranges?
Which tag represents the weight axis?
What does tabular-nums request?
Does a computed axis value guarantee a glyph change?
Which is preferred for ordinary weight selection?