CodeKit - PurgeCSS (2024)

What's PurgeCSS?

PurgeCSS removes unused CSS rules from your stylesheets to reduce their size and therefore speed up page-loads.

It's very important that you configure this tool correctly, or it will remove CSS rules that you need!

Enabling PurgeCSS

CodeKit - PurgeCSS (1)

First, make sure you've read Setting Language Options.

PurgeCSS is available for Sass, Less, Stylus, and regular CSS files. Select one of those files, then click the "Purge Unused CSS Rules" pop-up button:

You can also turn on PurgeCSS for all files at once. Open Project Settings, choose one of the languages above, then click the "Purge Unused CSS" pop-up button.

Build Environments

Along with "always" and "never", you can set PurgeCSS to run only when your project's Build Environment is set to "Production" or "Development". You can change this environment in Project Settings > General.

(Using the Build Environment options lets you rapidly toggle various tools on and off all at once simply by changing the environment.)

See Also
Unminify CSS

PurgeCSS Options

Open Project Settings > PurgeCSS to adjust settings:

CodeKit - PurgeCSS (2)
Critical: Pages To Scan

This list MUST contain every type of file where you use CSS rules. PurgeCSS will look only in these files to decide if each rule is used or not. If you use a custom filetype and forget to add it to this list, PurgeCSS may remove rules you need in your final CSS!

Follow the pattern to add your own entries. The **/*.html means "look in every subfolder for any file with an 'html' extension and scan it".

Skipped Content

If you need to exclude certain folders, use this list. The default entry node_modules/** will prevent PurgeCSS from scanning files of any type in (and below) the "node_modules" folder.

Safe & Block Lists
CodeKit - PurgeCSS (3)

These lists let you tell PurgeCSS to always keep or delete a certain rule, regardless of whether it's used or not.

Each entry can be a string (class name, ID, element name, etc.) or regex pattern.

Danger: Things to Know

PurgeCSS is deliberately naive when scanning for used CSS rules. It would be too slow to parse and run each file, so PurgeCSS simply looks for the text of each rule. This means if you do "clever" things with CSS rules in your JavaScript (such as combine different parts of a rule's name instead of using the full name all in one string), PurgeCSS may not detect that a rule is used by your script.

For details, read the official PurgeCSS Documentation.

CodeKit - PurgeCSS (2024)

FAQs

How does PurgeCSS work? ›

PurgeCSS matches the CSS selectors used in your HTML elements with those in stylesheets. Then, it automatically removes all unused rules, producing smaller CSS files. Since the default behavior may produce undesired results, it is highly customizable and supports many options.

How to remove unused CSS? ›

How to manually remove unused CSS
  1. From the Show Coverage option, select a CSS file. ...
  2. Then, click on CSS Overview:
  3. Next, click on Capture Overview, and you'll be presented with the CSS overview page, as shown below:
  4. On this page, navigate to the Unused declarations option, and you'll be shown the page in the image below:
Aug 4, 2023

How to configure PurgeCSS? ›

You can specify content that should be analyzed by PurgeCSS with an array of filenames or globs open in new window. The files can be HTML, Pug, Blade, etc. PurgeCSS also works with raw content. To do this, you need to pass an object with the raw property instead of a filename.

How to remove unused CSS in Angular? ›

In angular material, color="primary" changed to mat-primary in runtime. Post-build (PurgeCss), All the mat classes are removed from styles. css which are not used in any of the HTML/js files.

Is PurgeCSS good? ›

Modularity enables developers to create module extractors for specific use cases and frameworks. An extractor is a function that reads the contents of a file and extracts a list of CSS selectors that are used. PurgeCSS provides a very reliable default extractor that can work with a wide range of files types.

What is the alternative to PurgeCSS? ›

As mentioned before, there are 2 alternatives to PurgeCSS: UnCSS & PurifyCSS.

Should I remove unused CSS? ›

CSS rules are one of the most common sources of site bloat. Removing unused CSS on WordPress sites improves speed and performance. If you ran a performance audit of your site through PageSpeed Insights, you may have come across the “Reduce unused CSS” (previously “Remove unused CSS”) recommendation.

How do I remove unused CSS asset CleanUp? ›

Asset cleanup is a plugin that helps you to reduce unused CSS to improve the WordPress website's pagespeed. First, it will fetch the homepage and will show you all CSS files loaded on that page. You need to review all loaded files. If you find any files that you don't need then you need to unload that file.

What is the extension to remove unused CSS? ›

Here are the two easy plugins to be able to remove unused CSS that is loading on your WordPress website.
  1. Core Web Vitals & PageSpeed Booster. Core Web Vitals & PageSpeed Booster – WordPress plugin. ...
  2. Asset Cleanup. Asset CleanUp: Page Speed Booster – WordPress Plugin.
Jan 14, 2022

How to use PurgeCSS with React? ›

This example shows how to set up PurgeCSS with create-react-app template.
  1. Method 1 - Use craco. Custom PostCSS plugins (including PurgeCSS) can be added to Create React App apps using craco. ...
  2. Method 2 - Run PurgeCSS CLI in postbuild. Add the following code in package.json.
  3. Method 3 - eject create-react-app.
Nov 22, 2019

Does Tailwind remove unused CSS? ›

Removing all unused styles

By default, Tailwind will only remove unused classes that it generates itself, or has been explicitly wrapped in a @layer directive. It will not remove unused styles from third-party CSS you pull in to your project, like a datepicker library you pull in for example.

How to find unused CSS in Visual Studio Code? ›

Open the Coverage tool
  1. To open DevTools, right-click the webpage, and then select Inspect. Or, press Ctrl+Shift+I (Windows, Linux) or Command+Option+I (macOS). ...
  2. In DevTools, open the Command Menu. ...
  3. Start typing coverage, press the Down Arrow key to highlight the Show Coverage command, and then press Enter:
Dec 7, 2023

What is purge CSS? ›

PurgeCSS is a tool to remove unused CSS. It can be used as part of your development workflow. PurgeCSS comes with a JavaScript API, a CLI, and plugins for popular build tools. Here are a couple of ways to use PurgeCSS: CLI.

How do I remove an existing CSS? ›

setProperty() method can be used to set the required property of the style. The element of which the property has to be removed is selected and this property is applied to its style property. Setting this property to 'initial' resets the property to its initial value, removing any effect of the property.

How do I remove unused CSS from Chrome? ›

Chrome DevTools Coverage panel for unused JS and CSS
  1. Open Chrome DevTools. Control + Shift + I. ...
  2. Open the Command Menu. Control + Shif t +P. ...
  3. Type + click the following: "Show Coverage"
  4. Click the reload button to reload the page and to see which code is loaded.
  5. Then double click on the JS or CSS file that you want to unminify.
Feb 23, 2021

How to use PurgeCSS in React? ›

This example shows how to set up PurgeCSS with create-react-app template.
  1. Method 1 - Use craco. Custom PostCSS plugins (including PurgeCSS) can be added to Create React App apps using craco. ...
  2. Method 2 - Run PurgeCSS CLI in postbuild. Add the following code in package.json.
  3. Method 3 - eject create-react-app.
Nov 22, 2019

How does Tailwind remove unused CSS? ›

The problem of unused CSS

For example, Tailwind uses PurgeCSS to remove unused CSS from final builds automatically. Netflix Top 10 uses Tailwind on its entire website and only requires 6.5kB for the CSS file. The CSS file would be ten times the final build size without removing unused CSS.

Does Webpack remove unused CSS? ›

Remove unused CSS using uncss in Webpack. This plugin is an alternative to using UnCSS with postcss-loader . Running UnCSS as a loader has a few drawbacks: There is no way to obtain the HTML files in the pipeline, hence you can only run UnCSS against HTML files on disk.

Top Articles
Which types of motorcycles are easiest to insure in 2024?  | Rate.com
What Is Ethereum 2.0? How Is It Different From Ethereum? | SoFi
Weather.com Radar Map
K-Active – Jetzt kaufen bei SVG
How to Use Craigslist (with Pictures) - wikiHow
Understanding Sheryl Crow's Impressive Net Worth And Wealth
Funeral Homes in Grand Forks, North Dakota
Bj타리
Kevin Murphy: Current: Faculty: Jacobs School of Music: Indiana University Bloomington
Gunny's Burgers The Mule
Danielle Moodie-Mills Net Worth
No Cable Schedule
Cobblemon Resource Pack
Ark Fjordur Managarmr
Bible Gateway passage: John 6 - New International Version
Kodo Yocan Blinking 5 Times
Green Light Auto Sales Dallas Photos
Craigslist Hunting Land For Lease In Ga
The Equalizer 3 - The Final Chapter
Cosentyx® 75 mg Injektionslösung in einer Fertigspritze - PatientenInfo-Service
La Monja 2 Pelicula Completa Tokyvideo
Cvs Minuteclinic Locations Near Me
Creed 3 Showtimes Near Southeast Cinemas Alamance Crossing Stadium 16
Bellapyr
craigslist sitemap for Ludington ± 9 mi
Peekskillpatch
How to Sell Cars on Craigslist: A Guide for Car Dealers | ACV Auctions
Bolly2Tolly.app | Watch Full HD Movies Online
Magma Lozenge Location
Soap2Day That 70S Show
Skip The Strip And Head To These Unique Hidden Gems In Las Vegas - Explore
80 For Brady Showtimes Near Cinemark At Harlingen
Shapers Stars
Ame Bibabi Net Worth
How To Get The Unphased Badge In Slap Battles
Craigslist Odessa Midland Texas
M12 X 1.5 : Thread Dimensions (Machining Doctor)
What Auto Parts Stores Are Open
Polaris ATV Motorrad kaufen und verkaufen
Deer Shed Clover Sc
Hidden Figures Movie Quiz Answers
Kamzz Llc
Pokemon Sapphire Evolution Chart
Eve Fastest Ship
Www.socialserve.com Ga
Craigslist Lake Charles
Indiana Wesleyan Transcripts
7.5/8 As A Percent
Meet The Parents Putlocker
Craigslist Domestic Job
Jigme Khesar Namgyel Wangchuck Net Worth
Qvc Host Dies Lisa Robertson Cause Of Death
Latest Posts
Article information

Author: Merrill Bechtelar CPA

Last Updated:

Views: 6047

Rating: 5 / 5 (50 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Merrill Bechtelar CPA

Birthday: 1996-05-19

Address: Apt. 114 873 White Lodge, Libbyfurt, CA 93006

Phone: +5983010455207

Job: Legacy Representative

Hobby: Blacksmithing, Urban exploration, Sudoku, Slacklining, Creative writing, Community, Letterboxing

Introduction: My name is Merrill Bechtelar CPA, I am a clean, agreeable, glorious, magnificent, witty, enchanting, comfortable person who loves writing and wants to share my knowledge and understanding with you.