Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท At-rules

The @font-palette-values at-rule

Reference for the CSS @font-palette-values at-rule: name a custom palette for a color font, pick a base palette and override individual colors.

Some fonts, called color fonts, contain more than outlines: their glyphs are painted with several colors, and the font file can ship one or more built-in palettes (sets of those colors). The @font-palette-values at-rule creates a named custom palette for one font family: you pick a base palette and optionally replace individual colors. You then apply it with the font-palette property.

It only has a visible effect on color fonts that define palettes. Plain text fonts ignore it.

CSS
@font-palette-values --ocean {
  font-family: "My Color Font";
  base-palette: 1;
  override-colors: 0 #0a3d62, 1 #3c9bd6;
}

.title { font-family: "My Color Font"; font-palette: --ocean; }

Try it

This site cannot load third-party fonts in previews, so there is no color font with palettes to show. The demo defines the palette, applies it, and reports whether your browser understands font-palette. With a real color font, the glyph colors change.

Define and apply a palette

Syntax

CSS
@font-palette-values <dashed-ident> {
  font-family: <family-name>;
  base-palette: light | dark | <integer>;
  override-colors: <integer> <color> [, <integer> <color>]*;
}

It is an at-rule, so initial value, inheritance and animatability do not apply.

Syntax and arguments

Descriptor Description
Name (--ocean) A dashed identifier. You use it as the value of font-palette.
font-family Required. The family the palette applies to. Only one family is allowed per rule.
base-palette The palette to start from: light or dark (as declared by the font), or the zero-based index of a palette in the font. Default is the font's first palette.
override-colors A comma-separated list of index color pairs that replace single entries of the base palette. Indexes are zero-based.

Usage notes

  • The font must have palettes. The indexes refer to color slots inside the font file; you need the font's documentation or a font tool to know which slot is which.
  • Pair with font-palette. A rule on its own changes nothing. Set font-palette: --name on elements that use the font.
  • Built-in keywords font-palette: light and dark select the font's own light or dark palette without any at-rule.
  • Colors must not depend on context. currentcolor and values that need an element are not allowed in override-colors.
  • Fall back safely. If the font has no matching palette, or the browser lacks support, the default colors appear.
  • Accessibility. Check contrast after overriding colors, especially on top of different backgrounds.

Browser support

Supported in current Chrome, Edge, Safari and Firefox. The effect depends on the font itself: only color fonts with palette tables respond.