::details-content
Baseline
2025
Newly available
Since September 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The ::details-content CSS pseudo-element represents the expandable/collapsible contents of a <details> element.
Try it
details[open]::details-content {
color: dodgerblue;
padding: 0.5em;
border: thin solid grey;
}
<details open>
<summary>Example summary</summary>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
<p>
Architecto cupiditate ea optio modi quas sequi, esse libero asperiores
debitis eveniet commodi hic ad.
</p>
</details>
Syntax
css
selector::details-content
Examples
>Basic example
In this example the ::details-content pseudo-element is used to set a background-color on the content of the <details> element.
HTML
html
<details>
<summary>Click me</summary>
<p>Here is some content</p>
</details>
CSS
css
details::details-content {
background-color: #a29bfe;
}
Result
Transition example
In this example the ::details-content pseudo-element is used to set a transition on the content of the <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
opacityproperty is given a basic transition over600msto create the fade-in/fade-out effect. - The
content-visibilityproperty (which is toggled betweenhiddenandvisiblewhen the<details>content is expanded/collapsed) is also given a basic600mstransition, but with thetransition-behaviorvalueallow-discretespecified. This opts the browser into having a transition started oncontent-visibility, the animation behavior of which is 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
Specifications
| Specification |
|---|
| CSS Pseudo-Elements Module Level 4> # details-content-pseudo> |
Browser compatibility
Loading…