Unused CSS is usually framed as a problem of removing stylesheets or rules that never apply. The inverse question is just as practical: which classes appear in the HTML but never in any CSS? Answering it would let you strip dead attributes from your markup.
How the detection works
A technique shared by Robert Kieffer in a Gist takes two steps. First, load document.styleSheets and collect every class rule it contains. Second, attach a MutationObserver to the DOM, walk each node's classList, and flag any class that has no counterpart in the collected stylesheet rules.

Caveats before you run it
Module timing
The script is written as an ES Module. If you merely import it into a normal HTML document, the deferred <script type="module"> means the MutationObserver never catches anything. The simplest fix is to drop the module wrapper and place the script in the <head>.
Classes used for other purposes
This is arguably a harder problem than unused CSS. A class can exist purely as a JavaScript hook. Styles can also arrive in <style> blocks, which this script never inspects. And integration tests running in CI may rely on classes for their own selectors.
Treat the output as a lead, not a verdict: use it to inspect classes you suspect are dead, but don't bulk-delete everything it reports without checking first.



