UnCSS is a utility that reduces stylesheet size by removing CSS rules that are not used by the supplied HTML documents. It is particularly useful when websites incorporate extensive CSS frameworks but only use a subset of their available styles.
The software loads HTML documents using jsdom, executes associated scripts and parses stylesheets using PostCSS. It then tests CSS selectors against the document object model and generates a stylesheet containing the remaining rules. Developers must explicitly preserve selectors associated with application states that are only triggered by user interactions, since these may not be detected automatically during analysis.
This is free and open source software.
Key Features
- Analyse multiple HTML documents when determining which CSS rules are used.
- Support for local HTML files, remote web pages and raw HTML input.
- Detect CSS selectors associated with elements generated by scripts during page loading.
- Preserve specified selectors using literal names or regular expressions.
- Special comments for excluding individual rules or sections of stylesheets from removal.
- Exclude entire stylesheets from processing.
- Specify alternative stylesheets and additional raw CSS for analysis.
- Configurable media queries.
- Execute custom scripts before analysing documents.
- Configurable waiting period for script execution and page loading.
- Custom user agent for retrieving web pages.
- Command-line interface, programmatic API and PostCSS integration.
- Reusable JSON configuration files.
Website: github.com/uncss/uncss
Support:
Developer: Giacomo Martino
License: MIT License
UnCSS is written in JavaScript. Learn JavaScript with our recommended free books and free tutorials.
Related Software
| CSS Code Formatters | |
|---|---|
| Prettier | Opinionated code formatter |
| Oxfmt | Tools for JavaScript and TypeScript |
| CSScomb | Coding style formatter for CSS |
| UnCSS | Removes unused CSS from stylesheets |
| Malva | Fast formatter for CSS, SCSS, Sass and Less |
| lax | Collection of fast formatters |
| csscss | CSS redundancy analyzer |
Read our verdict in the software roundup.
LinuxLinks helps you discover the best free and open source software for Linux. Explore our extensive collection of recommended applications, including alternatives to popular proprietary software.We also publish software reviews, Linux tutorials, hardware reviews, free programming books and articles covering the wider open source community. Browse our Linux resources to discover more. Know a useful free and open source Linux application we haven't covered? Suggest a program for inclusion. Has your software been featured on LinuxLinks? Display one of our Featured on LinuxLinks badges on your website or GitHub README. |


Please read our Comment Policy before commenting.