Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Css Class Collector (Purge CSS)

No security coverage Under active development 1 sites

This module automatically scans your Drupal site and collects all CSS classes used in database-driven content. It generates a list of actually used CSS classes, which is useful for CSS optimization workflows that require accurate safelists to prevent the removal of dynamic or backend-generated classes.

Remove unused CSS from your theme, without breaking the pages your editors built.

Tools like PurgeCSS shrink big CSS files (Bootstrap, Tailwind, a design system) by keeping only the classes your theme uses. They find those classes by reading your templates and JavaScript. But they cannot see the classes your editors type into content: an alert alert-info box in a body field, a Bootstrap grid in a paragraph, a button class in a custom block. Those styles get purged, and content breaks in production.

CSS Class Collector fixes that. It keeps a list of every CSS class used in your Drupal content and exports it as a CSV safelist, so those classes are always kept.

All collected classes in one place, under Reports » Collected CSS classes, ready to export.

Why use it

  • Smaller CSS, faster pages. Purge hundreds of kilobytes of unused framework CSS with confidence, and improve your Core Web Vitals.
  • No broken content. Classes that only exist in the database are on the safelist, so editors' layouts keep their styles.
  • Always up to date. Content is collected every time it is saved; you never maintain the safelist by hand.
  • Works with any purge tool. The export is a plain CSV: use it with PurgeCSS, Tailwind's safelist, or your own build step.

What it collects

  • Content: the long text fields (formatted and plain) of nodes, paragraphs and custom blocks, in every language, each time they are saved.
  • Views: the output of each view display on the front end (at most once a day per display, so pages are not slowed down).
  • Blocks rendered with markup on the front end.
  • Everything that already exists, with one click on Run full scan: all content plus every enabled view display, rendered with your front-end theme.

Admin pages are ignored, so admin theme classes stay out of the list, and classes generated for a single render (such as js-view-dom-id-…) are skipped.

Run the full scan once after installing the module, or after a content import.

How to use it

  1. Install: composer require drupal/css_class_collector and drush en css_class_collector.
  2. Give the Administer CSS Class Collector permission to your site builders.
  3. Go to Reports » Collected CSS classes and click Run full scan.
  4. Click Export CSV to download css-classes.csv.
  5. Use the CSV as the safelist of your CSS purge step.

Example: purge Bootstrap with PurgeCSS

The module includes help-file/build-css.js, an example for a Bootstrap theme (for example a bootstrap_barrio subtheme):

  1. Copy build-css.js into your theme, next to your bootstrap.min.css, and put the exported css-classes.csv next to it.
  2. Install the tools: npm install purgecss glob
  3. Run node build-css.js

It reads your Twig templates and JavaScript, keeps every class from the CSV plus a few dynamic Bootstrap patterns (col-*, btn-*, modal-*…), and writes bootstrap-purge.min.css. Load that file in your theme instead of the full Bootstrap. Adjust the paths and patterns to your theme.

Requirements

  • Drupal 10.3, 11 or 12, with Views.
  • Paragraphs and Custom Block are optional: they are scanned when they are enabled.

Questions and ideas are welcome in the issue queue.

Drupal 10–11

Ask your assistant about Css Class Collector (Purge CSS)

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

  • views Drupal core

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
8
Tracked since
Nov 2025
Latest release
6 days ago
Releases (12 mo)
6 ▲ from 2
Maintenance
Active

Release Timeline

Releases

Version Type Core PHP Release date
1.0.8 Stable 10–11 Nov 23, 2026
1.0.7 Stable 10–11 Nov 19, 2026
1.0.5 Stable 10–11 Sep 6, 2026
1.0.4 Stable 10–11 Dec 29, 2025
1.0.3 Stable 10–11 Dec 29, 2025
1.0.2 Stable 10 Dec 29, 2025
1.0.0 Stable 10 Nov 26, 2025
1.0.x-dev Dev 10 Nov 26, 2025