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.
details::details-content { background: #f1f5f9; padding: 0.5rem 1rem; }
Try it
Syntax
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,
displayandcontent-visibilityall work. Because it is the box that gets hidden when the details are closed,content-visibilityanddisplayare 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-contentwithtransitiononcontent-visibility(withtransition-behavior: allow-discrete) and onblock-sizeusinginterpolate-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
paddingon::details-contentis simpler. - Do not hide it with
display: nonemanually. The browser already hides it when the element is closed; overridingdisplayorcontent-visibilitycan 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
detailselements the samenameattribute makes them exclusive;::details-contentstyling 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.
Related
::markerโ the disclosure triangle can be styled with it::before- Lesson: Pseudo-elements
- Lesson: Transitions