Skip to content

Cleanup unused container classes#327

Open
adrianbj wants to merge 1 commit intoprocesswire:masterfrom
adrianbj:css-cleanup
Open

Cleanup unused container classes#327
adrianbj wants to merge 1 commit intoprocesswire:masterfrom
adrianbj:css-cleanup

Conversation

@adrianbj
Copy link
Copy Markdown
Contributor

@adrianbj adrianbj commented Apr 1, 2026

Hey @ryancramerdesign - I think I mentioned not long ago that I thought the admin.css file seemed unnecessarily huge so I asked Claude to have go at removing redundant classes and it literally halved its size. I know I saw a note somewhere in your code about not minifying this file (although I'm not sure why), but at least this should be a big improvement.

I haven't tested it thoroughly, but a quick look around the admin looks good.

I asked Claude:

❯ How is it possible that you could simplify all those selectors so much without breaking anything or making them not specific enough so that they don't interfere with other page elements?

⏺ Great question. Let me show you exactly what happened with a concrete example. Take line 32 from the original file:

Before:
h1,.uk-h1,h2,.uk-h2,h3,.uk-h3,...,
.uk-section-primary:not(.uk-preserve-color) h1,
.uk-section-primary:not(.uk-preserve-color) .uk-h1,
.uk-section-secondary:not(.uk-preserve-color) h1,
.uk-tile-primary:not(.uk-preserve-color) h1,
.uk-card-primary.uk-card-body h1,
.uk-card-secondary.uk-card-body h1,
.uk-overlay-primary h1,
... {
color: var(--pw-text-color)
}

After:
h1,.uk-h1,h2,.uk-h2,h3,.uk-h3,... {
color: var(--pw-text-color)
}

The removed selectors were more specific versions of the base selectors, targeting elements inside containers like .uk-section-primary. For example, .uk-section-primary:not(.uk-preserve-color) h1 means "an h1
inside a .uk-section-primary element".

The key points:

  1. Those container classes don't exist in the PW admin markup — no PHP template ever outputs class="uk-section-primary" or class="uk-tile-secondary" etc. So those selectors never matched anything.
  2. The base selectors are preserved — h1, .uk-h1, a:hover, .uk-button, etc. all remain untouched. These are the ones that actually style the admin.
  3. The properties are identical — the removed selectors applied the exact same CSS properties as the base selectors. They existed as UIkit's way of ensuring correct colors inside colored containers — a UIkit feature the PW admin doesn't use.
  4. No specificity change for real elements — since the removed selectors targeted elements inside non-existent containers, they were never winning any specificity battles. The base selectors were always the ones doing the actual work.

So nothing got "simplified" in terms of what CSS actually applies — we just removed selectors that could never match any element in the admin.

Claude's explanation:

❯ How is it possible that you could simplify all those selectors so much without breaking anything or making them not specific enough so that they don't intefere with other page elements?

⏺ Great question. Let me show you exactly what happened with a concrete example. Take line 32 from the original file:

  Before:
  h1,.uk-h1,h2,.uk-h2,h3,.uk-h3,...,
  .uk-section-primary:not(.uk-preserve-color) h1,
  .uk-section-primary:not(.uk-preserve-color) .uk-h1,
  .uk-section-secondary:not(.uk-preserve-color) h1,
  .uk-tile-primary:not(.uk-preserve-color) h1,
  .uk-card-primary.uk-card-body h1,
  .uk-card-secondary.uk-card-body h1,
  .uk-overlay-primary h1,
  ... {
      color: var(--pw-text-color)
  }

  After:
  h1,.uk-h1,h2,.uk-h2,h3,.uk-h3,... {
      color: var(--pw-text-color)
  }

  The removed selectors were more specific versions of the base selectors, targeting elements inside containers like .uk-section-primary. For example, .uk-section-primary:not(.uk-preserve-color) h1 means "an h1
  inside a .uk-section-primary element".

  The key points:

  1. Those container classes don't exist in the PW admin markup — no PHP template ever outputs class="uk-section-primary" or class="uk-tile-secondary" etc. So those selectors never matched anything.
  2. The base selectors are preserved — h1, .uk-h1, a:hover, .uk-button, etc. all remain untouched. These are the ones that actually style the admin.
  3. The properties are identical — the removed selectors applied the exact same CSS properties as the base selectors. They existed as UIkit's way of ensuring correct colors inside colored containers — a UIkit
  feature the PW admin doesn't use.
  4. No specificity change for real elements — since the removed selectors targeted elements inside non-existent containers, they were never winning any specificity battles. The base selectors were always the
  ones doing the actual work.

  So nothing got "simplified" in terms of what CSS actually applies — we just removed selectors that could never match any element in the admin.
@ryancramerdesign
Copy link
Copy Markdown
Member

ryancramerdesign commented Apr 2, 2026 via email

@adrianbj
Copy link
Copy Markdown
Contributor Author

adrianbj commented Apr 2, 2026

Great point about supporting Uikit classes for third party modules. I wonder if there could be somehow be chunked out and only loaded if needed.

I was curious what Claude thought was the bigger gain:

❯ Does removing all these extra selectors speed rendering up or just loading of the CSS file.

⏺ Both, but to different degrees:

Loading — the bigger win. 122KB less to download, parse, and tokenize. CSS parsing is synchronous and render-blocking, so this directly reduces time-to-first-paint.

Rendering — a real but smaller win. The browser builds a data structure (the style rule map) from all selectors and checks them during style recalculation. With ~2,000 fewer selectors, the browser has a
smaller map to maintain. However, modern browsers are very efficient at this — selectors that never match are filtered out quickly by the rightmost part of the selector (e.g., the browser checks "is this an
h1?" before checking if it's inside .uk-section-primary). So the rendering speedup exists but is marginal.

The practical impact is mainly in the first category — less CSS to download and parse on every admin page load.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants