How to Fix CSS Not Updating in the Browser and in WordPress

Quick Summary
- Browsers reuse cached stylesheets, so change the file's URL when it changes, such as style.css?ver=123, and every visitor loads the new copy.
- In WordPress, pass filemtime() of the file as the fourth argument of wp_enqueue_style(); the default false only adds the WordPress version.
- If the served file already has your change, look elsewhere: page, CSS-optimization or CDN caches, selector specificity, or the wrong file being edited.
When your CSS changes don’t show up, the browser, or a cache between your server and the browser, is still using the old copy of the stylesheet. To check your own screen, do a hard reload: Ctrl+Shift+R in Chrome on Windows and Linux, or Cmd+Shift+R in Chrome on a Mac. To make every visitor load the new file, change the stylesheet’s URL whenever the file changes, for example custom-style.css?ver=123. In WordPress, pass that version as the fourth argument of wp_enqueue_style(), and use filemtime() so it updates by itself.
Why does the browser keep the old CSS?
Browsers store stylesheets and reuse them on the next page view. If your server sends cache headers, for example after setting Expires headers in .htaccess, the browser may not ask for the file again for weeks. Even without such headers, browsers may reuse a file for a while based on its age; MDN calls this heuristic caching.
To the browser, a different URL is a different file. That’s why a version number in the URL works. In a test in headless Chrome 153, a stylesheet was served with a one-hour cache time and then edited:
- Linked as plain
custom-style.css, the page kept the old styles when it was visited again and after a normal reload. Only a hard reload fetched the new file. - Linked with
?ver=and the file’s modification time, the page showed the new styles on the next visit, because the edit changed the URL.
How do you check that it’s really a cache problem?
Open your browser’s developer tools, tick Disable cache in the Network panel and reload. The option exists in Chrome, Edge and Firefox; in Chrome it only applies while DevTools is open. You can also open the stylesheet’s URL directly from the page source and look for your change.
If the file the page loads already contains your change, the cache isn’t the problem. Select the element and check the Styles panel: a rule with a more specific selector may win. Or you edited a different file from the one the page loads, such as the parent theme’s stylesheet instead of the child theme’s, or a Sass file whose compiled CSS goes elsewhere (see setting the output path in Live Sass Compiler).
How do you force WordPress to load the new file?
Use the version argument of wp_enqueue_style(). Its signature in WordPress 7.1 is wp_enqueue_style( $handle, $src, $deps, $ver, $media ), and wp_register_style() takes the same arguments. WordPress adds $ver to the file’s URL as ?ver=:
false, the default, adds the WordPress version, such as?ver=7.1.2. The URL then only changes when you update WordPress, which is why a stylesheet enqueued without a version keeps its old URL after you edit it.nulladds no version at all.- Any other value, such as
'1.2.0', is added as it is.
The simplest version to maintain is the file’s modification time. Add this to your child theme’s functions.php:
function my_theme_enqueue_styles() {
$file = '/css/custom-style.css';
wp_enqueue_style(
'custom-style',
get_stylesheet_directory_uri() . $file,
array(),
filemtime( get_stylesheet_directory() . $file )
);
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );filemtime()returns the time the file was last changed, as a Unix timestamp. Every time you save the file, the number and so the URL change, and browsers download the new copy. Until then, they keep using their cached one.filemtime()needs the file’s path on the server, fromget_stylesheet_directory(), while the URL comes fromget_stylesheet_directory_uri(). Both point to the active theme, which is the child theme when you use one. For a file in the parent theme, useget_template_directory()andget_template_directory_uri(), as explained in child and parent theme paths.
Run in WordPress 7.1.2 with the theme’s style.css as the file, it printed a link ending in style.css?ver=1790465183.
If you prefer to control the version yourself, pass wp_get_theme()->get( 'Version' ) instead. That reads the Version line of the active theme’s style.css header, so the URL changes each time you raise that number.
An earlier version of this post passed rand(111,9999) as the version. That changes the URL on every page load, so browsers download the stylesheet every time and never use their cache. It’s harmless while you develop, but on a live site use filemtime() or the theme version.
What if the stylesheet is linked in a template?
In a WordPress theme, load the file with wp_enqueue_style() as above rather than a <link> tag in header.php. On a plain PHP site, you can add the modification time to the link yourself:
<link rel="stylesheet" href="/css/custom-style.css?ver=<?php echo filemtime( __DIR__ . '/css/custom-style.css' ); ?>">__DIR__ is the folder of the PHP file that contains the tag; adjust the path if the stylesheet lives elsewhere. In a test with PHP’s built-in server, the printed version changed as soon as the CSS file was saved.
What other caches can serve old CSS?
- Page caching. A caching plugin or your host may serve a saved copy of the page’s HTML, which still links the old
?ver=URL. Clear the page cache after you change a stylesheet. - CSS optimization. Plugins that minify or combine CSS write their own copies of your files. Clear their cache too.
- A CDN. Cloudflare’s default caching level, Standard, treats each query string as a different file, so a new
?ver=reaches visitors. If your CDN is set to ignore query strings, purge the file there after each change. - Additional CSS. CSS entered in the Customizer’s Additional CSS box is printed inside the page, in a
<style id="wp-custom-css">tag, not as a separate file. If it doesn’t show, a page cache or a more specific rule is the likely cause, not the browser’s file cache. - Block themes. WordPress merges
theme.jsonfirst and the styles saved in the Site Editor last, so a setting changed in the Site Editor overrides the same setting intheme.json. If an edit totheme.jsondoesn’t show, check whether that style was customized in the editor.
Frequently asked questions
Why does a hard refresh show my changes when visitors still see the old CSS?
A hard refresh reloads the page without using your browser’s cache. In Chrome, that’s Ctrl+Shift+R or Shift+F5 on Windows and Linux, and Cmd+Shift+R on a Mac. In Safari on a Mac, Cmd+Shift+R opens Reader instead; hold Option and use Reload Page From Origin in the View menu. Visitors keep their cached copy until the file’s URL changes or the cache expires.
Does a version in the URL stop the stylesheet from being cached?
No, as long as the version only changes when the file does. Each ?ver= URL is cached like any other file. In the Chrome test, a normal reload with an unchanged version used the cached copy and sent no new request for the stylesheet.
Related articles
- fixing the browser caching warning: the cache headers that make versioned URLs matter
- child and parent theme paths in WordPress: which function points to which theme folder
- the output path for compiled CSS in Live Sass Compiler: when the file you edit isn’t the file the page loads

