Variable Fonts - OpenType Font Variations Flashcards
What are variable fonts?
Variable fonts—or, more specifically, OpenType Font Variations—are a relatively new font format introduced in 2016 that allow one font file to contain multiple stylistic variations, and thus break down the strict delineations of “traditional” (static) fonts. Weight, width, style, optical size, etc. can then be manipulated by the designer or adjusted based on contextual rules.
Google Fonts Glossary: Variable Fonts. Retrieved March 23, 2023
Q: What are the differences between typeface, font face, font family, variable fonts, and a style in Typography?
- Typeface: A typeface is a design of lettering that can include variations, but not size or weight. It’s the creative work itself, the design.
-
Font Face: In digital typography, font face refers to a set of characters, symbols, and glyphs that share the same design and attributes. Typically, it’s a specific variation within a typeface, such as
'bold'
or'italic'
. -
Font Family (Typography context): In typography, font family refers to a collection of fonts that are designed and intended to be used together, often sharing common design traits. A font family can consist of multiple weights (
light, regular, bold
) and styles (italic, oblique
). -
Font Family (CSS context): In CSS, font-family refers to a prioritized list of font family names and/or generic family names. It helps browsers select an appropriate font from those available on the system or through
@font-face
. E.g.,font-family: Arial, sans-serif;
. - Variable Fonts: Variable fonts are a relatively new font format that allows designers to use a single font file for a variety of styles. It contains a continuous range of styles and attributes within the same file. It can be controlled in CSS using properties such as font-weight, font-stretch, and custom-defined axes.
-
Style: In typography, style refers to attributes such as italics, boldness, and underlining. In CSS, you can control these attributes through properties like
font-style
, orfont-weight
Anatomy of a variable font
Variable fonts are a single font file with an inbuilt spectrum of styles. They consist of a ‘default’ style, usually ‘Regular’, and additional styles connected through ‘axes’. Weight, Width, Slant, and Optical Size are common axes. Along each axis, an ‘instance’ represents a specific style, and a variable font can have countless instances. Instances can be unnamed or named (e.g. SemiBold).
Example: In Roboto Flex, the Weight axis encompasses styles from light to heavy, with the Regular style in the middle, allowing selection among 900 different weights.
“Anatomy of a variable font #”(web.dev). Retrieved March 28, 2023.
What is an axis in variable fonts?
In variable fonts, “axis” usually refers to a single aspect of a typeface’s design that can be altered by the user.
Common axes include Italic, Optical Size, Slant, Weight
, and Width
, all five of which are registered (defined) in the OpenType file format specification.
Google Fonts Glossary: Axis in Variable Fonts. Retrieved March 23, 2023
What does the Italic axis (ital
) do in variable fonts?
“Italic” (ital
in CSS) is an axis found in some variable fonts. It controls the font file’s italic parameter, with italics either turned “off” or “on”, rather than gradually changing over a range.
Possible values according to Google Fonts CSS v2 API:
-
0
(default) - off -
1
- on
Google Fonts Glossary: Italic Axis Retrieved March 23, 2023
What does the Optical Size axis (opsz
) do in variable fonts?
“Optical Size” (controlled with font-optical-sizing
or font-variation-setting: ‘opsz’
VALUE in CSS) is an axis found in some variable fonts. It controls the font file’s optical size optimizations.
Possible values according to Google Fonts CSS v2 API:
-
14
default -
6
- min -
144
max
With step of size 0.1
Examples:
body { font-variation-settings: 'opsz' 16; } h1 { font-variation-settings: 'opsz' 48; }
Google Fonts Glossary: Optical Size Axis. Retrieved March 23, 2023
What is the problem with the Optical Size axis in browsers
The Optical Size axis in variable fonts is meant to adjust the font’s appearance for readability at different sizes. Ideally, the Optical Size should correlate with the physical size of the text in print (measured in points).
However, browsers lack the concept of physical size and rely on CSS pixels (px), which don’t necessarily equate to physical points. As a result, the Optical Size axis doesn’t align with the actual printed size.
CSS introduces font-optical-sizing
to help control this behavior. By default, it is set to auto
, allowing the browser to adjust the Optical Size. However, if needed, developers can disable this feature by setting it to none or explicitly set Optical Size using font-variation-settings:
/* Allow the browser to adjust Optical Size */ body { font-optical-sizing: auto; } /* Disable automatic adjustment of Optical Size */ body { font-optical-sizing: none; } /* Explicitly set Optical Size */ body { font-variation-settings: 'opsz' 16; } h1 { font-variation-settings: 'opsz' 48; }
This allows for greater control, though it does not solve the discrepancy between CSS pixels and physical points.
Google Fonts Glossary: Optical Size Axis. Retrieved March 23, 2023
What does the Optical Slant axis (slnt
) do in variable fonts?
“Slant” (slnt
in CSS) is an axis found in some variable fonts. It controls the font file’s slant parameter for oblique styles.
Possible values according to Google Fonts CSS v2 API:
-
0
default -
-90
- min -
90
max
With step of size 1
Examples:
body { font-variation-settings: 'slnt' 16; } h1 { font-variation-settings: 'slnt' 48; }
fonts.google.com “Slant axis (slnt)”. Retrieved 2023-03-27.
What does the Optical Weight axis (wght
) do in variable fonts?
“Weight” (wght
in CSS) is an axis found in many variable fonts. It controls the font file’s weight parameter.
Possible values according to Google Fonts CSS v2 API:
-
400
default -
1
- min -
1000
max
With step of size 1
Examples:
body { font-variation-settings: 'wght' 450; } h1 { font-variation-settings: 'wght' 810; }
fonts.google.com “Weight axis (wght)”. Retrieved 2023-03-27.
What does the Optical Width axis (wdht
) do in variable fonts?
“Width” (wdth in CSS) is an axis found in some variable fonts. It controls the font file’s width parameter.
Possible values according to Google Fonts CSS v2 API:
-
100
default -
25
- min -
200
max
With step of size 0.1
“Width” is the result of how much horizontal space is taken up by a typeface’s characters. A condensed face takes up considerably less space than a wide one.
In CSS, we can assign a variable width to an element of our choosing using the font-stretch
property. (Despite the name, note that the type is never literally “stretched” by browsers.
Examples:
p { font-stretch: 50%; } strong { font-stretch: 193%; } body { font-variation-settings: 'wdht' 450; } h1 { font-variation-settings: 'wdht' 810; }
“Width axis (wdth) – Fonts Knowledge - Google Fonts” (Google Fonts). Retrieved 2023-03-27.
How do you load a variable font file?
Variable fonts are loaded with the same @font-face
mechanism as traditional static web fonts, but with two new enhancements:
@font-face { font-family: 'Roboto Flex'; src: url('RobotoFlex-VF.woff2') format('woff2') tech('variations'), url('RobotoFlex-VF.woff2') format('woff2-variations'); font-weight: 100 1000; font-stretch: 25% 151%; }
-
Source Formats: We don’t want the browser to download the font if it doesn’t support variable fonts, so we add
format
andtech
descriptions: once in the future syntax (format('woff2') tech('variations')
), once in the deprecated but supported among browsers syntax (format('woff2-variations')
). If the browser supports variable fonts and supports the upcoming syntax, it will use the first declaration. If it supports variable fonts and the current syntax, it will use the second declaration. They both point to the same font file. -
Style Ranges: You’ll notice we’re supplying two values for
font-weight
andfont-stretch
. Instead of telling the browser which specific weight this font provides (for examplefont-weight: 500;
), we now give it the range of weights supported by the font. ForRoboto Flex
, the Weight axis ranges from 100 to 1000, and CSS directly maps the axis range to thefont-weight
style property. By specifying the range in@font-face
, any value outside this range will be “capped” to the nearest valid value. The Width axis range is mapped in the same way to thefont-stretch
property.
“Loading variable font files”(web.dev). Retrieved March 28, 2023.
How can you change the weight (wght
) axis?
The wght
axis can be changed widh font-weight
.
Traditionally, you would set font-weight
as a keyword (light
, bold
) or as a numerical value between 100
and 900
, in steps of 100
. With variable fonts, you can set any value within the font’s weight range:
.kinda-light { font-weight: 125; } .super-heavy { font-weight: 1000; }
“Using weights and widths”(web.dev). Retrieved March 29, 2023.
How can you cange the width (wdht
) axis?
The wdth
axis can be changed with font-stretch
.
We can set font-stretch
with keywords (condensed
, ultra-expanded
) or with percentage values:
.kinda-narrow { font-stretch: 33.3%; } .super-wide { font-stretch: 151%; }
“Using weights and widths”(web.dev). Retrieved March 29, 2023.
How do you use the italics (ital
) axis?
The ital
axis is intended for fonts that contain both a regular style, and an italic style. The axis is meant to be an on/off switch: value 0
is off and will show the regular style, value 1
will show the italics. Unlike other axes, there’s no transition. A value of 0.5
won’t give you “half italics”.
i, em, .italic { font-variation-settings: 'ital' 1; }
“Using italics and obliques #”(web.dev). Retrieved March 29, 2023.
How do you use the obliques (slnt
) axis?
The slnt
axis is different from italics in that it’s not a new style, but just slants the regular style. By default its value is 0
, which means the default upright letter shapes. Roboto Flex has a maximum slant of -10 degrees, meaning the letters will lean to the right when going from 0 to -10.
.slanted { font-variation-settings: 'slnt' 10; }
“Using italics and obliques” (web.dev). Retrieved March 29, 2023.