theme.json) is the central configuration file for block themes, providing a unified way to define theme settings, styles, and editor capabilities.
Overview
Introduced in WordPress 5.8,theme.json consolidates theme configuration that was previously scattered across multiple add_theme_support() calls, providing:
- Editor settings and capabilities
- Style presets (colors, fonts, spacing)
- Default styles for blocks and elements
- Layout configuration
- Responsive design controls
Three-Layer System
Architectural Decision:Styles system: Three-layer merge — WordPress defaults <theme.json< user preferences. Use Block Supports API and CSS custom properties (--wp--preset--*), not hardcoded values.
The Three Sources
1. WordPress Core Basetheme.json bundled with WordPress providing default settings and styles.
2. Active Theme
theme.json file in the theme directory (optional but recommended for block themes).
3. User Preferences
User customizations made via the Global Styles interface in the Site Editor.
Merge Priority
File Location
File Structure
Settings Section
Thesettings section configures the editor and defines style presets.
Top-Level Settings
Color Settings
Palette Definition:Typography Settings
Font Families:Spacing Settings
Block-Level Settings
Settings can be applied to specific blocks:Styles Section
Thestyles section defines default styles for the site.
Top-Level Styles
Element Styles
h1,h2,h3,h4,h5,h6linkbuttoncaptioncite
Block Styles
Elements Within Blocks
CSS Custom Properties
All presets generate CSS custom properties with a consistent naming structure:--wp--preset--color--primary--wp--preset--font-size--large--wp--preset--font-family--heading--wp--preset--spacing--50
Using Custom Properties
In theme.json:Version System
Theme JSON uses versioning to maintain backward compatibility. Current Version: 2- Block-level settings and styles
- Element styles
- Template part areas
- Custom templates
Template Parts
Custom Templates
User Customization Storage
User customizations via Global Styles UI are stored:- In the database as a special CPT:
wp_global_styles - One record per theme
- Follows the same theme.json structure
- Merged with highest priority during stylesheet generation
Output: Global Styles Stylesheet
The three-layer merge produces a single stylesheet:Best Practices
Use Semantic Slugs
Use meaningful slug names:Reference Presets via Custom Properties
Always use CSS custom properties:Provide Comprehensive Presets
Include sufficient presets for common use cases:- 5-7 colors minimum
- 4-5 font sizes
- Multiple font families if custom fonts used
Test User Overrides
Ensure theme works well when users customize via Global Styles UI.Document Custom Properties
Document available custom properties for theme users and developers.Migration from add_theme_support
Theme JSON replaces manyadd_theme_support() calls:
Before: