#1323·purgecss

[Bug]: Selector that never matches not removed

Author: hvenevCreated Feb 5, 2025Updated Feb 9, 2025
Labelsbug

Describe the bug

A CSS selector that only uses classes/tags/ids that occur in the content, but never matches, is not removed.

Example HTML:

xml
<div class="div">div</div>
<span class="span">span</span>

CSS:

css
div.span {
	color: #f00;
}

To Reproduce

  1. Copy the HTML and CSS from the example above.
  2. Invoke purgecss
  3. Observe that it does not purge the CSS

Expected Behavior

The CSS ruleset does not match anything and should therefore be removed.

Environment

purgecss version 6.0.0

Add any other context about the problem here

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct