Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(css): add :open page #37689

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions files/en-us/web/css/_colon_open/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
title: ":open"
slug: Web/CSS/:open
page-type: css-pseudo-class
browser-compat: css.selectors.open
---

{{CSSRef}}

The **`:open`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) selects elements in the open state. It works only on elements that have both open and closed states. It matches {{HTMLElement("details")}} and {{HTMLElement("dialog")}} when they are in their open state, and matches {{HTMLElement("select")}} and {{HTMLElement("input")}} when they are in modes which have a picker and the picker is showing.

## Syntax

```css
:open {
/* ... */
}
```

## Examples

This example demonstrates some of the HTML elements that have an open state.

### CSS

```css
details:open > summary {
background-color: pink;
}

:is(select, input):open {
background-color: pink;
OnkarRuikar marked this conversation as resolved.
Show resolved Hide resolved
}
```

```css hidden
@supports not selector(:open) {
body::before {
content: "Your browser doesn't support :open selector.";
background-color: wheat;
display: block;
width: 100%;
text-align: center;
}

body > * {
display: none;
}
}
```

### HTML

```html
<details>
<summary>Details</summary>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In pulvinar dapibus
lacus, sit amet finibus lectus mollis eu. Nullam quis orci dictum, porta lacus
et, cursus nunc. Aenean pulvinar imperdiet neque fermentum facilisis. Nulla
facilisi. Curabitur vitae sapien ut nunc pulvinar semper vitae vitae nisi.
</details>
<hr />

<label for="pet-select">Choose a pet:</label>
<select id="pet-select">
<option value="dog">Dog</option>
<option value="cat">Cat</option>
<option value="hamster">Hamster</option>
</select>
<hr />

<label for="start">Start date:</label>
<input type="date" id="start" />
```

### Result

{{EmbedLiveSample("Examples", 300, 200)}}

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{Cssxref(":modal")}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there examples somewhere of dialog[open] or details[open] that we can link to as a "fallback"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loading