pseudo-class

:state() — CSS reference

Matches a custom element whose ElementInternals.states set contains the named custom state. The name is not a class or an HTML attribute. Component code owns the state; use native semantics or ARIA separately as needed.

Formal Syntax & Structure

css syntaxcss
widget:state(ready) { color: teal; }

Working Example

Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>CSS reference lab</title><style>demo-state {color:#202020} demo-state:state(ready) {color:#006050}</style><body><demo-state id="a" ready>Ready</demo-state><demo-state id="b">Waiting</demo-state><script>class DemoState extends HTMLElement {constructor(){super();this.internals=this.attachInternals()} connectedCallback(){if(this.hasAttribute("ready"))this.internals.states.add("ready")}} customElements.define("demo-state",DemoState);</script></body></html>
CSS Reference