Skip to main contentSkip to docs navigation

Chassis

Font Assets

View on GitHub

Where font files go in the source, how they are named by role, and which formats the build copies to web, iOS and Android.

Introduction

Fonts are the files under fonts/ of an app. The build copies the WOFF and WOFF2 files to the web output and the TTF and OTF files to iOS and Android, together with the license of each font. Stylesheets in the folder go to the web output only.

The files are named by the role a font plays, not by its family, so that every brand ships its fonts under the same names. On the web, a role that a brand sets in the family of another role has no files of its own. An app reads a file by role, so it gets a file for every role.

Source layout

Fonts live in source/<brand>/<app>/fonts/. The default brand holds the fonts that every brand gets, and a brand holds only the files that differ.

TEXT
source/
├── _default/
│   └── <app>/
│       └── fonts/
│           ├── ui-normal.woff2       -> copied to the web output
│           ├── ui-normal.ttf         -> copied to the iOS and Android output
│           ├── ui-license.txt        -> copied to every platform
│           └── fonts.css             -> copied to the web output
└── <brand>/
    └── <app>/
        └── fonts/
            └── ui-normal.woff2       -> replaces the default file of the same name

A brand file replaces the default file of the same path. A brand without a fonts/ folder gets the default fonts as they are. A default brand without fonts leaves every brand to hold all of its own, with a fonts.css of its own.

A font that every app of a brand uses lives once, in source/<brand>/_shared/fonts/, and every app of the brand gets it. A file of the same name in the fonts/ folder of an app replaces it for that app, so each app can hold a fonts.css of its own beside the shared fonts.

Formats

Each platform keeps the formats it can load, and the build leaves the rest out.

FormatWebiOSAndroid
WOFF2, WOFFCopiedDroppedDropped
TTF, OTFDroppedCopiedCopied
CSS, SCSSCopiedDroppedDropped
TXTCopiedCopiedCopied

The build does not convert a font from one format to another. A font that is needed on the web and in an app is added in both formats.

A font is copied with every character it has. A build with the --subset option writes the WOFF and WOFF2 files of the web again with the characters of a list of Unicode ranges only, under the same names; see Font subsets. The same option fixes an axis of a variable font at a value, where the configuration names one for the brand, and, with --split, writes a font once per range beside itself, with a rule per range in the stylesheets.

Naming

A font file is named <role>-<weight>.<ext>, with -italic after the weight for an italic. The role and the weight are the names that Chassis Tokens uses for typography, so a file name says where the font is used and stays the same when the family changes.

PartNamesMeaning
Roleui, prose, display, codeInterface text, reading content, headings, monospace
Weightelegant, normal, strong, massFrom the lightest to the heaviest weight of the role

On the web, a role that a brand sets in the family of another role has no files: the files of a family are under the role that owns it, and the stylesheet declares the family once. A brand that sets its prose role in its ui family has no prose file for the web.

An iOS or Android app takes a font by its file name, so its folder, source/<brand>/<app>/fonts/, holds a file for every role and weight of the tokens. A role in the family of another role has copies of that family's files under its own names, each at the weight its token gives, so the code of an app names the same files in every brand.

A brand with fonts for the ui and the code roles names them this way:

TEXT
source/<brand>/<app>/fonts/
├── code-normal.ttf
├── code-strong.ttf
├── ui-normal.ttf
├── ui-normal-italic.ttf
├── ui-strong.ttf
└── ...

A variable font holds every weight of a role in one file, so its name has no weight: <role>.<ext>, and <role>-italic.<ext> for the italic.

Which family a role holds, and which numeric weight a name stands for, is the choice of the brand. The stylesheet of the brand records it for the web, see Stylesheets.

Role names are a convention, not a rule of the build. A file with another name, such as inter-regular.woff2, is copied like any other font. It follows the general naming rules of the design guidelines: lowercase letters, digits and hyphens.

Adding files

A font enters the repository as a file in fonts/, in every format its platforms need, with its license beside it.

Font files

Put the WOFF2 file of a font in the fonts/ folder of each web app, and the TTF or OTF file in the fonts/ folder of each iOS and Android app. Name both by role. WOFF is copied too, for a brand that still needs it.

Fonts are Git LFS files. Install Git LFS before adding one, so that the commit holds a pointer and not the font itself.

Variable fonts

A family with a variable font gets both forms in a web app: the variable file of the role, and one file per weight beside it.

TEXT
source/<brand>/<app>/fonts/
├── fonts.css               -> declares ui.woff2 and ui-italic.woff2
├── ui-italic.woff2         -> every weight, italic
├── ui-normal.woff2         -> one weight
├── ui-strong.woff2
├── ui.woff2                -> every weight, upright
└── ...

The stylesheet of the brand declares the variable file. The files by weight stay for a page that writes its own @font-face rules. A family without a variable font has the files by weight only, and the stylesheet declares those.

Files by weight

A family with a variable font gets its files by weight from the variable file of each style, with chassis-assets static-font. The command fixes every axis, the ones that are given at their value and the others at their default, and names the font as a download of the family by weight names it: Inter SemiBold, with the PostScript name Inter-SemiBold, by which an iOS app loads a font.

Shell
npx chassis-assets static-font source/<brand>/<app>/fonts/ui.ttf \
  source/<brand>/_shared/fonts/ui-strong.ttf source/<brand>/_shared/fonts/ui-strong.woff2 wght=600

The command writes the font to every output it is given: TrueType for the apps, and WOFF2 for the web when the name of an output ends with .woff2. The font keeps every glyph, every character and every layout feature of the variable font, and the same command on the same file writes the same bytes. The names come from the STAT table of the variable font, and a value that the table has no name for fails the command. An optical size that the table names is a part of the family, as in a download: give it as wght=600 opsz=18 when its default is not the size the brand shows.

The command needs the package subset-font installed beside the build. It reads variable fonts with TrueType outlines.

Brand fonts

A brand changes a font of the default brand by adding a file of the same name to its own folder. A brand that replaces the ui and the code fonts of a web app holds their files, their licenses and a stylesheet:

TEXT
source/<brand>/<app>/fonts/
├── code-license.txt
├── code-normal.woff2
├── code-strong.woff2
├── fonts.css
├── ui-license.txt
├── ui-normal.woff2
├── ui.woff2
└── ...

A brand that replaces the files of a role replaces the license of that role too, and adds a fonts.css of its own that declares every family of the brand, since the stylesheet of the default brand declares the families of the default brand.

A brand file replaces a default file only when the name and the extension are the same. A brand with ui-normal.otf beside a default ui-normal.ttf gets both files in its output.

A brand gets every default file that it does not replace: a brand whose family of a role has no variable font, or that sets a role in the family of another role, would get the default files of that role beside its own, and its fonts.css would load none of them. chassis-assets lint-source warns about such a file: a font of the default brand whose family no stylesheet of the brand declares.

Stylesheets

A .css or .scss file in fonts/ is copied to the web output like a font. Each brand has one stylesheet, fonts.css, which declares every family of the brand with one @font-face rule per variable file:

CSS
@font-face {
  font-family: "Brand Sans";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("ui.woff2") format("woff2");
}

The rule names the family of the brand and the range of weights the file holds, and loads the file from the folder the stylesheet is in. A family without a variable font has one rule per file, with the numeric weight of the role. A page that links fonts/fonts.css needs no @font-face rule of its own.

The stylesheet is one per brand and not one per role, because a brand sets several roles in one family and a rule declares a family: a stylesheet per role would declare one family twice. The comment of each block names the role and the family.

chassis-assets lint-source reads the file of each rule and fails when the rule says something else than the file is: another family, another weight or a range the weight axis does not hold, or an italic declared as normal. A cut of a family is of the family: a cut named <family> 18pt is declared as <family>.

A rule declares the file of the web, and an app gets the file of the same name in another format. The lint checks the rule against that file too: ui.ttf beside a declared ui.woff2 has to be what the rule says. It also fails when two files of one name in a folder, such as ui-normal.ttf and ui-normal.woff2, are not one font in two formats: when they differ in the family, the weight, the style, the axes, the version or the number of glyphs. Write both files from the same font to keep them together.

The lint warns about a format() that is not the format of its file, such as format("woff") after a .woff2 file.

A stylesheet may also load fonts from a service instead of the folder. The build copies it as it is.

Licenses

Every font in source/ has its license beside it, named by role: ui-license.txt, display-license.txt and code-license.txt. The build copies the license to the fonts/ folder of every platform, so the license text travels with every copy of the font, as the SIL Open Font License asks.

Check that the license of a font allows embedding in an app and serving on the web before adding it. A brand that replaces a font adds the license of the new font under the same name.

Integration

The role and weight names come from the typography tokens of Chassis Tokens. The font tokens hold the family of each role and the weight of each name, and the typography tokens combine them into text styles.

The two projects meet in the names only. The build of Chassis Assets does not read a token, and a brand keeps the family in its tokens and the files in its fonts/ folder in step by hand.

Best practices

The rules of fonts/ leave a few choices to the designer. These keep a font replaceable by brand and complete on every platform.

  • Name fonts by role: ui-strong.woff2 works for every brand. A file named after a family has to be renamed, in the source and in every app, when the brand changes its font.
  • Add every format a platform needs: WOFF2 for a web app, TTF or OTF for an iOS or Android app. The build drops a format a platform does not keep and does not convert one.
  • Keep the license beside the font: as <role>-license.txt in the same folder. The build copies it to every platform.
  • Replace the stylesheet with the fonts: a brand that replaces the fonts of a role adds its own fonts.css, or the web output declares the families of the default brand for the files of the brand.
  • Replace every file of a role: a brand adds a file for each default file of the role, under the same name and extension, or its output holds the default font beside its own.

Avoid the habits that undo this:

  • Do not put a font outside fonts/: a WOFF2 file under another folder is copied to iOS and Android as well, since only fonts/ has the format rules.

Platform output

The build copies each font to the fonts/ folder of the job, in the formats the platform keeps, and renames it for the platform.

PlatformFolderNameFormats
Webdist/web/<app>/<brand>/fonts/kebab-caseWOFF2, WOFF, CSS, SCSS, TXT
iOSdist/ios/<app>/<brand>/fonts/snake_caseTTF, OTF, TXT
Androiddist/android/<app>/<brand>/fonts/snake_caseTTF, OTF, TXT

The web output of a brand with a variable ui font and its files by weight:

TEXT
dist/web/<app>/<brand>/fonts/
├── ...
├── fonts.css
├── ui-italic.woff2
├── ui-license.txt
├── ui-normal-italic.woff2
├── ui-normal.woff2
├── ui-strong.woff2
└── ui.woff2

The iOS and the Android output hold the TTF and OTF files of the same roles, under the same names in snake_case:

TEXT
dist/ios/<app>/<brand>/fonts/
├── ui_license.txt
├── ui_normal.ttf
├── ui_normal_italic.ttf
├── ui_strong.ttf
└── ...

The snake_case name is a valid Android resource name, so a file of the Android output can go to res/font/ as it is. A build with the --res option writes the font files there, and leaves the licenses in fonts/.

See the web, iOS, and Android docs for how an app uses these files.