April 24, 20206 yr Is there a tool to find out if any custom class or id in my css file is currently unused? I'm talking about the id/classes I've created, eg: .main-hero #technology #technology ul etc. I'm in the process of reorganising it but first would like to get rid of anything that is not used. Thank you
April 24, 20206 yr There's a tab in Chrome's developer tools that does it, but it's only per page - https://developers.google.com/web/tools/chrome-devtools/coverage
April 24, 20206 yr You can actually automate this too using https://purgecss.com, which is what I do to remove extra utility classes that I don't use in my CSS file. It's quite advanced to setup though so I'd only consider it if it's something you really need.
April 25, 20206 yr Author That's a neat idea. Can it just highlight the unused classes (as opposed to removing them) so the user can review it before deleting?
April 25, 20206 yr 1 hour ago, portia79 said: That's a neat idea. Can it just highlight the unused classes (as opposed to removing them) so the user can review it before deleting? I don't think so, it's designed to be used before deploying code to a live site, so there's no benefit of doing manual checks and keeping code. It would actually take forever to review some codebases if you had to do this every time. I wouldn't bother using something like PurgeCSS unless you're really familiar with frontend tooling, otherwise you'll give yourself a lot of headaches. It's nice to know tools like this exist, but they have quite advanced use cases. For most sites you likely wouldn't need to remove unused CSS, it's one of those things that's actually not that common.
Create an account or sign in to comment