
Table of Contents
Move design tokens, preset definitions, and block defaults out of scattered stylesheets and into theme.json. Add the file at your theme root, define version, settings, and styles, then let WordPress generate CSS variables and block rules for editor and front end. You know it is done right when the editor controls show your presets, DevTools shows --wp--preset--* variables on :root or body, and removing the old override CSS causes no visual regression. Validate with wp theme list, a fresh editor save, and a front-end diff in staging before production.
How It Works: From JSON Schema to Generated CSS
theme.json is not a stylesheet that the browser reads. It is a declarative manifest parsed by WordPress core on the server. In 2026, WordPress 6.9-era builds still route this through the WP_Theme_JSON class and its resolver family: WP_Theme_JSON_Resolver::get_merged_data() pulls core defaults, theme data, and user Global Styles from the database; WP_Theme_JSON::get_stylesheet() compiles the merged tree into CSS; wp_add_global_styles_for_blocks() and the global styles inline loader print it into wp_head for the front end and into the editor iframe for the Site Editor.
The internal shape matters when debugging. Core ships wp-includes/theme.json with baseline presets and default spacing scales. Your theme file is read by WP_Theme_JSON_Resolver::get_theme_data(), which also merges any styles/*.json style variations selected in the editor. User customizations are stored as a wp_global_styles custom post type containing a theme.json-shaped JSON blob in post_content. The resolver merges in this order: core, theme, style variation, user. Every later layer can override tokens and style values, but only keys allowed by settings remain exposed as UI controls.
Compilation is selector-aware. A key such as styles.blocks.core/paragraph.typography.fontSize becomes a rule for p or the block class, while styles.color.background targets the root body wrapper. Presets are emitted as CSS custom properties first, for example --wp--preset--color--brand and --wp--preset--font-size--lede, then style declarations reference those variables with var(). That indirection is the main reason to prefer configuration over hacks: changing one slug value updates editor swatches, block markup classes such as has-brand-color, and front-end output together instead of chasing three copies of a hex code.
Core also derives utility classes. A color preset produces .has-{slug}-color, .has-{slug}-background-color, and .has-{slug}-border-color; a font-size preset produces .has-{slug}-font-size. Block serialization stores the slug, not the raw value, so content stays portable when the token changes. If you previously wrote .entry-content p { color: #0b5fff !important; }, the block saved has-custom-color or inline markup that now competes with generated rules. Migration therefore means both adding JSON and cleaning saved content or legacy CSS, not only creating a file.
To inspect the mechanism locally, use WP-CLI and the browser rather than guessing:
# From the site root, in a staging copy
wp theme list --status=active
wp eval 'echo esc_html( wp_json_encode( WP_Theme_JSON_Resolver::get_merged_data()->get_raw_data(), JSON_PRETTY_PRINT ) );' | head -n 80
wp option get stylesheet
# See the user Global Styles post that can override your theme
wp post list --post_type=wp_global_styles --fields=ID,post_title,post_status,post_name
# Clear caches that commonly hide a freshly edited theme.json
wp cache flush
wp rewrite flush --hard
In DevTools, filter the Elements panel for global-styles-inline-css or wp-block-library and search for --wp--preset--color--brand. In the editor, open the Styles panel and confirm the palette and type scale are visible. Those two checks prove the resolver read the file and the compiler emitted CSS; a screenshot alone does not, because a cached stylesheet can still paint the old color.
Step-by-Step Process: Minimal Runnable WordPress theme.json Tutorial
- Create a block theme skeleton in
wp-content/themes/runok-tokens/withstyle.css,index.php,templates/index.html, andtheme.json; activate it withwp theme activate runok-tokens. - Paste the manifest below, keeping
versionat3for WordPress 6.6-6.9 in 2026 and using lowercase slugs only. - Add one paragraph and one button in the editor, apply the Brand and Lede presets, and save; confirm serialized content contains
has-brand-background-colorandhas-lede-font-size. - Run
wp cache flush, reload the front end, and inspect the generated inline stylesheet for the variables and block selectors. - Delete the legacy override rule from
style.css, take a visual diff, and committheme.jsonseparately so rollback is one revert.
The following is deliberately small. It runs on a clean WordPress 6.6+ install, needs no build step, and demonstrates settings, root styles, and a block-level override in one file:
{
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 3,
"settings": {
"appearanceTools": true,
"color": {
"custom": false,
"palette": [
{ "slug": "ink", "name": "Ink", "color": "#14181f" },
{ "slug": "paper", "name": "Paper", "color": "#f7f5ef" },
{ "slug": "brand", "name": "Brand", "color": "#0b5fff" }
]
},
"typography": {
"customFontSize": false,
"fontFamilies": [
{
"slug": "system",
"name": "System",
"fontFamily": "-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
}
],
"fontSizes": [
{ "slug": "body", "name": "Body", "size": "1rem" },
{ "slug": "lede", "name": "Lede", "size": "clamp(1.15rem, 2vw, 1.45rem)" }
]
},
"spacing": { "units": ["rem", "vw"], "spacingScale": { "steps": 0 } },
"layout": { "contentSize": "720px", "wideSize": "1100px" }
},
"styles": {
"color": { "background": "var(--wp--preset--color--paper)", "text": "var(--wp--preset--color--ink)" },
"typography": { "fontFamily": "var(--wp--preset--font-family--system)", "fontSize": "var(--wp--preset--font-size--body)", "lineHeight": "1.65" },
"spacing": { "padding": { "top": "2rem", "bottom": "2rem", "left": "1.25rem", "right": "1.25rem" } },
"elements": {
"button": {
"color": { "background": "var(--wp--preset--color--brand)", "text": "#ffffff" },
"border": { "radius": "6px" }
}
},
"blocks": {
"core/paragraph": { "typography": { "fontSize": "var(--wp--preset--font-size--lede)" } }
}
},
"templateParts": [
{ "name": "header", "title": "Header", "area": "header" }
]
}
Pair it with a minimal template so the generated root styles have a wrapper to land on:
<!-- wp:template-part {"slug":"header","theme":"runok-tokens","area":"header"} /-->
<!-- wp:group {"layout":{"type":"constrained"},"tagName":"main"} -->
<main class="wp-block-group">
<!-- wp:paragraph -->
<p>Configured, not hacked.</p>
<!-- /wp:paragraph -->
<!-- wp:buttons -->
<div class="wp-block-buttons"><!-- wp:button /--></div>
<!-- /wp:buttons -->
</main>
<!-- /wp:group -->
Verification is concrete: curl -s https://staging.example/ | grep -o -- '--wp--preset--color--brand[^;]*' should return the hex value; wp post list --post_type=wp_global_styles should show one active post after an editor save; and the block markup should contain slugs rather than raw hex. If the variable is missing, the file was not parsed. If the variable exists but the paragraph is still old-sized, a user Global Styles override or a later style.css rule is winning. Use the Computed panel to identify the exact stylesheet and selector instead of adding more !important.
Common pitfalls here are subtle. A trailing comma makes the whole JSON invalid and WordPress silently falls back to core defaults; run php -r 'json_decode(file_get_contents("theme.json"), true, 512, JSON_THROW_ON_ERROR);' or jq . theme.json before activating. Slugs with uppercase letters or underscores break class naming. Referencing a preset before declaring it produces var(--wp--preset--...) with no fallback. Setting custom: false hides the picker but does not remove inline colors already saved in older posts, so audit content with wp search-replace 'style="color:' 'style="' --dry-run before enforcing tokens. Finally, object caches on managed hosts can hold a compiled stylesheet for minutes; flush with WP-CLI and re-save the Global Styles post once.
Get a Quote
Email + requirement + budget range — we reply with a quote within 24 hours.
Rollback should be boring. Keep the old CSS in a single file such as assets/legacy-overrides.css and enqueue it conditionally with wp_enqueue_style() behind a theme mod: if ( get_theme_mod( 'runok_legacy_css', false ) ) { wp_enqueue_style( 'runok-legacy', get_template_directory_uri() . '/assets/legacy-overrides.css', array(), '2026.01' ); }. Toggle it with wp theme mod set runok_legacy_css 1, flush cache, and confirm. For a full revert, git revert <commit> the manifest, delete the wp_global_styles post with wp post delete <ID> --force only in staging or after export, then re-activate the prior theme. Always export the user Global Styles JSON first: wp post get <ID> --field=content > global-styles-backup.json.
The theme.json Cascade
The cascade is a four-layer merge, not CSS specificity. Core defaults define the schema and baseline tokens; the active theme’s theme.json overrides or disables them; a selected style variation from styles/*.json overrides the theme; the saved wp_global_styles post overrides everything for that site. Parent and child themes add another axis: the child manifest is merged over the parent manifest before user data is applied, which is why a child theme only needs the keys it changes.
Inspect the winning layer
Use WP_Theme_JSON_Resolver::get_merged_data( 'theme' ) for the front-end view and compare it with get_merged_data() for the editor view. The difference is usually the user post. In practice, when a client says the brand color changed everywhere except the editor, the resolver is returning two different merged trees because the Site Editor saved a user-level styles.color.background value. Reset it from Styles > Reset to theme defaults, or update the post content directly in staging, then re-check both outputs.
Control what can be overridden
settings is the permission layer. "color": { "custom": false } removes arbitrary color pickers; "typography": { "customFontSize": false } removes free-form sizes; appearanceTools: true enables border, spacing, and layout controls in one switch. Per-block overrides under settings.blocks narrow further, for example allowing custom spacing on core/group but not on core/paragraph. If a control still appears, check whether a plugin called add_theme_support() or filtered wp_theme_json_data_theme after your theme loaded. The official Global Settings and Styles guide documents the merge hooks and schema keys; use the filter names there when auditing plugin interference.
Resolve conflicts without escalating specificity
Generated rules are intentionally low-specificity, often body, .wp-site-blocks, or .wp-block-button__link. A legacy rule like .site-content .entry-content a.button will beat them. Do not fight it with !important; move the intent into styles.elements.button or styles.blocks.core/button, then remove the legacy selector. Verify with the Computed panel: the winning declaration should cite global-styles-inline-css, not your old handle. If a third-party plugin still wins, enqueue its stylesheet earlier or use wp_theme_json_data_theme to add a block-scoped style rather than raising specificity.
Palette and Typography Presets
Presets are the contract between design, content, and code. Each entry needs a stable slug, a human name, and a value. The slug is serialized into post content, so treat it like an API: renaming brand to primary in 2026 orphans every saved has-brand-color class. Add a new slug, migrate content with wp search-replace 'has-brand-color' 'has-primary-color' --dry-run first, and keep the old token as an alias for one release if the site has years of content.
Palette entries support more than swatches. With appearanceTools enabled, the same slugs feed background, text, border, link, heading, and button controls. Use fluid values where they belong: clamp() is valid in fontSizes[].size and emitted unchanged, so a Lede token can scale without a media query. For font families, declare a local stack or use fontFace entries under settings.typography.fontFamilies[] pointing to file:./assets/fonts/*.woff2; core then registers @font-face rules for both editor and front end. Avoid loading Google Fonts from a CSS hack, because the editor iframe will not inherit it and the Site Editor preview will drift.
"fontFamilies": [
{
"slug": "editorial",
"name": "Editorial",
"fontFamily": "'Editorial', Georgia, serif",
"fontFace": [
{
"fontFamily": "Editorial",
"fontWeight": "400 700",
"fontStyle": "normal",
"src": ["file:./assets/fonts/editorial-var.woff2"],
"fontDisplay": "swap"
}
]
}
]
Verification has three parts. First, the editor: open a paragraph, confirm only Body and Lede appear in the size dropdown and Ink/Paper/Brand in the palette. Second, the database: wp post get <ID> --field=content on a saved page should contain slugs, not hex codes. Third, the front end: curl -s | grep -o -- '--wp--preset--font-size--lede:[^;]*' should print the clamp expression, and the font file should return 200 with a font/woff2 content type. If the swatch shows but the front end does not, the block saved a class while your old CSS still defines .has-brand-color with a different hex; remove that duplicate definition.
Common pitfalls include disabling custom after editors already used the picker, forgetting customDuotone and customGradient when locking a palette, and assuming fontFace paths resolve from style.css rather than the theme root. Relative file:./ paths are resolved against the active theme directory, and in a child theme they resolve against the child. Roll back a bad type scale by restoring the previous fontSizes array and flushing cache; because content stores slugs, no post edit is needed. If you changed slugs, restore the old array and re-run the reverse search-replace from the dry-run log.
For teams standardizing multiple properties, our WordPress Theme Development & Customization work usually starts by freezing slugs in a shared token file before any template migration, because that single decision prevents the largest class of content drift. The same discipline applies when a performance vendor later audits render-blocking CSS; if you are comparing partners, the evaluation notes in Choosing a Vendor for WordPress Site Optimization in 2026 align well with the cache-flush and inline-CSS checks above.
Limits with Classic Themes
Classic themes can read theme.json, but they do not get the full Global Styles experience. WordPress loads the manifest for any active theme, so presets, CSS variables, and editor-side controls appear in the block editor even when the theme uses index.php, header.php, and functions.php. What is missing is the Site Editor, template parts, wp_site-blocks wrappers, and user-level Styles saves. In 2026, a classic theme still needs add_theme_support( 'wp-block-styles' ), add_theme_support( 'align-wide' ), and usually add_theme_support( 'editor-styles' ) plus add_editor_style() to approximate parity.
The practical limit is selector coverage. Generated root styles target body and .wp-site-blocks; a classic header built from <header id="masthead"> and a custom nav walker will not inherit block spacing or layout constraints. Buttons rendered by the_content() get styles.elements.button, but buttons hardcoded in footer.php do not. Do not solve this by duplicating every token into style.css; instead reference the generated variables from the few classic templates that need them:
/* style.css in a classic theme: consume tokens, do not redefine them */
#masthead {
background: var(--wp--preset--color--paper, #f7f5ef);
color: var(--wp--preset--color--ink, #14181f);
padding-block: var(--wp--custom--space--md, 2rem);
}
.site-footer .cta {
background: var(--wp--preset--color--brand, #0b5fff);
border-radius: 6px;
}
Note the fallbacks. They are not redundancy; they protect the page if a plugin filters the manifest out or the theme is switched during a deploy. Also add "custom": { "space": { "md": "2rem" } } under settings if you want --wp--custom--space--md generated, otherwise the fallback is the only value that ever applies. Verify by toggling the theme in staging and checking that the footer CTA still renders, then inspect wp_head for the inline global styles handle. If it is absent, call wp_enqueue_global_styles() indirectly by ensuring core’s default hooks were not removed with remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' ) in legacy code.
Another limit is user overrides. Without a wp_global_styles post tied to block templates, the Styles sidebar is largely absent, so client changes land back in Additional CSS. That reintroduces the exact hack you are removing. If the roadmap allows, migrate to a block theme or a hybrid theme with templates/index.html while keeping PHP template parts via block_template_part(). If it does not, document that theme.json is developer-owned in a classic build and lock Additional CSS with remove_theme_support( 'custom-css' ) or a Customizer capability check. Rollback is straightforward: restore the previous style.css and remove the manifest; because classic templates used fallbacks, the site degrades instead of going unstyled. Broader platform trade-offs are covered in our WordPress vs Wix Comparison for Vendor Selection in 2026 when a classic estate is being reconsidered rather than refactored.
Version Compatibility

Version compatibility has two numbers: the version key inside theme.json and the WordPress core version running the site. In 2026, use "version": 3 for WordPress 6.6, 6.7, 6.8, and 6.9. Version 2 is still parsed for WordPress 5.9-6.5, and version 1 belongs to the 5.8 Gutenberg experiment. Core does not upgrade your file in place; an unknown higher version is ignored or partially read, so a manifest copied from a newer starter into a 6.4 site can silently lose backgroundImage, fontFace weights, or styles.blocks selectors. Pin the schema to the oldest core you actually support, not the newest one on your laptop.
| Core line | Safe theme.json version | Notable behavior in 2026 | Verification command |
|---|---|---|---|
| WordPress 5.8 | 1 | Experimental Gutenberg-only Global Styles; do not target for new builds. | wp core version |
| WordPress 5.9-6.4 | 2 | Block themes, style variations, appearanceTools, fluid typography basics. | wp core version |
| WordPress 6.5 | 2 or 3 | Font Library and fontFace improvements; v3 accepted with care. | wp eval 'echo WP_Theme_JSON::LATEST_SCHEMA;' |
| WordPress 6.6-6.9 | 3 | Current schema, refined block selectors, stable $schema validation. | wp eval 'echo WP_Theme_JSON::LATEST_SCHEMA;' |
Before an upgrade, run a matrix in staging. Capture the compiled CSS on the old core with wp eval 'echo WP_Theme_JSON_Resolver::get_merged_data()->get_stylesheet();' > css-before.txt, update with wp core update --version=6.9, run the same command to css-after.txt, then diff -u css-before.txt css-after.txt. Core changes selector output between releases; the diff tells you whether a spacing or border rule moved before clients report it. Keep the $schema URL pointed at https://schemas.wp.org/trunk/theme.json for editor autocomplete, but validate against the installed core constant, because trunk may describe keys the production resolver does not yet implement. The theme.json living reference is the right place to confirm a key before adding it to a supported matrix.
Plugin compatibility is part of the same audit. Filters such as wp_theme_json_data_defaults, wp_theme_json_data_theme, wp_theme_json_data_blocks, and wp_theme_json_data_user can inject settings after your file is read. Log them with wp eval 'print_r( array_keys( $GLOBALS["wp_filter"]["wp_theme_json_data_theme"]->callbacks ?? array() ) );' or simply grep the plugin directory: grep -R "wp_theme_json_data_" wp-content/plugins/ -n. A plugin that adds its own palette under defaults will appear below your theme layer, which is fine; one that writes to user will beat you. Common pitfalls include shipping v3 to a 6.4 client, leaving version out entirely so core assumes the oldest schema, and assuming a staging dump includes the wp_global_styles post. It often does not, which is why colors look correct locally and wrong after import.
Rollback across versions means more than restoring JSON. Downgrade core with wp core update --version=6.8.3 --force only after a database backup, set version back to the matching schema, re-import global-styles-backup.json into the wp_global_styles post, and flush object cache. Then re-run the stylesheet diff until it matches css-before.txt. If you maintain several client estates, keep one CI job per supported core line that activates the theme, calls get_stylesheet(), and fails on an unexpected diff; that catches compatibility drift far earlier than a visual QA pass. For broader release notes and deployment patterns, the technical column index is where we keep the surrounding upgrade checklists.
Frequently asked questions
Does theme.json replace style.css completely?
No. Keep style.css for the theme header, small layout glue, and classic-template fallbacks. Move tokens, presets, element defaults, and block defaults into JSON. If a rule needs a PHP-generated class or a third-party markup hook, leave it in CSS but reference --wp--preset--* variables.
Why did my palette change in the editor but not on the front end?
Usually one of three causes: a saved wp_global_styles post overriding the theme layer, a persistent object cache serving the previous compiled stylesheet, or legacy CSS defining the same .has-* class later in the cascade. Run wp cache flush, compare get_merged_data( 'theme' ) with get_merged_data(), and check the Computed panel for the winning handle.
Can I use theme.json on a classic theme in WordPress 6.9?
Yes, for presets, variables, and block-editor controls. You will not get the Site Editor, template parts, or user Styles saves. Add the relevant add_theme_support() calls, consume variables in PHP templates with fallbacks, and treat the manifest as developer-owned configuration.
Action Checklist
- Export the current
wp_global_stylespost and commit the legacy CSS as a single rollback file before touching tokens. - Create
theme.jsonwithversion: 3for WordPress 6.6-6.9, validate withjq ., and activate in staging withwp theme activate. - Verify slugs in saved post content,
--wp--preset--*variables inglobal-styles-inline-css, and editor dropdowns afterwp cache flush. - Run the
get_stylesheet()before/after diff across every supported core line and grep plugins forwp_theme_json_data_filters. - Remove duplicate
.has-*rules and!importantoverrides only after the generated selector wins in DevTools.
Need this migrated without a visual regression? Our engineers audit the cascade, freeze preset slugs, and ship a tested rollback path. See theme development services or browse all services.
