CSS Reference ยท Pseudo-classes
The :open pseudo-class
Reference for the CSS :open pseudo-class: match details, dialog and picker elements in their open state, with a fallback pattern and a browser support warning.
The :open pseudo-class matches an element that has an open and a closed state, and is currently open. That includes <details> and <dialog>, and form controls that show a popup, such as <select> and some <input> types with pickers.
For <details> and <dialog> you can already write [open], so the extra value of :open is mostly the picker controls, which have no attribute for the state.
:open is new and does not work in every browser. Test it, and use [open] as a fallback for <details> and <dialog>.
details:open > summary { font-weight: 700; }
Try it
Syntax
:open { /* declarations */ }
No arguments; specificity (0,1,0).
Syntax and arguments
| Part | Description |
|---|---|
details:open |
A disclosure widget that is expanded. Same as details[open]. |
dialog:open |
A dialog that is showing (modal or not). |
select:open |
A select whose dropdown list is showing, where supported. |
:not(:open) |
The closed state. |
Usage notes
- Don't depend on it yet. If a browser doesn't know the selector, the whole rule is dropped. Never put
:openin a selector list with other selectors you need; write a separate rule, or use@supports selector(:open). [open]is the safe choice. For<details>and<dialog>,[open]has worked for years. Use:openwhen you need the picker controls too.- Not for popovers. A popover uses
:popover-open, not:open. - Styling a native
<select>popup also needsappearance: base-select, which is separate and also has limited support. - No script needed. The state is controlled by the browser and the user; CSS only reads it.
Browser support
Limited: supported only in newer browser versions and not yet Baseline, so check current support tables before relying on it.
Related
:popover-openโ open popovers:modalโ modal dialogs:checkedโ checked inputs- Lessons: Pseudo-classes, Feature queries