Navigation

Tokens

Font

Font families, sizes and weights, all written as font-*.

On this page

Classes

ClassDeclarations
font-<family>font-family: var(--font-family-<family>);
font-<size>font-size: var(--font-size-<size>);
font-<weight>font-weight: var(--font-weight-<weight>);

The three namespaces share the font- prefix, so a name must be unique among them. A name defined in more than one reports AMBIGUOUS_TOKEN and generates no CSS.

Values

Families are ordered fallback lists, sizes are rem lengths and weights are numeric requests. Pixel equivalents assume a 16px root font size. The rendered face and available weights depend on the fonts loaded by the page.

Family

ClassValue
font-sans
var(--font-sans, ui-sans-serif), system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"var(--font-sans, ui-sans-serif), system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"
font-mono
var(--font-mono, ui-monospace), SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospacevar(--font-mono, ui-monospace), SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace
font-serif
var(--font-serif, ui-serif), Georgia, Cambria, "Times New Roman", Times, serifvar(--font-serif, ui-serif), Georgia, Cambria, "Times New Roman", Times, serif
Compare all font families
font-sans
The shape of a letter
font-mono
The shape of a letter
font-serif
The shape of a letter

Size

ClassValue
font-3xs.5rem8px
font-2xs.625rem10px
font-xs.75rem12px
font-sm.875rem14px
font-md1rem16px
font-lg1.125rem18px
font-xl1.25rem20px
font-2xl1.5rem24px
font-3xl2rem32px
font-4xl2.25rem36px
font-5xl2.5rem40px
font-6xl3rem48px
font-7xl3.75rem60px
font-8xl4.5rem72px
font-9xl6rem96px
font-10xl8rem128px
Compare all font sizes
font-3xs
Aa
font-2xs
Aa
font-xs
Aa
font-sm
Aa
font-md
Aa
font-lg
Aa
font-xl
Aa
font-2xl
Aa
font-3xl
Aa
font-4xl
Aa
font-5xl
Aa
font-6xl
Aa
font-7xl
Aa
font-8xl
Aa
font-9xl
Aa
font-10xl
Aa

Weight

ClassValue
font-thin100
font-extralight200
font-light300
font-regular400
font-medium500
font-semibold600
font-bold700
font-extrabold800
font-heavy900
Compare all font weights
font-thin
The shape of a letter
font-extralight
The shape of a letter
font-light
The shape of a letter
font-regular
The shape of a letter
font-medium
The shape of a letter
font-semibold
The shape of a letter
font-bold
The shape of a letter
font-extrabold
The shape of a letter
font-heavy
The shape of a letter

One prefix, independent properties

font-serif, font-4xl and font-semibold write font-family, font-size and font-weight respectively. They can be combined because they set different properties; none is a complete type treatment.

The font prefix can change three independent properties

Every row starts with font-sans, font-2xl and font-regular. The result replaces only the class for the named property. The available fonts determine the rendered faces.

Text description
  1. The baseline text uses the sans family, 1.5rem size and weight 400, with a 16px root font size.
  2. The font-serif row changes only font-family. The font-4xl row changes only font-size, to 2.25rem. The font-semibold row changes only font-weight, to 600.
  3. Each result uses the same words. A common unitless line-height of 1.5 keeps the samples readable; these font classes do not set line-height.
  4. The samples render real preset CSS with available system fonts. They do not imply that a family class downloads a font file.

A size class leaves line height and letter spacing to their own declarations or inheritance. Use text-<name> when all three metrics should come from one treatment. Family and weight remain separate in either form.

A family token names fonts; it does not download them. The preset sans, mono and serif stacks begin with the optional --font-sans, --font-mono and --font-serif hooks. The Typography guide owns loading fonts and choosing a site-wide stack.

Keep custom keys distinct across the three namespaces. If both --font-family-brand and --font-size-brand exist, font-brand is ambiguous. An explicit native declaration such as (font-size:var(--font-size-brand)) names the intended property and variable.

Usage

Set a heading in a larger size and medium weight, and a code sample in the mono family.

Release notes

Install the new version with npm i @master/css.

<h3 class="… font-2xl font-medium">Release notes</h3><p class="… font-sm">Install the new version with <code class="… font-mono font-xs">npm i @master/css</code>.</p>
Generated CSS
@layer theme {  :root,  :host {    --font-family-mono: var(--font-mono, ui-monospace), SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;    --font-weight-medium: 500;    --font-size-xs: .75rem;    --font-size-sm: .875rem;    --font-size-2xl: 1.5rem  }}@layer utilities {  .font-mono {    font-family: var(--font-family-mono)  }  .font-2xl {    font-size: var(--font-size-2xl)  }  .font-sm {    font-size: var(--font-size-sm)  }  .font-xs {    font-size: var(--font-size-xs)  }  .font-medium {    font-weight: var(--font-weight-medium)  }}

Customize

Each namespace takes its own tokens: --font-family-display creates font-display, and --font-size-hero creates font-hero.

@theme {  --font-family-display: "Inter Display", var(--font-family-sans);  --font-size-hero: 4rem;}
Generated CSS
@layer theme {  :root,  :host {    --font-family-sans: var(--font-sans, ui-sans-serif), system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"  }  :root,  :host {    --font-family-display: "Inter Display", var(--font-family-sans);    --font-size-hero: 4rem  }}@layer utilities {  .font-display {    font-family: var(--font-family-display)  }  .font-hero {    font-size: var(--font-size-hero)  }}