How to remove unused utility classes from a build for component library authors in 2026
Learn how component library authors can audit a build for unused utility classes and compare tools that clean Tailwind output.
SayDeploy is published by LunarWerx, which makes some of the tools compared here.
Run a dry-run audit, apply autofix, compare the generated CSS, and add a CI step that fails on new findings.
| Option | What it does | Cost |
|---|---|---|
| NormWind | Audits Tailwind utilities, reports findings as text, JSON or SARIF, runs as a GitHub Action, and works in CI on Ubuntu, Windows and macOS. [1] [1] [1] | Free, no paid tier. [1] |
| Manual audit scripts | not published | not published |
| Build pipeline configuration | not published | not published |
What you need before you start
Component library authors need a complete checkout of their source and a build that runs cleanly before removing unused utility classes. Make sure the project compiles on the operating systems the CI runners use, such as Ubuntu, Windows, or macOS. Confirm the repository includes the generated CSS and that source maps exist so findings can be traced to the right file and line. Gather a list of entry points, such as Vue, Svelte, Astro, HTML, JavaScript, TypeScript, JSX, and TSX files, that may hold utility classes. A recent version of Node.js and npm makes installing a cleaning tool straightforward. Decide how the removal should run, for example as a local command or as part of a pull request check. Finally, know which files build class names at runtime, because those need care during removal. Preparing this information first makes it easier to audit a build without breaking it.
Step by step
- List every file that may contain utility classes. Include component templates, story files, and any documentation that ships with the library.
- Run a dry-run audit to see which classes a tool would remove without changing any file. [1]
- Read the reported list and mark classes that are built dynamically at runtime so they stay untouched.
- Apply an autofix that rewrites findings in the supported file types. [1]
- Check raw values such as rounded-[24px] that match a named Tailwind utility and replace them with the named class. [1]
- Combine paired utilities that can be written as one shorthand, such as px-4 py-4 into a single p-4. [1]
- Compare the generated CSS before and after each merge, and skip any change that would alter the stylesheet. [1]
- Commit the cleaned files and run the build again. Make the job fail when unused classes remain. [1]
- Record a baseline of current findings so only new ones fail the job on later runs. [1]
- Add the cleaning step as a GitHub Action so pull requests show inline warnings about unused classes. [1]
- Review the final diff before merging and confirm the library still renders as expected.
Tools that can do it
NormWind is made by the team that publishes this site. NormWind works with Tailwind CSS v4 projects and prints its output as text, JSON, or SARIF 2.1.0 for GitHub code scanning. [1] [1] It runs as a GitHub Action that annotates pull requests inline. [1] The tool works in CI on Ubuntu, Windows, and macOS. [1] Installation is a single npm command as a dev dependency, or a one-off run with npx. [1] NormWind is free with no paid tier. [1] It is released under an MIT licence. [1]
Other tools may offer different ways to remove unused classes. Check how each one reads content files, handles dynamically built class names, reports findings, and runs on the CI systems the team uses before choosing.
Other tools may offer different ways to remove unused classes. Check how each one reads content files, handles dynamically built class names, reports findings, and runs on the CI systems the team uses before choosing.
Common mistakes to avoid
Running the audit without a dry run first can rewrite files that hold dynamic class names. Always verify the change list before applying fixes. Skipping the render safety check can leave a stylesheet that no longer matches the original, breaking component styles. [1] Ignoring baseline recording can make CI fail on classes that were accepted earlier, producing noisy failures. [1] Waiting to update the list of content files after moving code can leave unused classes unnoticed. Treating every unused class as safe to delete can remove classes that appear only in documentation examples. Test the library build after any removal so the published styles stay correct.
Frequently asked questions
How can component library authors safely remove unused utility classes from a build?
Authors can run a dry-run audit to see which classes are unused, apply autofix to rewrite supported files, and use a render safety check to confirm the generated CSS does not change unexpectedly. CI exit codes and baseline tracking keep the process repeatable, so a build only fails when a genuinely new unused class appears.
What is the benefit of shorthand auditing for Tailwind classes?
Shorthand auditing combines paired utilities such as px-4 py-4 into a single p-4 that means the same thing. This makes the component code easier to read without changing how the element looks on the page. [1]
How should classes built at runtime be handled during removal?
Classes that are assembled from strings or variables at runtime can look unused in a static scan even though the page needs them. A dry-run report should be scanned for these before autofix is applied. Check whether the tool being used can exclude these classes so the build is not broken.
Can the removal step fail a continuous integration job?
Yes. An audit can exit with a failing code when it finds unused classes, so the job stops and the pull request is reviewed. Recording a baseline of current per-file counts lets later runs fail only for new findings instead of all old ones.
Is NormWind free for component library authors?
NormWind is free with no paid tier. [1] It installs from npm as a dev dependency or runs with npx. [1]
NormWind is free with no paid tier. [1]
Try NormWindSources
Related comparisons
- How to add a background worker to a dev cluster
- Comparing array library speed on real data for quant analysts
- How to compare two languages in 2026
- How to compare syntax between languages in 2026
- How to copy a working code snippet to try immediately
- How to enforce consistent class order in PRs for CI maintainers
- Fail the build on duplicate Tailwind classes for CI in 2026
- How to find loop syntax fast for language hoppers in 2026
- How to free a port that is already in use in 2026
- How to let users upload a contacts CSV into a CRM