::details-content CSS Pseudo Element
Description
The ::details-content pseudo-element represents the expandable content area inside a <details> element, excluding the <summary> itself. It allows authors to directly style the portion of a disclosure widget that becomes visible when the element is opened, without needing to wrap the content in extra containers. This pseudo-element is especially useful for controlling spacing, animations, backgrounds, and transitions tied specifically to the revealed content rather than the toggle header.
The ::details-content pseudo-element is intrinsically linked to the HTML details element and reacts to its open or closed state. When the <details> element is collapsed, the content targeted by ::details-content is not rendered visually; when expanded, it becomes part of the layout flow. This allows developers to style open-state behaviors such as padding expansion, opacity changes, or animated reveals without affecting the <summary> element. It also integrates cleanly with the built-in accessibility and interaction model of <details>, making it preferable to custom JavaScript toggles in many cases.
One of the most powerful uses of ::details-content is in animation and transitions. By combining it with properties like transition, opacity, and height, you can create smooth open and close effects that feel native and performant. Unlike older techniques that required wrapper elements or JavaScript height calculations, this pseudo-element gives direct styling access to the revealable region itself. It also works well with logical properties such as padding-block, which helps maintain writing-mode flexibility.
Example: Styling expandable content
<details>
<summary>More information</summary>
<p>This content is revealed when the details element is opened.</p>
</details>
details::details-content {
padding: 1rem;
background: #f5f7fa;
border-radius: 6px;
transition: opacity 0.3s ease;
}
details[open]::details-content {
opacity: 1;
}
In this example, the ::details-content pseudo-element applies spacing and visual styling only to the expandable section, keeping the <summary> visually separate and interactive. This results in cleaner markup, better accessibility, and more predictable styling behavior compared to older disclosure-pattern techniques.
Syntax
selector::details-content
Example
Browser Support
The following information will show you the current browser support for the CSS ::details-content pseudo element. Hover over a browser icon to see the version that first introduced support for this CSS psuedo element.
This psuedo element is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 31st December 2025
