
UnCSS
Remove unused styles from CSS
- Free • Open Source
- Self-Hosted
- CSS
What is UnCSS?
UnCSS is a tool that removes unused CSS from your stylesheets. It works across multiple files and supports Javascript-injected CSS.
How?
The process by which UnCSS removes the unused rules is as follows:
- The HTML files are loaded by jsdom and JavaScript is executed.
- All the stylesheets are parsed by PostCSS.
- document.querySelector filters out selectors that are not found in the HTML files.
- The remaining rules are converted back to CSS.
Please note:
• UnCSS cannot be run on non-HTML pages, such as templates or PHP files. If you need to run UnCSS against your templates, you should probably generate example HTML pages from your templates, and run uncss on those generated files; or run a live local dev server, and point uncss at that. • UnCSS only runs the Javascript that is run on page load. It does not (and cannot) handle Javascript that runs on user interactions like button clicks. You must use the ignore option to preserve classes that are added by Javascript on user interaction.
UnCSS Screenshots
UnCSS information
Supported Languages
- English
GitHub repository
- 9,318 Stars
- 441 Forks
- 65 Open Issues
- Updated
Tags
- unused-css
- development
- CSS / Stylesheets
- css-development
- css3
Comments and Reviews Post a comment/review