October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk10 min

How to Add CSS Variables to a WordPress Child Theme

Learn where to define CSS custom properties in a WordPress child theme, how to load the child stylesheet correctly, and how to troubleshoot missing or overridden variables.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Define your custom properties in the child theme’s root style.css, then make sure WordPress actually loads that file. Use :root for site-wide tokens, component selectors for local tokens, and var() wherever a token is consumed. Classic themes may need a dependent functions.php enqueue; block themes often manage design settings through theme.json instead.

What you need before adding variables

A child theme is an extension of a parent theme. It keeps the parent’s templates and functionality while giving you a safer place for custom styles and overrides. Your child theme must be installed under wp-content/themes and activated in WordPress before its CSS can affect the front end.

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.
  • Know the parent theme’s directory name, including capitalization. This is the folder name, not necessarily the theme’s display name.
  • Have a child-theme directory inside wp-content/themes.
  • Use a root-level style.css in that child directory.
  • Check whether the site uses a classic theme or a block theme before deciding how styles should be loaded.

The Template header in the child stylesheet must match the parent folder exactly. If it does not, WordPress will not associate the child with the intended parent.

/*
Theme Name: My Child Theme
Template: parent-theme-folder
*/

Replace My Child Theme with the name you want displayed in the Themes screen and replace parent-theme-folder with the exact parent directory name. Keep this file at the top level of the child theme; placing it in a subfolder prevents WordPress from recognizing it correctly.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

How CSS custom properties work

CSS variables are formally called custom properties. Their names begin with two hyphens, such as --brand-color, and their values are read with the var() function. They are not PHP variables and do not require a WordPress plugin.

Custom properties participate in the normal CSS cascade and inherit by default. A declaration on :root is available throughout the document unless another rule overrides it. A declaration on a component, such as .card, is available to that component and its descendants.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
:root {
  --brand-color: #14532d;
  --surface-color: #ffffff;
  --text-color: #1f2937;
  --content-gap: 1.5rem;
}

.card {
  --card-radius: 0.75rem;
  border-radius: var(--card-radius);
}

Use names that describe a design role rather than a single location. --brand-color remains useful if the color later changes from green to another hue, while a name such as --green-header-border ties the token to an implementation detail.

Step 1: Put shared tokens on :root

For colors, spacing, typography scales, borders, and other values used in multiple areas, add a :root block to the child theme’s style.css. The following is a complete starting point:

:root {
  --brand-color: #14532d;
  --surface-color: #ffffff;
  --text-color: #1f2937;
  --content-gap: 1.5rem;
  --radius-medium: 0.75rem;
  --shadow-soft: 0 8px 24px rgb(15 23 42 / 0.12);
}

The values can be lengths, colors, font families, numbers used in calculations, or other valid CSS values. A custom property stores the token as written; the browser validates the final declaration when the token is substituted into a normal property.

Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.

Use a component-scoped property when a value has no useful meaning outside that component:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.pricing-card {
  --card-radius: 0.75rem;
  --card-padding: 1.25rem;
  border-radius: var(--card-radius);
  padding: var(--card-padding);
}

This keeps the global namespace smaller and lets a nested variant override the component without changing unrelated elements.

Step 2: Consume the tokens in child-theme rules

Call a token inside a regular declaration with var(--token-name). The function can replace a complete value or one part of a value.

body {
  color: var(--text-color);
  background: var(--surface-color);
}

.site-header {
  border-bottom: 1px solid var(--brand-color);
  padding-block: var(--content-gap);
}

.entry-content a {
  color: var(--brand-color);
}

.button {
  border-radius: var(--radius-medium);
  box-shadow: var(--shadow-soft);
}

var() cannot be used as a property name or selector. This is valid:

.button {
  background-color: var(--brand-color);
}

This is not valid CSS:

var(--property-name): red;

Custom-property names are case sensitive. --Brand-Color and --brand-color are different tokens, so spelling and capitalization must match at every use.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by

Step 3: Add fallbacks where a token may be unavailable

Pass a second argument to var() when the declaration should use a backup value if the custom property is undefined or invalid:

.button {
  background: var(--brand-color, #0f766e);
  color: var(--button-text-color, #ffffff);
}

The fallback is used by browsers that support custom properties when the named token cannot provide a valid value at that point in the cascade. It is not a compatibility substitute for browsers that do not support custom properties at all. If broad legacy-browser support is a requirement, provide an ordinary declaration before the variable-based declaration:

.button {
  background: #0f766e;
  background: var(--brand-color, #0f766e);
}

Keep fallbacks close to the use site when the component must remain usable even if a global token is removed. If the token is mandatory and a missing value should be obvious during development, omitting the fallback can make the failure easier to spot in computed styles.

Classic themes: make sure WordPress loads the CSS

Do not assume every parent theme loads the same files. Some parent themes load both parent and child stylesheets, some load only the active stylesheet, and some documented themes do not load a stylesheet automatically. Inspect the parent theme’s enqueue code and test the actual page source or network panel before adding PHP.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Situation What to do Why it matters
The parent already loads the child stylesheet Leave the existing mechanism in place and do not enqueue the same file again. Duplicate handles or files make load order and caching harder to diagnose.
The parent loads its own CSS but not the child CSS Enqueue the parent first and the child with the parent handle as a dependency. The child rules then arrive after the parent rules, allowing intended overrides.
The theme has no automatic stylesheet loading Add an explicit enqueue in the child theme’s functions.php. A perfectly written variable block has no effect if the browser never receives the file.

For a classic theme that needs explicit loading, add this to the child theme’s root functions.php:

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.
<?php
function my_child_enqueue_styles() {
    $parent = 'parent-style';

    wp_enqueue_style(
        $parent,
        get_parent_theme_file_uri( 'style.css' )
    );

    wp_enqueue_style(
        'child-style',
        get_stylesheet_uri(),
        array( $parent ),
        wp_get_theme()->get( 'Version' )
    );
}
add_action( 'wp_enqueue_scripts', 'my_child_enqueue_styles' );

wp_enqueue_style() is WordPress’s standard stylesheet-enqueue function. The first call registers the parent stylesheet under a handle. The second call loads the child stylesheet and lists that handle in its dependency array, so WordPress places the child after the parent. The version argument comes from the active child theme’s metadata and can help browsers request a fresh file after a theme update.

Use a unique function name and handles that do not collide with another plugin or theme. If the parent uses a different stylesheet, a custom handle, or its own dependency logic, adapt the example to that implementation rather than blindly adding a second parent load.

Classic versus block themes

The correct workflow depends on the theme architecture.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Decision Classic theme Block theme
Primary style mechanism Stylesheets and PHP enqueue logic are common. Design settings and many styles are commonly expressed through theme.json.
Where to start Inspect the parent’s stylesheet-loading code and the child’s functions.php. Inspect the existing theme.json settings and styles first.
Is child style.css always required for design tokens? Usually it is the natural location, provided it is loaded. Not necessarily. Style loading is optional and often unnecessary for settings handled through theme.json.
When to add CSS For custom properties and selectors not supplied by the parent. For rules that theme.json cannot express, while ensuring the relevant front-end or editor stylesheet is loaded.

Block themes often centralize color, spacing, typography, and other design settings in theme.json. If the token belongs to a setting that the theme already exposes there, use the existing configuration rather than creating a parallel CSS system. Add a stylesheet when you need custom selectors, component-specific behavior, or CSS features not represented by the theme settings.

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

A complete child-theme example

The following combines a root token set, a component token, ordinary fallbacks, and real selectors. Place it in the child theme’s root style.css after the required header.

/*
Theme Name: My Child Theme
Template: parent-theme-folder
*/

:root {
  --brand-color: #14532d;
  --surface-color: #ffffff;
  --text-color: #1f2937;
  --content-gap: 1.5rem;
  --radius-medium: 0.75rem;
}

body {
  color: var(--text-color, #1f2937);
  background: var(--surface-color, #ffffff);
}

.site-header {
  border-bottom: 1px solid var(--brand-color, #14532d);
  padding-block: var(--content-gap, 1.5rem);
}

.card {
  --card-radius: var(--radius-medium, 0.75rem);
  border-radius: var(--card-radius);
  background: var(--surface-color, #ffffff);
}

.button {
  background: var(--brand-color, #0f766e);
  color: #ffffff;
}

Notice that the component token can itself reference a global token. A local override can then change only one card variant:

.card--square {
  --card-radius: 0;
}

Verify that the variables are working

Test in a logged-out front-end view as well as while signed in, because editor and admin styles can differ. Use browser developer tools to inspect an element that should receive a token.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Open the page and choose Inspect on the affected element.
  2. In the Styles or Computed panel, search for the custom-property name, such as --brand-color.
  3. Confirm that the declaration appears on :root, the component, or an ancestor from which it should inherit.
  4. Check that the consuming declaration, such as color: var(--text-color), is not crossed out by a later or more specific rule.
  5. Open the page source or the browser’s Network panel and confirm that the child stylesheet returns successfully.
  6. After changing CSS, reload without a stale cache if the old value remains visible. The enqueue version helps with cache-busting, but host, CDN, and browser caches can still be involved.

Troubleshooting: why child-theme CSS is not loading

The child theme is not recognized or cannot be activated

  • Confirm that the child directory is directly under wp-content/themes.
  • Confirm that style.css is in the child directory’s root.
  • Check that the Template value exactly matches the parent folder, including case and hyphens.
  • Make sure the child theme is active in the Themes screen.

The stylesheet request is missing

If the child file does not appear in page source or the network panel, inspect the parent’s loading behavior. Add the explicit enqueue only when the parent does not already load the child. For a classic theme, verify that the enqueue function is attached to wp_enqueue_scripts and that the child functions.php has no PHP syntax error.

The file loads but the variable is empty

  • Check the token’s spelling and capitalization; names are case sensitive.
  • Check that the declaration is inside a valid selector block and that a closing brace was not omitted earlier in the file.
  • Inspect the element and its ancestors to see whether the token is inherited from the expected scope.
  • Look for a later declaration that overrides the same custom property.
  • Add a temporary fallback, such as var(--brand-color, magenta), to distinguish an undefined token from a color that is merely being overridden.

The variable exists but the property is crossed out

This is normally a cascade or specificity issue. The token may be valid while another rule wins on the consuming property. Compare the selector, source order, and any !important declarations. Loading the child stylesheet after the parent helps, but it does not automatically defeat a more specific selector in another stylesheet.

The front end works but the editor does not

Front-end and editor styles can use different loading paths, especially in block themes. Check whether the custom rule is intended for the editor, the front end, or both, and ensure the relevant stylesheet is registered for that context. For a block theme, inspect theme.json before adding another global CSS layer.

Choosing the right scope and loading method

Choice Use it when Main trade-off
:root token The value is a site-wide design token used by multiple components. It is easy to reuse but enters the global namespace and can be overridden anywhere in the cascade.
Component token The value belongs only to one component or its descendants. It limits unintended effects but is unavailable outside that component subtree.
Bare var(--token) The token is required and a missing value should be visible during development. An undefined or invalid token can invalidate the consuming declaration.
var(--token, fallback) A supported browser should retain a usable value if the token is absent or invalid. The fallback does not add support for browsers that lack custom-property support.
Parent-provided loading The parent already enqueues the child stylesheet correctly. No extra PHP is needed, but the behavior depends on the parent implementation.
Explicit child enqueue The parent does not load the child file or has no automatic stylesheet loading. It requires PHP and careful dependency ordering.

Safe maintenance practices

  • Keep the required theme header at the top of style.css; put custom properties and rules below it.
  • Use a consistent naming scheme, such as --color-*, --space-*, and --radius-*, so later edits are searchable.
  • Define a token once at the broadest scope that genuinely needs it, then override it locally instead of duplicating values.
  • Change one layer at a time: first confirm the stylesheet request, then the token declaration, then the consuming rule.
  • Inspect both inherited and computed values. A token can be present on an ancestor while a descendant’s local declaration changes what it receives.
  • Do not duplicate a parent stylesheet or child handle merely to make a rule appear later; fix the dependency relationship instead.

With the child theme recognized, the custom properties declared in the right scope, and the stylesheet loaded in the correct order, CSS variables behave like any other cascade-aware CSS feature while giving the theme a reusable design-token layer.

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

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 *

Free tools Windows power users keep installed

One-click scans. No signup required.

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver 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.