Font palettes and feature values
Definition and purpose
Color fonts can contain palettes of indexed colors. @font-palette-values creates a named palette configuration for a font family; font-palette selects it. @font-feature-values instead assigns memorable names to numeric OpenType feature values for a family.
Named color palette
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } @font-palette-values --brand { font-family: LessonColor; base-palette: 0; override-colors: 0 navy; } #a { font-family: LessonColor, sans-serif; font-palette: --brand; } </style> </head> <body> <p id="a">Palette and alternate sample</p> </body></html>The computed palette name is --brand; no color font is supplied.
Syntax and mental model
A palette name begins with two hyphens. base-palette selects a source palette; override-colors maps a color index to a new color. For alternate glyphs, @styleset inside @font-feature-values maps a name to one or more positive feature numbers, referenced by font-variant-alternates: styleset(name). A real color or alternate-capable face is required to see changes. The local samples deliberately use an unprovided family and test rule declarations and computed requests only.
Named stylistic set
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } @font-feature-values LessonColor { @styleset { alternate: 1; } } #a { font-family: LessonColor, sans-serif; font-variant-alternates: styleset(alternate); } </style> </head> <body> <p id="a">Palette and alternate sample</p> </body></html>The named feature request computes even when the fallback font cannot provide it.
Common mistakes
Changing font-palette does not recolor ordinary monochrome text. Keep foreground/background contrast readable and verify the exact font supports the desired palette index and feature.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Variable fonts and font features. Next lesson: Text processing and international layout.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Font palettes and feature values — knowledge check
Five questions on font palettes and feature values.
What starts a custom palette name?
What does override-colors map?
Which rule names numeric font feature values?
Which property selects a named styleset?
Why might no visible palette change occur?