CSS font-palette Property
The font-palette property selects a color palette used to render glyphs in compatible color fonts.
Some fonts contain multiple colors within individual characters or symbols. These fonts may provide alternative palettes for light and dark backgrounds or different visual styles. The font-palette property allows a browser to select one of those palettes or use a custom palette defined with the @font-palette-values rule.
font-palette Syntax
The font-palette property accepts the keywords normal, light, and dark, or the name of a custom palette defined using @font-palette-values.
Basic Syntax
selector {
font-palette: normal;
}
Select a Light Palette
selector {
font-palette: light;
}
Select a Dark Palette
selector {
font-palette: dark;
}
Select a Custom Palette
selector {
font-palette: --brand-palette;
}
A custom palette name must correspond to an applicable @font-palette-values definition.
CSS-Wide Keywords
.example {
font-palette: inherit;
}
.example {
font-palette: initial;
}
.example {
font-palette: unset;
}
.example {
font-palette: revert;
}
.example {
font-palette: revert-layer;
}
The property does not accept a list of CSS colors or a numeric palette index directly. Use @font-palette-values to select a numbered palette or override individual palette colors.
Property Values
The available values determine how a palette is selected for a compatible color font.
| Value | Description |
|---|---|
normal |
Uses the font's default color palette. |
light |
Requests a palette intended for use on a light background. |
dark |
Requests a palette intended for use on a dark background. |
--custom-name |
Uses a named palette defined with @font-palette-values. |
CSS-Wide Values
| Value | Description |
|---|---|
inherit |
Uses the computed value of the parent element. |
initial |
Restores the initial value, normal. |
unset |
Uses the inherited value because the property is inherited. |
revert |
Reverts the property according to CSS cascade origins. |
revert-layer |
Reverts the property according to CSS cascade layers. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | normal |
| Inherited | Yes |
| Applies to | All elements and text |
| Computed value | As specified |
| Animation type | Discrete |
| Percentages | Not applicable |
The selected font must support palette-based color rendering for this property to produce a visible effect.
How It Works
Compatible color fonts can store multiple colors for individual glyphs. Some fonts also provide several predefined palettes containing different color combinations.
Step 1: Select a Color Font
.color-text {
font-family: "Example Color Font", sans-serif;
}
Step 2: Choose a Palette
.color-text {
font-family: "Example Color Font", sans-serif;
font-palette: light;
}
Step 3: Locate a Suitable Palette
The browser examines the selected font's available palettes. If the font identifies a palette suitable for light backgrounds, the browser can select it.
Step 4: Render the Glyphs
The selected palette supplies colors used by the font's palette-based glyph rendering.
Step 5: Apply Custom Overrides When Defined
A custom palette can use an existing font palette as its starting point and replace selected color entries using @font-palette-values.
Important Consideration
The property does not create color glyphs in ordinary fonts. It selects palette information that the font's color rendering system can use.
The normal Value
The normal value uses the font's default palette. It is the initial value of font-palette.
Default Palette
.color-text {
font-palette: normal;
}
Apply to a Heading
h1 {
font-family: "Example Color Font", sans-serif;
font-palette: normal;
}
Reset a Custom Palette
.custom-text {
font-palette: --brand-palette;
}
.custom-text .default-text {
font-palette: normal;
}
Important Consideration
The default palette is determined by the font. It is not necessarily designed specifically for a light or dark background.
The light Value
The light value requests a palette designed to work well on a light background.
Light Background Example
.light-panel {
background-color: #ffffff;
}
.light-panel .color-text {
font-palette: light;
}
Light Palette for a Heading
.light-heading {
font-family: "Example Color Font", sans-serif;
font-size: 48px;
font-palette: light;
}
How the Palette Is Selected
The browser selects an appropriate palette from those identified by the font as suitable for light backgrounds. If no matching palette is available, the font's default palette is used.
Important Consideration
The light value does not make the text light-colored. It requests a palette intended to remain visible against a light background.
The dark Value
The dark value requests a palette designed to work well on a dark background.
Dark Background Example
.dark-panel {
background-color: #20242a;
}
.dark-panel .color-text {
font-palette: dark;
}
Dark Palette for a Heading
.dark-heading {
font-family: "Example Color Font", sans-serif;
font-size: 48px;
font-palette: dark;
}
How the Palette Is Selected
The browser selects an appropriate palette identified by the font as suitable for dark backgrounds. If the font does not provide a matching palette, its default palette is used.
Important Consideration
The dark value does not automatically change the element's background. Set the background color separately using CSS.
Custom Font Palettes
Custom palettes allow developers to select an existing font palette and replace individual colors with their own choices.
Define a Custom Palette
@font-palette-values --brand-palette {
font-family: "Example Color Font";
base-palette: 0;
override-colors:
0 #2563eb,
1 #f59e0b;
}
Apply the Custom Palette
.brand-heading {
font-family: "Example Color Font", sans-serif;
font-palette: --brand-palette;
}
Create Multiple Custom Palettes
@font-palette-values --blue-palette {
font-family: "Example Color Font";
base-palette: 0;
override-colors: 0 #2563eb;
}
@font-palette-values --red-palette {
font-family: "Example Color Font";
base-palette: 0;
override-colors: 0 #dc2626;
}
Apply Different Palettes
.blue-text {
font-palette: --blue-palette;
}
.red-text {
font-palette: --red-palette;
}
Important Consideration
Custom palette names are CSS dashed identifiers beginning with two hyphens. They are not CSS custom properties and do not use the var() function to reference their definitions.
The @font-palette-values Rule
The @font-palette-values rule defines a named font palette that can be selected using font-palette.
Basic Structure
@font-palette-values --custom-palette {
font-family: "Example Color Font";
base-palette: 0;
}
Available Descriptors
| Descriptor | Purpose |
|---|---|
font-family |
Identifies the font family associated with the palette definition. |
base-palette |
Selects a starting palette by index or a light/dark palette category. |
override-colors |
Replaces selected palette entries with specified CSS colors. |
Using a Numbered Base Palette
@font-palette-values --alternate-palette {
font-family: "Example Color Font";
base-palette: 1;
}
Palette indexes are zero-based, so 0 selects the first palette and 1 selects the second.
Using a Light Base Palette
@font-palette-values --light-brand {
font-family: "Example Color Font";
base-palette: light;
override-colors: 0 #1d4ed8;
}
Using a Dark Base Palette
@font-palette-values --dark-brand {
font-family: "Example Color Font";
base-palette: dark;
override-colors: 0 #93c5fd;
}
Important Consideration
The font-family descriptor is required for associating the palette with the intended font family. A palette definition does not load a font or create new glyphs.
Overriding Palette Colors
The override-colors descriptor replaces specific entries in a font's color palette.
Override One Color
@font-palette-values --single-color {
font-family: "Example Color Font";
base-palette: 0;
override-colors: 0 #e11d48;
}
Override Multiple Colors
@font-palette-values --multi-color {
font-family: "Example Color Font";
base-palette: 0;
override-colors:
0 #2563eb,
1 #f97316,
2 #16a34a;
}
Understanding Palette Indexes
Each number identifies an entry in the font's palette. The numbers are not assigned to letters, words, or glyph layers by CSS. Their meaning depends on how the font was designed.
Preserving Other Colors
Colors that are not overridden continue to use the values from the selected base palette.
Using Transparency
@font-palette-values --transparent-accent {
font-family: "Example Color Font";
base-palette: 0;
override-colors: 0 rgb(37 99 235 / 70%);
}
Important Consideration
Check the font's palette entries before choosing override indexes. An index that does not correspond to a useful palette entry may produce no visible change.
Color Font Requirements
The font-palette property works with color fonts that use palette-based rendering. It does not apply arbitrary colors to every type of font.
Palette-Based Color Fonts
OpenType color fonts can use COLR glyph data together with CPAL color palette information. These palettes can be selected or customized through CSS.
Example
.color-icon {
font-family: "Example COLR Font", sans-serif;
font-palette: dark;
}
Ordinary Monochrome Fonts
.ordinary-text {
font-family: Arial, sans-serif;
font-palette: dark;
}
For an ordinary monochrome font, the declaration generally has no visible effect. Use the color property to change the text color.
Bitmap and SVG Color Fonts
Some color fonts store artwork using bitmap or SVG glyph formats rather than palette-based COLR rendering. The font-palette property does not necessarily control colors in those formats.
Font Fallback
If the selected color font is unavailable, the browser may use a fallback font without palette support. The text or symbols can still render, but palette selection may have no effect.
Important Consideration
Not all emoji fonts support CSS palette selection. A colorful emoji does not automatically indicate that its font provides selectable CPAL palettes.
font-palette vs. color
The font-palette and color properties control different aspects of text rendering.
Using the color Property
.ordinary-heading {
color: #2563eb;
}
The color property specifies the foreground color used for ordinary text and other elements that use the current text color.
Using font-palette
.color-heading {
font-palette: --brand-palette;
}
The font-palette property selects a palette containing colors used by compatible color glyphs.
Comparison
| Property | Purpose |
|---|---|
color |
Sets the foreground color used for ordinary text and related rendering. |
font-palette |
Selects a collection of colors used by compatible color font glyphs. |
Using Both Properties
.example {
color: #1f2937;
font-palette: --brand-palette;
}
The two properties can be used together. The visible result depends on whether the selected font uses palette colors, the current text color, or a combination of both.
Important Consideration
Use color for ordinary text coloring. Use font-palette when the font provides multiple palette-controlled colors within its glyphs.
Palettes and Color Schemes
Font palettes can be selected to complement light and dark website designs.
Light Theme
.light-theme {
background-color: #ffffff;
}
.light-theme .color-text {
font-palette: light;
}
Dark Theme
.dark-theme {
background-color: #1f2937;
}
.dark-theme .color-text {
font-palette: dark;
}
Respond to the User's Color Scheme
.color-text {
font-palette: light;
}
@media (prefers-color-scheme: dark) {
.color-text {
font-palette: dark;
}
}
This example requests a light-background palette by default and a dark-background palette when the user's system preference indicates a dark color scheme.
Custom Theme Palettes
.theme-light .color-text {
font-palette: --brand-light;
}
.theme-dark .color-text {
font-palette: --brand-dark;
}
Important Consideration
The light and dark keywords describe the intended background for the palette. They do not automatically detect the page background or switch when the operating system theme changes.
Inheritance
The font-palette property is inherited, allowing descendants to use the same palette selection unless another declaration overrides it.
Set a Palette for a Container
.icon-container {
font-palette: --brand-palette;
}
Override a Child Element
.icon-container {
font-palette: --brand-palette;
}
.icon-container .alternate-icon {
font-palette: dark;
}
Explicit Inheritance
.child {
font-palette: inherit;
}
Reset to the Initial Value
.child {
font-palette: initial;
}
The initial value is normal.
Important Consideration
Although the property is inherited, only compatible color glyphs use its palette selection. Ordinary text inside the same container continues to render normally.
font-palette Example
This example demonstrates the normal, light, and dark values using a palette-based color font. It uses the Bungee Color font, which provides color glyphs through OpenType color font technology.
The example includes a custom palette definition to demonstrate the relationship between font-palette and @font-palette-values. The custom palette overrides a palette entry when the font and browser support the requested color index.
HTML Example
<div class="font-palette-demo">
<p class="demo-label">Default palette</p>
<p class="demo-normal">COLOR</p>
<p class="demo-label">Light palette</p>
<p class="demo-light">COLOR</p>
<p class="demo-label">Dark palette</p>
<p class="demo-dark">COLOR</p>
<p class="demo-label">Custom palette</p>
<p class="demo-custom">COLOR</p>
</div>
CSS Example
@import url("https://fonts.googleapis.com/css2?family=Bungee+Color&display=swap");
@font-palette-values --demo-palette {
font-family: "Bungee Color";
base-palette: 0;
override-colors: 0 #2563eb;
}
.font-palette-demo {
font-family: "Bungee Color", sans-serif;
}
.font-palette-demo p {
margin: 0 0 12px;
}
.font-palette-demo .demo-label {
font: 600 13px/1.4 Arial, sans-serif;
}
.demo-normal {
font-size: 40px;
font-palette: normal;
}
.demo-light {
font-size: 40px;
font-palette: light;
}
.demo-dark {
font-size: 40px;
font-palette: dark;
}
.demo-custom {
font-size: 40px;
font-palette: --demo-palette;
}
Default palette
COLOR
Light palette
COLOR
Dark palette
COLOR
Custom palette
COLOR
The default example uses the font's normal palette. The light and dark examples request palettes intended for different backgrounds, while the custom example requests a named palette with a modified color entry.
Some examples may appear identical if the font does not provide distinct light and dark palettes, the selected palette entry does not affect the displayed glyphs, or the browser cannot use the font's palette information. If the web font fails to load, the fallback font may render the text without color glyphs.
Common Mistakes
The most common problems involve using the property with ordinary fonts or confusing palette selection with regular text coloring.
Using a CSS Color as the Value
.example {
font-palette: #2563eb;
}
This declaration is invalid. Use color for ordinary text colors or define a custom palette using @font-palette-values.
Using a Numeric Palette Index
.example {
font-palette: 1;
}
The property does not accept numeric palette indexes directly. Use the base-palette descriptor inside @font-palette-values.
Using an Undefined Custom Palette
.example {
font-palette: --missing-palette;
}
A custom palette name must have an applicable @font-palette-values definition to select the intended palette.
Using an Ordinary Font
.example {
font-family: Arial, sans-serif;
font-palette: dark;
}
Ordinary monochrome fonts do not provide the palette-based color glyph data required for visible palette changes.
Assuming light Means Light-Colored Text
The light value requests a palette intended for light backgrounds. It does not mean that the glyphs themselves must use light colors.
Assuming dark Changes the Background
The dark value does not modify the background color or automatically activate a dark theme.
Using Incorrect Palette Indexes
Color indexes in override-colors refer to entries defined by the font. They are not universal indexes with the same meaning across different fonts.
Confusing Custom Palettes with CSS Variables
A custom palette name begins with two hyphens, but it is defined by @font-palette-values, not by a CSS custom property declaration.
Assuming All Emoji Fonts Support Palettes
Many emoji fonts use color rendering formats that do not provide selectable CPAL palettes.
Important Considerations
Keep the following points in mind when using the font-palette property:
- Purpose: Selects color palettes used by compatible color fonts.
- Initial value:
normal. - Inheritance: The property is inherited.
- Applies to: All elements and text.
- normal: Uses the font's default palette.
- light: Requests a palette intended for light backgrounds.
- dark: Requests a palette intended for dark backgrounds.
- Custom palettes: Named palettes are defined with
@font-palette-values. - Palette names: Custom palette identifiers begin with two hyphens.
- Font dependency: The selected font must provide compatible palette-based color glyph data.
- OpenType: COLR and CPAL font tables can provide palette-based color glyph rendering.
- base-palette: Selects a starting palette for a custom definition.
- override-colors: Replaces individual palette entries with specified CSS colors.
- Palette indexes: Indexes are determined by the font's palette structure.
- Ordinary text: Use the
colorproperty for standard text coloring. - Color schemes: Palettes can be selected for light and dark website themes.
- Theme switching: Use media queries or theme selectors to change palettes automatically.
- Fallback fonts: A fallback font without palette support may show no visible change.
- Accessibility: Ensure selected palette colors remain distinguishable against the background.
- Animation: The property uses discrete animation behavior.
- Browser support: The property is supported in modern browsers, although font format support can vary.
Use font-palette when working with color fonts that provide selectable palettes. For custom color combinations, define a palette with @font-palette-values and apply it using the palette's name.
Browser Support
The CSS font-palette property is Widely available in modern browsers, including Chrome, Edge, Firefox, and Safari.
Support for the property does not guarantee that every color font can use it. The font must contain compatible palette-based color information, and support for individual color font formats may vary.
Supported Example
.color-text {
font-palette: dark;
}
Feature Detection
@supports (font-palette: dark) {
.color-text {
font-palette: dark;
}
}
The @supports rule checks whether the browser recognizes the declaration. It does not verify that the selected font provides a dark palette.
Compatibility Considerations
Test palette selection with the actual color fonts used on the website. When a font lacks suitable palette information, the property may produce no visible difference.
For current compatibility information, visit Can I Use? and search for font-palette.
Specifications
The font-palette property is defined in the CSS Fonts Module, which describes color font palette selection and custom palette definitions.
CSS Fonts Module Level 4: font-palette Property
The same specification defines the @font-palette-values rule used to create named palettes.
CSS Fonts Module Level 4: @font-palette-values Rule
OpenType color font palettes are described in the CPAL table specification.
OpenType CPAL Color Palette Table
For additional explanations and examples, see MDN Web Docs.
