liveBook · Manning

:is()

As explained in Tiny CSS Projects

The CSS :is() pseudo-class matches an element against any selector in a supplied selector list and takes the specificity of the most specific selector in that list.

Use :is() to group selectors when the same rule should apply if any selector in a supplied list matches. It keeps CSS concise, especially when styling several form controls. section 10.3.4

Style selected controls together

The selector :is(input[type="radio"], input[type="checkbox"]):checked targets selected radio buttons and check boxes, then changes their border to var(--accent). section 10.3.8

Keep these differences in mind:

  • :is() uses the specificity of the most specific selector inside its list. section 10.3.4
  • An ID selector inside :is() can make the resulting rule difficult to override. section 10.3.4
  • :where() groups selectors similarly but always has zero specificity, making it easier to override. section 10.3.4 section 10.3.9
input:focus, textarea:focus, select:focus, button:focus { ... }

Compare a repeated focus-selector list with the grouped form to see why selector grouping keeps related form-control styles concise. section 10.3.4

How Tiny CSS Projects covers it

How deep it goes
Explains selector-list matching and specificity, including an ID-selector warning, but does not detail selector specificity beyond the worked form example.
Examples
Uses grouped radio-button and check-box selectors, selected-state borders, and a comparison with repeated focus selectors.
What it assumes
Assumes familiarity with selectors and specificity while demonstrating the grouped syntax through radio-button and check-box styling.
What you can do after
Apply :is() to consolidate related selectors and control specificity when styling grouped form states.
How it connects
Connects :is() to :where(), :checked, :hover, :focus, pseudo-elements, and CSS specificity.

Also explained in

Compare how 2 books explain :is() →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny CSS Projects. The section links point to the parts of the book it draws on.