Master theme.json: Building Global Styles for WordPress Block Themes

Building a WordPress theme used to require writing thousands of lines of custom CSS and cluttering your functions.php file with endless add_theme_support() declarations. If a client wanted to change their primary brand color, developers had to manually hunt down hardcoded hex codes across multiple stylesheets or rely on heavy, bloated page builders.

The maturation of Full Site Editing (FSE) has completely rewritten the rules of modern WordPress theme development. Today, if you want to build scalable, highly performant WordPress sites, you must master theme.json.

This single configuration file acts as the central nervous system of modern WordPress block themes. It dictates exactly which design tools are available to users in the Site Editor, generates highly optimized CSS Custom Properties (variables) on the fly, and controls the global styles for every single block on your website.

Here is an advanced developer’s guide to architecting a robust theme.json file, allowing you to build dynamic global styles without writing redundant CSS.

The Architecture of a Modern theme.json File

To master theme.json, you must understand its strict hierarchical structure. By 2026, the API is highly mature, operating on Version 3, and separates your design logic into two distinct primary categories: Settings and Styles.

1. Settings (The UI Controls and Tokens)

The settings object defines the boundaries of what a user can actually do inside the WordPress Site Editor. This is where you declare your brand’s color palette, define typography presets, and toggle specific UI controls on or off.

If you want to prevent a client from breaking a layout by changing the padding on a core group block, you disable the spacing controls here. The settings section is fundamentally about establishing your design tokens.

2. Styles (The Application)

The styles object is where you apply your predefined settings to the frontend of the website. Instead of writing standard CSS in a style.css file, you map the design tokens you created in the settings object directly to the root of the site, or to specific WordPress blocks.

Step-by-Step Implementation Guide

Let us construct a production-ready theme.json file from scratch, complete with custom palettes, fluid typography, and block-specific styling.

Step 1: The Basic Skeleton and Schema

Every theme.json file must sit in the root directory of your active theme. It begins by declaring the schema and the API version. Always use the latest schema URL to enable autocompletion and validation in your code editor (like VS Code).

{
"$schema": "https://schemas.wp.org/trunk/theme.json",
"version": 3,
"settings": {},
"styles": {}
}

Step 2: Defining Global Settings and Palettes

Next, we populate the settings object. In this example, we will disable custom colors to force the user to strictly use our predefined brand colors. We will also set up a fluid typography preset.

Notice how we use strict slug names. WordPress automatically takes these slugs and generates CSS variables on the frontend, such as –wp–preset–color–brand-primary.

{
"version": 3,
"settings": {
"color": {
"custom": false,
"defaultPalette": false,
"palette": [
{
"slug": "brand-primary",
"color": "#005a9c",
"name": "Brand Primary"
},
{
"slug": "brand-secondary",
"color": "#f4a261",
"name": "Brand Secondary"
}
]
},
"typography": {
"fluid": true,
"customFontSize": false,
"fontSizes": [
{
"slug": "base",
"size": "1rem",
"name": "Base Size"
},
{
"slug": "heading-large",
"size": "clamp(2rem, 5vw, 3.5rem)",
"name": "Large Heading"
}
]
}
}
}

Step 3: Applying Global Styles to the Root

Now that our settings are defined, we need to apply them to the frontend using the styles object. We will map our “brand-primary” color to the overall text of the site, and apply our fluid typography to the root document.

{
"version": 3,
"styles": {
"color": {
"background": "#ffffff",
"text": "var(--wp--preset--color--brand-primary)"
},
"typography": {
"fontSize": "var(--wp--preset--font-size--base)",
"fontFamily": "system-ui, sans-serif",
"lineHeight": "1.6"
},
"elements": {
"link": {
"color": {
"text": "var(--wp--preset--color--brand-secondary)"
}
}
}
}
}

Step 4: Targeting Specific WordPress Blocks

The true power of theme.json lies in its ability to style specific core or custom blocks globally. Instead of writing standard CSS to target .wp-block-button__link, you declare the block namespace inside the blocks object within your styles.

Here, we will automatically style every button on the website to use our secondary brand color, applying border-radius and padding natively.

{
"version": 3,
"styles": {
"blocks": {
"core/button": {
"color": {
"background": "var(--wp--preset--color--brand-secondary)",
"text": "#ffffff"
},
"border": {
"radius": "8px"
},
"spacing": {
"padding": {
"top": "0.75rem",
"bottom": "0.75rem",
"left": "1.5rem",
"right": "1.5rem"
}
}
}
}
}
}

Advanced Capabilities in Modern Block Themes

Once you master the basic architecture, you can leverage advanced theme.json capabilities to drastically speed up premium theme development.

Utilizing Style Variations

Modern block themes rarely rely on just one design. By placing additional JSON files inside a /styles/ directory within your theme (e.g., dark-mode.json or playful.json), you create Style Variations.

This allows site administrators to instantly swap the entire look and feel of the website with a single click in the Site Editor. A style variation simply overrides the specific settings and styles declared in your root theme.json file, requiring zero additional PHP or CSS.

Native Fluid Typography and Spacing

Hardcoding complex CSS media queries for tablet and mobile screens is largely obsolete in block theme development.

By enabling “fluid”: true in your typography and spacing settings, the WordPress core engine automatically calculates viewport math behind the scenes. It outputs CSS clamp() functions that scale your fonts and spacing scales perfectly across all devices, ensuring perfect responsive design with minimal effort.

Frequently Asked Questions (FAQ)

Can I still use traditional CSS when building global styles for WordPress block themes?

Yes, absolutely. While theme.json should handle your global design tokens, color palettes, and standard spacing grids, you can still enqueue standard stylesheets. Use traditional CSS for highly complex, bespoke animations, hover states, or intricate layout adjustments that the JSON API cannot currently handle natively.

How do I override a specific block’s default WordPress core styles?

You override core styles by targeting the specific block namespace (such as core/quote or core/heading) inside the styles.blocks object of your theme.json file. Any properties you define within that specific block’s object will automatically take precedence over the default WordPress core styling.

Does theme.json work with classic PHP-based WordPress themes?

While theme.json was designed specifically for Full Site Editing (FSE) and block themes, classic themes can adopt a limited version of it. By placing a theme.json file in a classic theme, you can control the block settings (like forcing a specific color palette or defining font sizes) within the Gutenberg post editor, though you will not have access to the visual Site Editor experience.

A WP Life
A WP Life

Hi! We are A WP Life, we develop best WordPress themes and plugins for blog and websites.