coderef

:state()Baseline · Newly available

The :state() CSS pseudo-class matches custom elements based on their custom state, set through the ElementInternals.states API.

Works in the latest version of every major browser, but older devices may not support it yet. Baseline since May 17, 2024.

Browser support

DesktopChrome
1–124Not supported
125+Supportedsince May 14, 2024
Current: 155
Edge
12–124Not supported
125+Supportedsince May 17, 2024
Current: 154
Firefox
1–125Not supported
126+Supportedsince May 14, 2024
Current: 157
Safari
1–17.3Not supported
17.4+Supportedsince Mar 5, 2024
Current: 27
MobileChrome Android
18–124Not supported
125+Supportedsince May 14, 2024
Current: 155
Firefox Android
4–125Not supported
126+Supportedsince May 14, 2024
Current: 157
Safari iOS
1–17.3Not supported
17.4+Supportedsince Mar 5, 2024
Current: 27

How to use

Every current browser supports this, but it only became Baseline on May 17, 2024. Use it as a progressive enhancement, or keep a fallback if you support older devices.

Example

Full syntax and examples are on MDN: CustomStateSet.

Feature detection

JS · check before using
if ("ElementInternals" in globalThis && "states" in ElementInternals.prototype) {
  // ElementInternals.states is available
}

Sub-features

Support for each part of the feature (13). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
CustomStateSet909012617.49012617.4
CustomStateSet.@@iterator909012617.49012617.4
CustomStateSet.add909012617.49012617.4
CustomStateSet.clear909012617.49012617.4
CustomStateSet.delete909012617.49012617.4
CustomStateSet.entries909012617.49012617.4
CustomStateSet.forEach909012617.49012617.4
CustomStateSet.has909012617.49012617.4
CustomStateSet.keys909012617.49012617.4
CustomStateSet.size909012617.49012617.4
CustomStateSet.values909012617.49012617.4
ElementInternals.states909012617.49012617.4
state12512512617.412512617.4