2023-06-09
2460
#css
Hamsa Harcourt
84343
Jun 9, 2023 â‹… 8 min read

Guide to removing unused CSS code with PurgeCSS

Hamsa Harcourt I'm Hamsa, a software engineer with a strong passion for building human-centric products. I love teaching concepts about JavaScript and the web at large.

Recent posts:

How to manage JavaScript closures in React

The proper handling of JavaScript closures is essential to any JavaScript project. In React projects specifically, closures can manifest themselves […]

Tanishka Kashikar
Mar 24, 2025 â‹… 10 min read
array filter method javascript

How to use the array filter() method in JavaScript

Learn about the array filter() method, from its basic syntax and use cases to more advanced techniques like chaining with map() and reduce().

Abiola Farounbi
Mar 24, 2025 â‹… 5 min read
css vertical alignment

CSS vertical alignment: Best practices and examples

CSS has come a long way, making vertical alignment easier than ever. Learn about this concept and explore some of the best CSS vertical alignment techniques.

Facundo Corradini
Mar 23, 2025 â‹… 8 min read
How to win clients with a Flutter web demo that feels real

How to win clients with a Flutter web demo that feels real

Use Flutter to build browser-based app demos that help clients visualize the product, speed up buy-in, and close deals faster.

Lewis Cianci
Mar 21, 2025 â‹… 5 min read
View all posts

6 Replies to "Guide to removing unused CSS code with PurgeCSS"

    1. Keep in mind that PurgeCSS doesn’t touch your source CSS files, just the ones that are output by the build process. So if you add new code that needs CSS rules that were previously purged, then the next time you build your app PurgeCSS will see that your code is using some new rules and will not purge them in that build.

  1. In frameworks such as Angular, you can use scss which is complied down to css. Is there any way to achieve this on scss?

    1. It doesn’t make sense to run it on SCSS because other SCSS files might be referencing your code dynamically elsewhere. You can transpile it to CSS, then run the process on CSS as part of your CI pipeline or have a local git hook to do so. It has the same effect.

Leave a Reply