CSS :open playground

Explore :open with details, dialog, select, and picker inputs. Change the background color and switch whether the style only applies when the element is open.

Ask AI

CSS :open playground

Response generated with openai/gpt-5.4-nano. AI can make mistakes. Always review the result.
Open details

This block has the open attribute.

Closed details

Opening it also puts it in the :open state.

Open dialog

This dialog uses the open attribute.

HTML
<div class="open-demo">
  <details open>
    <summary>Open details</summary>
    <p>This block has the open attribute.</p>
  </details>

  <details>
    <summary>Closed details</summary>
    <p>This block only matches :open when it is opened.</p>
  </details>

  <dialog open>
    Open dialog with the open attribute.
  </dialog>

  <label>
    Select
    <select>
      <option>CSS :open</option>
      <option>details</option>
      <option>dialog</option>
    </select>
  </label>

  <label>
    Input date
    <input type="date" />
  </label>

  <label>
    Input color
    <input type="color" value="#2f8f6b" />
  </label>
</div>
CSS
.open-demo {
  display: grid;
  gap: 1rem;
  max-inline-size: 42rem;
}

.open-demo :where(details, dialog, select, input[type="color"], input[type="date"], input[type="datetime-local"], input[type="month"], input[type="time"], input[type="week"]) {
  padding-block: 0.75rem;
  padding-inline: 0.875rem;
  border: 1px solid color-mix(in srgb, currentColor 24%, transparent);
  border-radius: 0.75rem;
  font: inherit;
}

.open-demo :where(details, dialog, select, input[type="color"], input[type="date"], input[type="datetime-local"], input[type="month"], input[type="time"], input[type="week"]):open {
  background-color: #2f8f6b;
}