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:

the replay graphic november 5

The Replay (11/5/25): Developer elitism, REST APIs, and more

Discover what’s new in The Replay, LogRocket’s newsletter for dev and engineering leaders, in the November 5th issue.

Matt MacCormack
Nov 5, 2025 ⋅ 32 sec read
lewis cianci quote developer elitism

It’s time to break the cycle of developer elitism

A senior developer discusses how developer elitism breeds contempt and over-reliance on AI, and how you can avoid it in your own workplace.

Lewis Cianci
Nov 5, 2025 ⋅ 13 min read
open ai agent kit

I tried OpenAI’s AgentKit: Does it make Zapier and n8n obsolete?

Examine AgentKit, Open AI’s new tool for building agents. Conduct a side-by-side comparison with n8n by building AI agents with each tool.

Clara Ekekenta
Nov 4, 2025 ⋅ 11 min read

A Jarvis for everyone: AI agents as new interfaces

AI agents powered by MCP are redefining interfaces, shifting from clicks to intelligent, context-aware conversations.

Peter Aideloje
Nov 4, 2025 ⋅ 10 min read
View all posts

7 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.

  2. So how do you use this on a standard static HTML website? What if someone does not use any javascript or php frameworks?

Leave a Reply

Would you be interested in joining LogRocket's developer community?

Join LogRocket’s Content Advisory Board. You’ll help inform the type of content we create and get access to exclusive meetups, social accreditation, and swag.

Sign up now