# uncss/uncss

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/uncss-uncss).**

9,408 stars · 405 forks · JavaScript · MIT

## Links

- GitHub: https://github.com/uncss/uncss
- awesome-repositories: https://awesome-repositories.com/repository/uncss-uncss.md

## Topics

`build-tool` `cleanup` `css` `javascript` `postcss` `stylesheets` `uncss` `unusedcss`

## Description

Uncss is a build pipeline CSS optimizer and optimization tool designed to remove unused styles from stylesheets. It analyzes HTML files to identify and strip selectors that do not match any elements in the markup, reducing the final stylesheet size and overall web page weight.

The tool functions as a DOM-based CSS analyzer that can simulate runtime document states. It provides mechanisms to preserve required selectors through the use of literal names, regular expressions, and specialized CSS comment markers to ensure styles triggered by user interactions are not deleted.

The project supports integration with build systems and task runners to automate the removal of dead CSS during the compilation process. It further enables the execution of custom JavaScript pre-processing scripts to modify the document state before analysis.

## Tags

### Web Development

- [CSS Unused Style Removers](https://awesome-repositories.com/f/web-development/css-unused-style-removers.md) — Provides a system to analyze the DOM and strip unused CSS selectors to reduce stylesheet size.
- [CSS Build Tools](https://awesome-repositories.com/f/web-development/web-infrastructure-deployment/asset-management-build-tools/style-optimization-tools/css-build-tools.md) — Acts as a build-time engine that scans source files to remove unused CSS styles.
- [Frontend Performance Optimization](https://awesome-repositories.com/f/web-development/frontend-performance-optimization.md) — Reduces CSS file size to improve page load times and browser rendering.
- [CSS Purging](https://awesome-repositories.com/f/web-development/web-infrastructure-deployment/asset-management-build-tools/style-optimization-tools/css-purging.md) — Identifies and removes unused CSS rules from stylesheets to reduce overall file size. ([source](https://github.com/uncss/uncss#readme))
- [Pre-Load Injections](https://awesome-repositories.com/f/web-development/custom-page-frameworks/page-content-injections/script-injections/pre-load-injections.md) — Executes custom JavaScript before analysis to simulate runtime DOM changes for more accurate results. ([source](https://github.com/uncss/uncss/blob/master/README.md))

### Part of an Awesome List

- [CSS Optimization](https://awesome-repositories.com/f/awesome-lists/devtools/css-optimization.md) — Provides a utility for purging unused CSS styles to optimize stylesheet size.

### Testing & Quality Assurance

- [CSS Payload Reduction](https://awesome-repositories.com/f/testing-quality-assurance/page-weight-analysis/css-payload-reduction.md) — Analyzes HTML markup to delete redundant CSS rules, ensuring only essential styles are delivered.

### User Interface & Experience

- [DOM Element Selectors](https://awesome-repositories.com/f/user-interface-experience/dom-element-selectors.md) — Matches CSS selectors against a parsed HTML document object model to determine which rules are actually applied.
- [Stylesheet Management](https://awesome-repositories.com/f/user-interface-experience/stylesheet-management.md) — Manages large stylesheets by stripping unnecessary rules while protecting essential selectors.
- [Unused Style Removal](https://awesome-repositories.com/f/user-interface-experience/ui-styling/high-performance-styling/unused-style-removal.md) — Analyzes HTML files to identify and delete styles from CSS stylesheets that are not used in the markup. ([source](https://github.com/uncss/uncss/blob/master/package-lock.json))
- [Interactive Selector Bindings](https://awesome-repositories.com/f/user-interface-experience/css-selectors/interactive-selector-bindings.md) — Preserves specific CSS selectors to ensure styles triggered by user interactions are not deleted. ([source](https://github.com/uncss/uncss#readme))
- [Preservation Lists](https://awesome-repositories.com/f/user-interface-experience/css-selectors/preservation-lists.md) — Prevents the removal of specific CSS rules using a list of selectors, regular expressions, or comments. ([source](https://github.com/uncss/uncss/blob/master/README.md))
- [Regex-Based Protection](https://awesome-repositories.com/f/user-interface-experience/style-selectors/regex-based-protection.md) — Prevents the deletion of specific styles by matching selector names against user-defined regular expressions.

### Development Tools & Productivity

- [Build System Integrations](https://awesome-repositories.com/f/development-tools-productivity/build-system-integrations.md) — Integrates with JavaScript build tools and style processors to remove unused CSS rules. ([source](https://github.com/uncss/uncss#readme))
- [CSS Rule Preservation Markers](https://awesome-repositories.com/f/development-tools-productivity/string-literal-handling/string-aware-comment-filtering/comment-preservation-filters/css-rule-preservation-markers.md) — Implements specialized CSS comment markers to flag style blocks that must be kept regardless of analysis.
- [Build Pipeline Integrations](https://awesome-repositories.com/f/development-tools-productivity/workflow-automation-tools/build-task-automation/build-pipeline-integrations.md) — Automates the cleanup of unused stylesheets during the compilation process using build tools.
- [Build Pipeline Integrators](https://awesome-repositories.com/f/development-tools-productivity/workflow-automation-tools/build-task-automation/build-pipeline-integrations/build-pipeline-integrators.md) — Connects task runners and style processors to automatically clean up unused CSS during the build process. ([source](https://github.com/uncss/uncss/blob/master/README.md))

### Programming Languages & Runtimes

- [DOM State Simulation](https://awesome-repositories.com/f/programming-languages-runtimes/runtime-environment-simulations/dom-state-simulation.md) — Executes custom JavaScript scripts to modify the document state to account for dynamic class additions.

### Software Engineering & Architecture

- [Abstract Syntax Tree Parsing](https://awesome-repositories.com/f/software-engineering-architecture/abstract-syntax-tree-parsing.md) — Uses abstract syntax tree parsing to deconstruct stylesheets for rule removal without breaking CSS syntax.
- [Asset Optimization Pipelines](https://awesome-repositories.com/f/software-engineering-architecture/asset-optimization-pipelines.md) — Operates as a middleware step in build tools to strip unused styles after compilation.
