Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Pseudo-elements

The ::details-content pseudo-element

Reference for the CSS ::details-content pseudo-element: style and animate the hidden content area of a details element, with live examples and support notes.

The ::details-content pseudo-element represents the content area of a <details> element: everything except the <summary>. Before it existed, you could only style the children one by one, because the browser wrapped them in an anonymous box that CSS could not reach.

With ::details-content you can give the whole panel a background, padding or border, and you can animate it open and closed, which was the main reason people asked for it.

CSS
details::details-content {
  background: #f1f5f9;
  padding: 0.5rem 1rem;
}

Try it

Style the details panel

Syntax

CSS
details::details-content { /* declarations */ }
  • Applies to: <details> elements (the pseudo-element is a child of the element's box, after the summary).
  • Properties: it behaves like a normal box, so box-model, background, border, display and content-visibility all work. Because it is the box that gets hidden when the details are closed, content-visibility and display are the properties that control whether it shows.
  • Specificity: counts as one pseudo-element, like ::before.

Values

Syntax and arguments Description
details::details-content The content area of every details element.
details[open]::details-content The content area while the element is open.
details:not([open])::details-content The content area while closed (usually hidden).
.faq::details-content The content area of details elements with a class.

Usage notes

  • Animating open and close. Pair ::details-content with transition on content-visibility (with transition-behavior: allow-discrete) and on block-size using interpolate-size: allow-keywords. This gives a smooth accordion without JavaScript, in browsers that support all three pieces.
  • Style the content area, not the summary. The <summary> stays outside the pseudo-element; style it with the normal element selector.
  • Padding goes here. If you pad each child separately, the panel looks uneven when children have margins. One padding on ::details-content is simpler.
  • Do not hide it with display: none manually. The browser already hides it when the element is closed; overriding display or content-visibility can make closed content visible by mistake and breaks find-in-page behavior.
  • Fallbacks. A browser without support ignores the whole rule, so the details element still works, just unstyled in that part. Design the page so that nothing essential depends on the pseudo-element.
  • Grouped accordions. Giving several details elements the same name attribute makes them exclusive; ::details-content styling applies to each one.

Browser support

Newer feature: supported in Chromium-based browsers (Chrome and Edge 131 and later); other engines were still catching up, so check current support tables and treat it as progressive enhancement.