To add custom CSS in WordPress, open Appearance, Customize, Additional CSS on a classic theme, or Appearance, Editor, Styles, then the three-dot menu and Additional CSS on a block theme. Paste your rules, save, and they load after the theme's own stylesheet, so you only write the rules you want to change.
That is the whole how-to. The rest of this post is about the part every guide skips: where WordPress keeps that CSS, which explains why it disappears on a theme switch, on a child theme, on multisite, and after some security hardening.
Where to add custom CSS in WordPress
There are four places, and they behave differently enough that picking the right one matters more than the CSS itself.
| Where | Theme type | Stored in | Survives a theme update | Survives a theme switch |
|---|---|---|---|---|
| Customizer, Additional CSS | Classic | a custom_css post, one per theme |
Yes | No |
| Site Editor, Styles, Additional CSS | Block | the wp_global_styles post, one per theme |
Yes | No |
A child theme's style.css |
Either | a file on disk | Yes | No |
| A plugin or mu-plugin | Either | the plugin's own storage or file | Yes | Yes |
The first two are the ones people mean by "custom CSS". They live in the database, not in theme files, which is why a theme update does not touch them.
It is also why a theme switch does.
Where Additional CSS is stored on a classic theme
Each theme gets its own row in wp_posts with post_type = 'custom_css'. Its post_name is the theme's folder name (the stylesheet slug), and post_content is your CSS, verbatim.
You can see them all with WP-CLI:
wp post list --post_type=custom_css --fields=ID,post_name,post_modified
On a site that has been through a few themes you will usually find several rows, one per theme anyone ever saved CSS in.
That is your CSS from the old theme. It was never deleted, only no longer looked up.
The lookup is wp_get_custom_css_post(). It searches for the custom_css post whose slug matches get_stylesheet(), the active theme's folder.
The front end prints the result in <style id="wp-custom-css"> on wp_head at priority 101, late enough to come after the theme's stylesheet.
Why custom CSS disappears when you change theme
Because the new theme has a different folder name, so the lookup finds a different post, or none. Switch back and the old CSS reappears, because its post was there the whole time.
This catches people in a specific way: activating a child theme.
A child theme has its own folder, so it has its own stylesheet slug and starts with no Additional CSS at all.
Your parent theme's CSS is still in the database under the parent's slug, and the site suddenly looks unstyled in exactly the places you had fixed.
To carry it across, copy it into the active theme's post. This reads the old theme's CSS and saves it for the current one:
wp eval 'wp_update_custom_css_post( wp_get_custom_css( "twentytwentyone" ) );'
Replace twentytwentyone with the old theme's folder name from the post_name column above. Be aware this replaces whatever CSS the active theme already had rather than appending to it.
Where custom CSS is stored on a block theme
Block themes do not show Customize in the Appearance menu, so the Customizer panel is gone. The Site Editor replaces it.
Open Styles, then the three-dot More menu, then Additional CSS.
That CSS is saved in a different place: the theme's wp_global_styles post, the same one that holds every colour, font and spacing change you make in Styles.
Its slug is wp-global-styles- plus the theme's folder name, and it is linked to the theme through the wp_theme taxonomy.
Your CSS sits inside its JSON as styles.css.
wp post list --post_type=wp_global_styles --fields=ID,post_name
There is also per-block CSS.
In Styles, Blocks, pick a block, and the Advanced panel accepts CSS without a selector; WordPress scopes it to that block.
It is stored in the same post under styles.blocks, so it has the same per-theme lifetime.
The same rule applies to child themes here too.
A child block theme has its own stylesheet slug, so it starts with a fresh set of user styles. Activating one drops every Styles change you made on the parent, not only the CSS.
What happens to old Customizer CSS on a block theme
It still prints, if a custom_css post exists for the active block theme. WordPress 7.1 merges it into the global styles inline stylesheet, in this order:
- The theme.json styles.
- The Customizer's Additional CSS for this theme.
- The Site Editor's Additional CSS.
So on a block theme there is no <style id="wp-custom-css"> tag to find in the page source. Look inside <style id="global-styles-inline-css"> instead.
If both a Customizer rule and a Site Editor rule set the same property with the same selector, the Site Editor one wins because it comes later.
Why the Additional CSS panel is missing
If the panel is not where this post says it should be, it is usually one of three things.
- You are on a block theme. The Customizer link is hidden, so look in the Site Editor. Core shows Customize again only when a plugin or the theme hooks
customize_register. - The site is multisite and you are not a super admin. Additional CSS needs the
edit_csscapability. Core maps it tounfiltered_html, and on multisite only super admins get that. A site administrator on a network does not see the panel at all. - Someone set
DISALLOW_UNFILTERED_HTML. That constant deniesedit_cssto every user, administrators included. It is a common line in hardening guides, and it removes Additional CSS in both the Customizer and the Site Editor as a side effect.
The capability check is in map_meta_cap(), in the same case as unfiltered_html. That is deliberate: CSS can carry content that matters for security, so core treats it like raw HTML.
Why custom CSS is not working
Assuming the panel is there and you saved, these are the causes worth checking, roughly in order of how often they bite.
Caching. A page cache or CDN will serve the old HTML, and on a classic theme the CSS is inline in that HTML. Purge the cache before debugging anything else.
Our post on clearing the WordPress cache covers each layer.
Specificity. Custom CSS loads last, but a more specific theme selector still beats a later, weaker one. Inspect the element in the browser's developer tools and match or exceed the selector the theme uses, rather than reaching for !important everywhere.
It refuses to save. WordPress rejects CSS containing </style, with the message The CSS must not contain "</style".
The Site Editor shows The custom CSS is invalid. Do not use <> markup. Usually this means something was pasted from an HTML snippet, tags included.
It saved, but nothing prints. This is the rare one.
wp_get_custom_css_post() caches the post ID in the theme mod custom_css_post_id, and it caches -1 when it finds no post.
If a custom_css post is created behind its back (an import, a plugin writing the row directly, wp post create), the cached -1 means WordPress never looks again.
The source even carries a @todo saying the cache should be cleared in that case. Clear it yourself:
wp theme mod get custom_css_post_id
wp theme mod remove custom_css_post_id
You are editing the wrong theme's CSS. After a child theme switch, the Customizer shows the child's (empty) CSS. The parent's is still in the database, as above.
Can you get old custom CSS back?
Often, yes.
The custom_css post type supports revisions, and WordPress saves one each time you publish a change from the Customizer, although the Customizer has no screen to browse them. List them and restore one with WP-CLI:
wp post list --post_type=revision --post_parent=<custom_css post ID> --fields=ID,post_date
wp eval 'wp_restore_post_revision( <revision ID> );'
On a block theme, the Site Editor does have a screen for this: Styles, then Revisions, which covers your Additional CSS along with every other style change. If revisions are disabled with WP_POST_REVISIONS, there is nothing to restore, and the only copy is the current row.
Which one should you use?
Use the panel your theme type gives you for small, visual fixes. It is the right tool for a tweak to a button colour, and it survives theme updates, which is the most common reason people lose CSS.
Use a child theme or a small plugin when the CSS is load-bearing. If the site would look broken without it, it belongs in a file under version control, not in a database row tied to one theme's folder name.
A plugin is the only option on the table above that survives a theme switch.
Do not edit the parent theme's style.css directly. The next theme update replaces it, which is the failure our post on the theme file editor walks through.
Test a theme switch before you make it
The losses in this post all happen at one moment: the theme or child theme changes and the lookup key changes with it. You do not find out until the front end looks wrong, and on a live site that is in front of visitors.
The safer order is to clone the site, switch theme on the copy, and compare.
SandyWP's Cloner copies the database and wp-content into a sandbox and only reads from production, so the custom_css and wp_global_styles rows come across with everything else.
Every sandbox has SSH and WP-CLI preinstalled, so the wp post list and wp eval commands above run as written.
Activate the child theme on the copy, run the copy command, check the pages that mattered, and only then do the same on production.
If you are building the theme yourself, the theme developer workflow covers the rest of that workflow.
For the font side of the same problem, see changing the font in WordPress, which stores its choice per theme in the same way.
