# ::details-content

> The `::details-content` CSS pseudo-element represents the expandable content of the `<details>` element.

## How do I animate opening and closing a details element?

The pseudo-element that targets the part of the `<details>` element that is shown and hidden. Allows styling and animating the content area of an accordion separately from its `<summary>`.

- Topic: Pseudo Elements
- Type: pseudo-element
- Browser support: Chrome 131+, Chrome Android 131+, Edge 131+, Firefox 143+, Firefox Android 143+, Safari 18.4+, Safari iOS 18.4+

## Example

Wrong:

```css
details .content {
  height: 0;
  transition: height 0.3s;
}
details[open] .content {
  height: auto;
}
```

Right:

```css
details::details-content {
  block-size: 0;
  overflow: hidden;
  interpolate-size: allow-keywords;
  transition: block-size 0.3s, content-visibility 0.3s allow-discrete;
}
details[open]::details-content {
  block-size: auto;
}
```

`::details-content` is the part that opens and closes, and 'allow-discrete' plus `interpolate-size` let it animate to 'auto'.

## Common mistakes

- The closing animation is skipped because `content-visibility` isn't transitioned with 'allow-discrete'.
- Trying to style the `<summary>` with `::details-content`, which covers only the content part.

## Key points

- Height animation to 'auto' with `interpolate-size` is treated as progressive enhancement, because it is not supported in every browser.
- `content-visibility` is in the `transition` list with `transition-behavior: allow-discrete`, so closing also animates.
- Motion is removed or reduced inside `@media (prefers-reduced-motion: reduce)`.

## Interview questions

### Can I animate details height without JavaScript?

Yes, with `::details-content`, `interpolate-size: allow-keywords` and a discrete transition on `content-visibility`. Where unsupported, it simply opens without animation.

### How do I make only one details element open at a time?

Give the `<details>` elements the same `name` attribute. Opening one then closes the others in the group.

## Related cards

- [`<details>`](https://wonderium.dev/html/details.md)
- [`<summary>`](https://wonderium.dev/html/summary.md)
- [:open](https://wonderium.dev/css/open.md)
- [transition](https://wonderium.dev/css/transition.md)
- [@starting-style](https://wonderium.dev/css/starting-style.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/details-content
- Last updated: 2026-11-25
