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

Add ::details-content page #37118

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
93 changes: 93 additions & 0 deletions files/en-us/web/css/_doublecolon_details-content/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
title: "::details-content"
slug: Web/CSS/::details-content
page-type: css-pseudo-element
browser-compat: css.selectors.details-content
---

{{CSSRef}}

The **`::details-content`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) represents the expandable/collapsible contents of a {{HTMLElement("details")}} element.

[//]: # '{{EmbedInteractiveExample("pages/tabbed/pseudo-element-details-content.html", "tabbed-shorter")}}'

## Syntax

```css
selector::details-content
```

## Examples

### Basic example

In this example the `::details-content` pseudo-element is used to set a {{cssxref("background-color")}} on the content of the {{HTMLElement("details")}} element.

#### HTML

```html
<details>
<summary>Click me</summary>
<p>Here is some content</p>
</details>
```

#### CSS

```css
details::details-content {
background-color: #a29bfe;
}
```

lukewarlow marked this conversation as resolved.
Show resolved Hide resolved
#### Result

{{EmbedLiveSample("Basic_example", "100%", 150)}}

### Transition example

In this example the `::details-content` pseudo-element is used to set a {{cssxref("transition")}} on the content of the {{HTMLElement("details")}} element so that it smoothly fades into view when expanded, and fades out again when collapsed. To achieve this, two separate transitions are specified inside the `transition` shorthand property:

- The {{cssxref("opacity")}} property is given a basic transition over `600ms` to create the fade-in/fade-out effect.
- The {{cssxref("content-visibility")}} property (which is toggled between `hidden` and `visible` when the `<details>` content is expanded/collapsed) is also given a basic `600ms` transition, but with the {{cssxref("transition-behavior")}} value `allow-discrete` specified. This opts the browser into having a transition started on `content-visibility`, the animation behavior of which is [discrete](/en-US/docs/Web/CSS/CSS_animated_properties#discrete). The effect is that the content is visible for the entire duration of the transition, allowing other transitions to be seen. If this transition was not included, the content would immediately disappear when the `<details>` content was collapsed — you wouldn't see the smooth fade-out.

#### HTML

```html
<details>
<summary>Click me</summary>
<p>Here is some content</p>
</details>
```

#### CSS

```css
details::details-content {
opacity: 0;
transition:
opacity 600ms,
content-visibility 600ms allow-discrete;
}

details[open]::details-content {
opacity: 1;
}
```

#### Result

{{EmbedLiveSample("Transition_example", "100%", 150)}}

## Specifications
lukewarlow marked this conversation as resolved.
Show resolved Hide resolved

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [`<details>`](/en-US/docs/Web/HTML/Element/details)
lukewarlow marked this conversation as resolved.
Show resolved Hide resolved
- [`<summary>`](/en-US/docs/Web/HTML/Element/summary)
Loading