Short answer: one object a color in settings.color.palette, each with a slug, a name and a color
How to set a color palette in theme.json
To set a color palette in theme.json, add an object for each color to settings.color.palette in the file, with a slug, a name and a color. WordPress turns each slug into a --wp--preset--color--{slug} CSS variable and matching utility classes. To pick the colors on your real site first, load it in Recolor (recolor.page), press Space and copy the values from Export. For the whole preview, see the WordPress palette preview guide.
Last updated
| Part | What the docs say | From Recolor |
|---|---|---|
| The palette | An array under settings.color.palette | The palette you chose on your live site |
| Each color | color, name and slug, all three set | The hex code from Export's Hex tab; the slug and name are yours |
| The slug | Names --wp--preset--color--{slug} and the has-{slug}-color classes | Nothing to copy: Recolor reads colors, not slugs |
| Background and text | The slugs base and contrast, a de facto standard | The swatches marked page and text |
| The version | 3, the latest, for WordPress 6.6 or later | Nothing to copy |
| WordPress's own colors | "defaultPalette": false hides them in the editor | Nothing to copy |
Where the palette goes in theme.json
Each object in the palette array must set three properties, WordPress's Theme Handbook page on color settings
says. The color property takes any valid CSS color value, name provides the label people see in the
editor, and slug sets the unique identifier that names its CSS custom property and classes. The $schema
line gives code editors hints.
{
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 3,
"settings": {
"color": {
"palette": [
{ "color": "#264653", "name": "Base", "slug": "base" },
{ "color": "#e9c46a", "name": "Contrast", "slug": "contrast" },
{ "color": "#2a9d8f", "name": "Primary", "slug": "primary" },
{ "color": "#f4a261", "name": "Secondary", "slug": "secondary" },
{ "color": "#e76f51", "name": "Accent", "slug": "accent" }
]
}
}
}Version 3 is the latest format and arrived with WordPress 6.6, the Block Editor Handbook's guide to theme.json says. Older versions continue to work, and the theme.json migration guide shows that version 3 changed nothing in how the palette array is structured.
Slugs follow no official naming scheme, but the Theme Handbook's Introduction to theme.json calls base and
contrast a de facto standard since the Twenty Twenty-Three theme. Themes use base for the main background
and contrast for body text. In the example above, the dark #264653 serves as the base.
What WordPress makes from each color
WordPress generates a CSS custom property from each slug, available on the front end and inside the editor. It
also generates helper classes for text and backgrounds, such as .has-contrast-background-color.
:root {
--wp--preset--color--base: #264653;
--wp--preset--color--contrast: #e9c46a;
--wp--preset--color--primary: #2a9d8f;
--wp--preset--color--secondary: #f4a261;
--wp--preset--color--accent: #e76f51;
}
.has-contrast-color { color: var(--wp--preset--color--contrast) !important; }Defining a palette only offers choices in the editor color picker. To apply those choices automatically to
your layout, add a styles key beside settings and reference the presets using the
var:preset|color|{slug} format, as the Theme Handbook's page on using presets explains.
{
"styles": {
"color": {
"background": "var:preset|color|base",
"text": "var:preset|color|contrast"
},
"elements": {
"link": {
"color": {
"text": "var:preset|color|secondary"
}
}
}
}
}Links take secondary in this example rather than primary to preserve readable contrast. The #f4a261
value reads 4.89:1 against the base, whereas #2a9d8f reaches only 3.03:1,
falling short of the 4.5:1 ratio that WCAG AA requires for body text. Reviewing black or white
text helps when balancing contrast, while the contrast text preset
here reads 6.03:1.
WordPress's own colors and the Styles panel
Setting "defaultPalette": false hides the standard WordPress palette, and "custom": false prevents users
from picking custom colors outside your predefined list. Even when hidden, WordPress still generates the CSS
custom properties for its default colors.
{
"settings": {
"color": {
"custom": false,
"defaultPalette": false
}
}
}WordPress's Styles overview notes that user choices saved in the Site Editor Styles panel override the theme's
default settings. Clicking Reset colors restores the theme.json palette values. WordPress caches theme.json
data, so changes to the file can take 30 seconds or more to appear unless WP_DEBUG or SCRIPT_DEBUG is set
to true in wp-config.php.
Choosing the colors on your live site
To design a palette against real content, load your site's public address in Recolor, press Space to generate palettes, and lock any colors you want to keep. Use site colours, in Mapping, puts the theme's own colors in the swatches first. Recolor repaints the preset variables across the page while leaving photos, video and canvas elements untouched. For local development environments, follow the steps for loading a page from an uploaded file.
By default, the background shifts toward the swatch labeled "page" and text elements move toward "text", as detailed in the guide to mapping. You can check every combination against accessibility standards with the contrast matrix.
Recolor's standard CSS variables do not match WordPress preset names, and JSON exports contain raw hex values
rather than theme.json objects, as shown in the guide to exports. Open the Hex tab in
Export, copy each hex code into your theme.json file's color values, and assign your chosen slug and name.
Common questions
Does every palette entry need a slug, a name and a color?
Yes. WordPress's Theme Handbook page on color settings requires all three properties on every palette object.
Can I paste Recolor's CSS export into theme.json?
No. theme.json requires structured JSON objects rather than CSS variables, so copy the hex codes into the file manually.
Does a theme.json palette color my site by itself?
No. The palette only provides selectable swatches in the editor until you assign them under the styles key.
Does defaultPalette false remove WordPress's color variables?
No. WordPress still outputs the default color custom properties in the stylesheet for backward compatibility.
Is it free?
Yes. Loading pages, generating palettes, checking contrast and copying hex codes from Recolor require no payment or account.
Sources
- WordPress's Theme Handbook page on color settings developer.wordpress.org
- the Theme Handbook's Introduction to theme.json developer.wordpress.org
- the Theme Handbook's page on using presets developer.wordpress.org
- the Block Editor Handbook's guide to theme.json developer.wordpress.org
- the theme.json version 3 reference developer.wordpress.org
- the theme.json migration guide developer.wordpress.org
- WordPress's Styles overview wordpress.org