Typografia ja teksti

Variable fonts, explained for designers

One file, every weight in between, and type that adjusts itself to the size you set it at. Variable fonts change what a type system can do, if you know which axes to reach for.

GradientlyVahvistettu Gradiently-tili··6 min lukuaika
Kansi: Folded Daybreak · GR·TDKP·D2

Tätä opasta ei ole vielä omalla kielelläsi, joten tässä se on englanniksi.

Lyhyesti

  • A variable font is a single font file that contains a continuous range of styles, such as every weight from thin to black, instead of one file per style.
  • Each range is called an axis; the five standard axes are weight, width, italic, slant and optical size.
  • Variable fonts let you pick in-between values, such as a weight of 450 or 650, and tune type precisely for each size and background.
  • Every current major browser supports variable fonts, and many families on Google Fonts are available as variable files.
  • A variable file can be larger than one static style, so the saving comes when you use several weights or widths from the same family.
Tällä sivulla

Variable fonts are font files that hold a continuous range of styles rather than a fixed set. Instead of separate files for Regular, Medium, Semibold and Bold, one variable file contains every weight between its lightest and heaviest, and often other ranges too, such as width or optical size. You choose any point along each range, called an axis, so a headline can sit at weight 680 and a caption at 430 if that is what reads best.

The format arrived as part of the OpenType specification in 2016 and is now supported by every current major browser and the main design tools. This guide covers what the axes do, when variable fonts are worth using, and how to set them up in CSS. For the bigger picture of choosing type, see typography basics and brand fonts.

Variable font axes and what each one does

An axis is a design dimension the type designer has drawn at its extremes; the font interpolates everything in between. Five axes are registered in the OpenType specification and have standard four-letter tags. Type designers can add their own custom axes, which are written in capitals.

AxisTagWhat it changesCSS property
WeightwghtStroke thickness, from thin to blackfont-weight
WidthwdthCondensed to extended letter widthsfont-stretch
Optical sizeopszDetail, contrast and spacing tuned for the sizefont-optical-sizing
SlantslntAn oblique angle without changing letter shapesfont-style: oblique
ItalicitalSwitches to true italic letter shapesfont-style: italic
Custome.g. GRAD, SOFTAnything the designer definesfont-variation-settings
The five registered axes, plus custom ones. Not every variable font has every axis: check what yours includes.

Custom axes are where fonts get personality. Roboto Flex has a grade axis (GRAD) that changes stroke weight without changing letter width. Fraunces has SOFT for rounder terminals and WONK for its quirkier letterforms. Recursive has MONO and CASL axes that move it from sans to monospaced and from linear to casual. You can explore all of them on Google Fonts, which lets you filter for variable families.

Why optical size matters most

Weight gets the attention, but optical size is often the most useful axis. Metal type was cut separately for each size: small sizes had sturdier strokes, larger x-heights and looser spacing; large sizes were finer, with more contrast and tighter spacing. Digital fonts lost that when one outline was scaled to every size. An opsz axis brings it back.

Display sizes: an optical size axis sharpens contrast and closes up spacing as type grows.

Text sizes: the same family opens up and strengthens small type so it survives a phone screen.

With font-optical-sizing: auto (the default in browsers), a font with an opsz axis adjusts itself to the font size you set. You don't need to do anything except choose a font that has the axis. This is especially helpful on designs with a big headline and small supporting text in one family, which is most social posts and landing pages.

When variable fonts are worth using

Worth it

  • You use three or more weights or widths from one family
  • You want in-between weights to balance type on different backgrounds
  • Headlines and small text share a family with an optical size axis
  • You want to animate weight or width in motion work

Probably not

  • You only ever use one or two weights
  • The static cut is smaller and you never need other styles
  • Your tool or platform can't select axis values
  • The variable version lacks a style or language you need

File size is the honest trade-off. A variable file carries the data for every style, so it is usually larger than one static weight but smaller than several. If a site loads Regular and Bold only, two static files may well be lighter. If it loads four weights and an italic, one variable file usually wins, and you gain every weight in between for free.

In-between weights are more useful than they sound. Light text on a dark or colourful ground looks heavier than the same weight on white, so you might set white text on a gradient at 460 instead of 500 to match a dark-on-light version optically. The effect is subtle but it is what makes a type system feel tuned. Text on a gradient explains the wider legibility problem.

How to use variable fonts in CSS

Declare the font once with a range for each axis, then use normal properties like font-weight and font-stretch. Reach for font-variation-settings only for custom axes, because it overrides every axis at once and is not inherited in a friendly way. MDN's variable fonts guide covers the details.

css
@font-face {
  font-family: "Brand Sans";
  src: url("/fonts/brand-sans-variable.woff2") format("woff2");
  font-weight: 100 900;   /* the wght range in the file */
  font-stretch: 75% 125%; /* the wdth range, if it has one */
  font-display: swap;
}

body {
  font-family: "Brand Sans", system-ui, sans-serif;
  font-weight: 420;
  font-optical-sizing: auto;
}

h1 {
  font-weight: 720;
  font-stretch: 90%;
}

.on-dark {
  font-weight: 390; /* light on dark reads heavier */
}

/* Custom axes go through font-variation-settings. */
.soft {
  font-variation-settings: "SOFT" 100, "WONK" 1;
}
Standard axes through standard properties; custom axes through font-variation-settings. The ranges in @font-face must match what the file contains.

Setting up a variable type system

  1. 1

    Check the axes

    Open the font's specimen page and note every axis and its range. Confirm the languages and characters you need are included in the variable version.

  2. 2

    Define roles, not weights

    Decide weights per role: body, emphasis, subheading, headline, label. A system of five tuned values beats nine standard ones used at random.

  3. 3

    Tune for grounds

    Create a slightly lighter weight for light-on-dark text and check both against each other at real size.

  4. 4

    Let optical size work

    Keep font-optical-sizing: auto unless you have a reason to fix it, and check headlines and captions side by side.

  5. 5

    Write it down

    Record the font file, axis ranges and every role's values in your brand style guide, so nobody rebuilds them from memory.

Variable fonts reward restraint. The point is not to use every value but to pick the exact few that make your type read well everywhere it appears, from a 16 px paragraph to a 200 px display headline.

Usein kysyttyä

What is a variable font?

A variable font is one font file containing a continuous range of styles along one or more axes, such as weight or width, so you can choose any value in between instead of a few fixed styles.

Do all browsers support variable fonts?

Every current major browser supports them. Check caniuse if you need to support very old browsers, and include a fallback font stack.

Are variable fonts smaller than static fonts?

Not always. One variable file is usually larger than one static style but smaller than several. The saving comes when you would otherwise load three or more styles.

What is optical size in a font?

Optical size is an axis that adjusts detail, contrast and spacing to the size text is set at, making small text sturdier and large text finer. Browsers apply it automatically with font-optical-sizing: auto.

Jaa tämä opas

Kirjoittanut GradientlyVahvistettu Gradiently-tili

Gradientlyn tiimi. Gradiently on Markien ympärille rakennettu suunnittelutyökalu: eläviä liukuvärejä, joiden ansiosta kaikki suunnittelemasi näyttää omaltasi.

Katso profiilimme