Theme.json is a JSON configuration file that was introduced in WordPress 5.8 to provide advanced global styling and theme settings specifically for the block editor. It has continued to evolve in subsequent WordPress versions with version 2 introduced in WordPress 5.9.
Rationale for Theme.json
Prior to theme.json being introduced, the block editor API and theme integration options had grown in complexity over time. There were various theme support flags, CSS approaches, editor settings, etc that themes could utilize, but it had become messy and difficult to configure cohesively.
Theme.json consolidates all of these separate configuration mechanisms for the block editor into one single standardized file. This provides an improved developer experience for building block-first themes.
It also allows settings and styles to be managed in a more granular way, with global, block, and element specific options exposed. The different origins of styles such as from core, themes, or users can also be handled better rather than specificity wars.
Functionality
At a high level, theme.json enables themes to configure block editor parameters including:
And more. The functionality continues to expand too.
Some key areas where theme.json improves block theme development:
Usage
To utilize theme.json configuration in a theme, you'll need WordPress 5.8+ with the JSON file added into the root theme folder.
The file format uses a specific schema broken into sections like settings, styles, templates etc. It's then detected automatically to apply the configurations on theme activation.