::details-content CSS pseudo-element

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

undefined

Basic example

This example demonstrates basic usage of the ::details-content pseudo-element to style the content of a <details> element.

HTML

Our <details> element includes a <summary> element, whose contents will always be visible. The details content includes a <p> element.

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

CSS

We set a background-color on the ::details-content pseudo-element:

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

Result

Click on the summary to view the detail contents.

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.

HTML

The HTML is the same as in the previous example.

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

CSS

To achieve our transition, we specify two separate transitions inside the transition shorthand property:

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

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

Result

To see the animation, toggle the visibility of the detail contents by clicking on the summary.

Specifications

See also