Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

:open — elements in the open state

The :open pseudo-class selects elements in their defined open state. Use it to style expanded details, open dialog elements, and controls with an open drop-down or picker.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

:open

:open is a pseudo-class with no arguments. It matches an element that has open and closed states while that element is currently open. It does not open anything itself. The state is semantic: hiding an element with display: none does not necessarily stop it matching.

In HTML, it matches details and dialog with an open attribute, a select operating as a drop-down box while that box is open, and an input supporting a picker while its picker is open. Not every select or input type has such a state.

Do not equate :open with [open]: the latter only tests attribute presence. A popover's showing state is separate and uses :popover-open; :open does not imply that a dialog is modal either.

The example uses details open, so its initial state needs no interaction. The details:open rule makes the border green; closing it leaves the gray border from the base rule. The example requires local verification in the target browser.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>:open example</title>
<style>
  details { border: 2px solid gray; padding: 12px; }
  details:open { border-color: green; }
</style>
<details open>
  <summary>Details</summary>
  <p>Extra content</p>
</details>
</html>

Result

Initially: expanded details with a green border. After activating Details: collapsed details with a gray border. Activating Details again restores the initial state.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources