Resetting list styles at the top of a stylesheet with list-style: none, padding: 0 and margin: 0 is a common habit, but it throws away useful defaults. Browsers apply these values to <ul> elements on purpose, which is what makes lists readable without any markup or styling. In Chromium the defaults look like this:

ul {
  list-style-type: disc;
  margin-block-start: 1em;
  margin-block-end: 1em;
  margin-inline-start: 0px;
  margin-inline-end: 0px;
  padding-inline-start: 40px;
}

Rather than discard those defaults globally, it is preferable to let the browser know that a default is likely unwanted whenever a class is present on the element. A scoped reset achieves that:

ul[class] {
  padding: 0;
  margin: 0;
  list-style-type: none;
}

The default styling now survives for plain lists and disappears only when the author opts in with a class.

Where the scoped reset breaks

Specificity is the catch. Suppose a classed list needs a different list-style-type:

ul[class] {
  padding: 0;
  margin: 0;
  list-style-type: none;
}

.list {
  list-style-type: square;
}

This declaration loses, because ul[class] carries more weight. The fix could be to raise the reset selector's weight as well:

ul.list {
  list-style-type: square; /* Specificity: 0, 1, 1 */
}

/* or */

.sidebar .list {
  list-style-type: square; /* Specificity: 0, 2, 0 */
}

That works, but many authors are unwilling to pay the price. Keeping element names baked into selectors conflicts with a separation of concerns, and with BEM-style conventions it is a reliable source of trouble.

Zeroing out specificity with :where()

Functional pseudo-selectors such as :is() and :where() can raise or cancel specificity. :where() in particular always contributes 0 specificity, which removes the conflict entirely:

:where(ul[class]) {
  list-style: none;
}

.list {
  list-style: square; /* Now this works like a charm! */
}

The same property lets a library ship styles that carry no specificity at all, leaving author CSS nothing to compete against. The demo lets you remove :where() and watch the difference.

CSS-Tricks star logo