Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
VGSources
Blog

How to Use CSS Custom Properties in WordPress theme.json

Define reusable CSS variables in WordPress theme.json with settings.custom, use preset tokens correctly, and connect the same values to the Site Editor, blocks, and front-end CSS.
WorldWordPress theme.json Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Define theme-level CSS variables in settings.custom, then consume them with WordPress’s var:custom|… syntax inside theme.json or with normal var(--wp--custom--…) syntax in a stylesheet. Use registered presets for values that should appear as standardized, user-selectable design options; use custom properties for free-form tokens such as line-height scales, component dimensions, or other values your theme needs.

WordPress generates the variables for both the Site Editor and the front end, so one token system can drive authoring and rendered pages.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What WordPress generates from theme.json

A block theme’s theme.json file has two related jobs: it declares which design controls a theme supports, and it defines the values and styles that use those controls. WordPress turns supported settings into CSS custom properties and prints the resulting CSS where the editor and the front end can use it.

There are two naming families:

  • Custom settings: variables beginning with --wp--custom--.
  • Presets: variables beginning with --wp--preset--, followed by a feature and slug.

For example, a custom key named lineHeight becomes --wp--custom--line-height. A nested key such as lineHeight.md becomes --wp--custom--line-height--md. A color palette entry with the slug primary becomes --wp--preset--color--primary.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

Choose between a custom property and a preset

The right declaration point depends on how the value should behave in the editor and in your theme’s design system.

Question settings.custom Standard preset collection
What is it for? A free-form theme token that WordPress should expose as a CSS custom property. A standardized value for a supported feature such as color, font size, font family, spacing, or shadow.
How is it named? --wp--custom--{key}, with nested keys added as more -- segments. --wp--preset--{feature}--{slug}.
Should it participate in the standard editor controls? Not by itself. It is a token your theme can consume. Yes. Supported presets are designed for standardized Site Editor options.
How is it referenced in theme.json? var:custom|… var:preset|…
How is it referenced in ordinary CSS? var(--wp--custom--…) var(--wp--preset--…)

Use a preset when an editor should choose among named palette colors, type sizes, spacing values, or other supported controls. Use settings.custom when the value is a theme implementation token or when no standard preset collection represents it. A custom line-height scale is a typical example: it can be reused consistently without pretending that it is a color palette or another preset type.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Define custom variables in settings.custom

Put your declarations under the top-level settings object. Keys are converted to kebab case, so JavaScript-style camelCase is safe to use in JSON while the generated CSS uses conventional CSS naming.

{
  "$schema": "https://schemas.wp.org/trunk/theme.json",
  "version": 2,
  "settings": {
    "custom": {
      "lineHeight": {
        "sm": "1.25",
        "md": "1.5"
      }
    }
  }
}

This creates variables equivalent to:

--wp--custom--line-height--sm: 1.25;
--wp--custom--line-height--md: 1.5;

WordPress assigns the values and loads the generated properties for you. You do not need to duplicate those declarations in style.css. Keep nesting practical: every additional object level produces another name segment and a longer variable name, which makes tokens harder to read and maintain.

Use valid JSON, not JavaScript

  • Quote property names and string values.
  • Separate properties with commas, but do not leave a trailing comma after the final property.
  • Keep the file’s declared version compatible with the theme.json API you are targeting.
  • Preserve the $schema URL if you use editor validation and autocomplete.

Register a preset when the value is a standard design control

Supported preset groups include colors, font sizes, font families, spacing, and shadows. A preset entry has a human-readable name, a slug, and the value appropriate to that feature.

"settings": {
  "color": {
    "palette": [
      {
        "name": "Primary",
        "slug": "primary",
        "color": "#1e40af"
      }
    ]
  }
}

WordPress generates a variable equivalent to --wp--preset--color--primary: #1e40af. The slug is the stable part of the token. Changing the display name does not change the reference, but changing the slug requires updating every use of that preset.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

Presets also give WordPress the information it needs to present standardized choices in the Site Editor. If a user should be able to select a color or type size through Appearance > Editor > Styles, register it in the relevant preset collection rather than hiding it as an unrelated custom key.

Reference tokens inside theme.json

Inside the styles tree, use WordPress’s pipe-delimited token notation. This is not the same syntax as a CSS declaration in a stylesheet.

Token type theme.json reference Generated CSS form
Custom line-height token var:custom|line-height|md var(--wp--custom--line-height--md)
Preset color token var:preset|color|primary var(--wp--preset--color--primary)

In the WordPress form, the segments identify the token family, feature path, and final key. For a nested custom object such as lineHeight.md, the reference is var:custom|line-height|md. For a color palette entry, the reference is var:preset|color|primary.

Complete working example

The following version-2 example defines two custom line-height tokens and one color preset, then consumes them at the global and block levels.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
{
  "$schema": "https://schemas.wp.org/trunk/theme.json",
  "version": 2,
  "settings": {
    "custom": {
      "lineHeight": {
        "sm": "1.25",
        "md": "1.5"
      }
    },
    "color": {
      "palette": [
        {
          "name": "Primary",
          "slug": "primary",
          "color": "#1e40af"
        }
      ]
    }
  },
  "styles": {
    "typography": {
      "lineHeight": "var:custom|line-height|md"
    },
    "color": {
      "text": "var:preset|color|primary"
    },
    "blocks": {
      "core/paragraph": {
        "typography": {
          "lineHeight": "var:custom|line-height|sm"
        }
      }
    }
  }
}

The global typography rule uses the medium line-height, while paragraphs use the smaller value. The global text color points to the registered primary palette color. WordPress emits the variables and applies the corresponding rules in the editor and on the front end.

Put consumers in the styles tree

Declare tokens in settings.custom or a preset collection, then consume them under styles. The styles tree has three useful scopes.

Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

Top-level styles

Properties directly under styles apply to the global style context, with top-level output emitted for the body selector. Use this level for defaults such as the site’s base text color, typography, or spacing behavior.

"styles": {
  "typography": {
    "lineHeight": "var:custom|line-height|md"
  },
  "color": {
    "text": "var:preset|color|primary"
  }
}

Semantic elements

The styles.elements branch is for supported semantic elements. It keeps an element-level rule in the global styles system instead of requiring a hand-written selector in a stylesheet. Use the element properties that the current theme.json API supports, and verify the living reference when targeting an API version newer than the version-2 example.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Blocks

Place block-specific rules under styles.blocks, using the block name such as core/paragraph. WordPress emits these declarations for the matching block selectors. This is preferable to writing a broad selector when the intent is limited to one block type.

"styles": {
  "blocks": {
    "core/paragraph": {
      "typography": {
        "lineHeight": "var:custom|line-height|sm"
      }
    }
  }
}

A block rule can override a global value intentionally. Keep that relationship explicit: define the reusable token once, apply the site default globally, and override only the blocks that need a different token.

Use the generated variables in style.css

Regular CSS does not understand the pipe-delimited theme.json notation. In a stylesheet, call the generated custom property with the CSS var() function.

.example-class {
  line-height: var(--wp--custom--line-height--md);
  color: var(--wp--preset--color--primary);
}

This works for selectors and CSS features that are outside the standard style properties, provided the generated variable is in scope. The same custom property can therefore be consumed by theme.json styles, an external stylesheet, or the theme’s styles.css field.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

Decide when to stay in theme.json and when to write CSS

WordPress recommends the standard styles properties for supported colors, typography, spacing, and related controls. That route keeps the value inside the Global Styles system and lets users adjust it through the Site Editor when the feature is exposed there.

Use the styles.css field or an external stylesheet when you need a selector or CSS feature that the standard style properties do not model. Examples include a narrowly targeted selector, a property that is not represented in the current theme.json schema, or a component rule that must be authored as ordinary CSS.

  • Prefer theme.json styles for global defaults, semantic elements, and block-level settings covered by the API.
  • Prefer stylesheet CSS for unsupported properties and selector-specific behavior.
  • Use the generated variable in either place so the value remains centralized in the token definition.

Once you move a rule into CSS, normal cascade and specificity rules apply. A more specific selector, a later declaration, or an inline style can override the result even though both declarations use the same generated variable.

How the editor and front end use the same token system

WordPress loads the generated custom properties in the block editor and on the rendered site. This prevents a common split where a value looks correct while editing but changes on the published page. It also means that a preset or custom token can be the single source for global styles, block styles, and custom selectors.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The editor’s controls are not identical for every token type. A preset belongs to a documented feature and can be surfaced as a standardized choice. A custom setting is a free-form variable declaration; adding it does not automatically create a new control in the Styles interface. To make a user-adjustable option, use the appropriate supported setting and style property when one exists.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Inspect the generated names before troubleshooting

Most reference errors come from using the wrong family, slug, or nesting path. Work through the name mechanically:

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.
  1. Start with the declaration family: custom or a preset feature such as color.
  2. Convert camelCase keys to kebab case. lineHeight becomes line-height.
  3. Append each nested object key as another double-hyphen segment.
  4. For presets, use the exact feature and slug from the preset entry.
  5. Use pipe-delimited var:… syntax in theme.json and the full var(--wp--…) name in CSS.

For the example declaration lineHeight.md, the final CSS name is --wp--custom--line-height--md, not --wp--custom--lineHeight--md. For the palette entry with slug primary, it is --wp--preset--color--primary.

Common failures and precise fixes

The variable is empty or the fallback is used

  • Check that the key is under settings.custom, not beside settings or inside styles.
  • Confirm that every nested segment appears in the reference and is in the same order.
  • Confirm that the CSS spelling uses kebab case and the complete --wp--custom-- or --wp--preset-- prefix.
  • Reload the editor and front end after changing theme.json; stale generated CSS can make a corrected declaration appear missing.

The theme.json parser reports an error

  • Validate JSON punctuation and quotation marks.
  • Ensure the referenced style property is supported by the declared API version.
  • Check that the value type is appropriate for the property. A line-height token should resolve to a usable line-height value, while a color token should resolve to a color.

The value works in CSS but not as a Site Editor control

That is expected for many custom settings. A custom property is a reusable declaration, not a new editor panel. If the value maps to a supported WordPress feature, register it as that preset type and apply it through the corresponding style property. Keep it custom when it is an implementation token with no standard control.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A block ignores the global value

Inspect styles.blocks and any block supports or user-applied styles. A block-specific declaration intentionally takes precedence over the global body-level style. Also check stylesheet specificity if a custom selector is competing with generated block CSS.

Design a maintainable token hierarchy

Start with a small vocabulary that describes intent and reuse it consistently. A nested object is useful when related values form a scale, as with lineHeight.sm and lineHeight.md. Avoid nesting merely to mirror every component in the theme; long generated names make references cumbersome and increase the chance of typos.

  • Use stable slugs for presets because those slugs become part of the public token name.
  • Use descriptive custom keys that explain the role of the value rather than where it happens to be used.
  • Define one value once, then reference it from global, element, block, and stylesheet rules.
  • Keep a distinction between editor-facing presets and internal implementation tokens.

For example, a palette color belongs in the color preset collection when it is part of the site’s selectable design system. A line-height scale can remain in settings.custom and be assigned to the global typography rule and selected blocks.

Version and schema considerations

The examples here use "version": 2. WordPress’s theme.json API evolves, so confirm property support and syntax against the living theme.json reference when building for a newer API version. The schema URL in the example is useful for editor validation, but schema support does not change the underlying distinction between custom settings, presets, and CSS consumption.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If a newer API introduces a property or changes a supported style path, update the version and verify the resulting generated CSS rather than assuming that a version-2 example covers every future feature.

A practical implementation checklist

  1. Decide whether the value is an editor-facing preset or a free-form theme token.
  2. Add custom values under settings.custom, or add a supported preset under its documented settings collection.
  3. Choose clear keys and slugs; remember that camelCase is converted to kebab case.
  4. Reference the token with var:custom|… or var:preset|… inside theme.json.
  5. Use var(--wp--custom--…) or var(--wp--preset--…) in ordinary CSS.
  6. Apply supported properties in styles, styles.elements, or styles.blocks so Global Styles can manage them.
  7. Use styles.css or an external stylesheet only for selector-specific or otherwise unsupported CSS.
  8. Verify the generated property in both the editor and the front end, then inspect cascade and specificity if a rule is overridden.

Bottom line

settings.custom is WordPress’s declaration point for your own CSS custom properties. Registered presets are the standardized, editor-oriented option; custom settings are the flexible token layer. Define each value once, use WordPress token syntax in theme.json, use normal var() syntax in CSS, and keep consumers in the styles tree whenever the standard API supports the property.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.