::details-content: style expandable content without wrapper divs

The ::details-content pseudo-element lets you style the expandable content of details elements separately from the summary, no divs needed.

Trevor I. Lasn Trevor I. Lasn
· 2 min read
Founder & CEO of 0xinsider.com — the Bloomberg terminal for prediction markets.

The ::details-content pseudo-element solves a problem that existed since <details> was introduced: you couldn’t style the content area without wrapping it in a div.

The problem: you want the summary and content to look different, so you’d need to add a wrapper div just for styling:

<!-- The old way: wrapper required for styling -->
<details>
<summary>How do I return an order?</summary>
<div class="content-wrapper">
<p>
Visit your order page and click "Return Item". You'll receive a prepaid
shipping label via email within 24 hours.
</p>
</div>
</details>
details::summary {
padding: 1rem;
background: white;
}
.content-wrapper {
padding: 1rem;
background: #f9fafb;
border-top: 1px solid #e5e7eb;
}

Now with ::details-content, forget the wrapper:

<!-- Clean HTML, no wrapper needed -->
<details>
<summary>How do I return an order?</summary>
<p>
Visit your order page and click "Return Item". You'll receive a prepaid
shipping label via email within 24 hours.
</p>
</details>
details::summary {
padding: 1rem;
background: white;
}
details::details-content {
padding: 1rem;
background: #f9fafb;
border-top: 1px solid #e5e7eb;
}

Here’s what that looks like in action:

How do I return an order?

Visit your order page and click "Return Item". You'll receive a prepaid shipping label via email within 24 hours. Ship the item back in original condition.

What's your return window?

We accept returns within 30 days of purchase. Items must be unused, in original packaging, and have the original receipt or proof of purchase.

Do you offer refunds or exchanges?

You can choose between a full refund or an exchange for a different size or color. Refunds are processed within 5-7 business days after we receive your return.

What if my item arrives damaged?

Contact our support team immediately with photos of the damage. We'll send a replacement at no cost or process a full refund, whichever you prefer.

You can also animate it:

details::details-content {
opacity: 0;
transition:
opacity 300ms,
content-visibility 300ms allow-discrete;
}
details[open]::details-content {
opacity: 1;
}

This fades the content in/out smoothly when opening and closing. The allow-discrete keyword lets content-visibility participate in the transition—important for performance when you have lots of content inside.

::details-content hit Baseline status in September 2025, so it works everywhere: Chrome 131+, Firefox 143+, Safari 18.4+, and Edge 131+. For older browsers, fall back to wrapper divs.

Use it for FAQs, documentation sidebars, expandable menus, pricing tiers, anything where the content needs to look different from the trigger. You get cleaner HTML, less CSS, full control over the content area, and no semantic compromises.


Trevor I. Lasn

Founder & CEO of 0xinsider.com — the Bloomberg terminal for prediction markets. Product engineer based in Tartu, Estonia, building and shipping for over a decade.


Found this article helpful? You might enjoy my free newsletter. I share dev tips and insights to help you grow your coding skills and advance your tech career.


Check out these related articles that might be useful for you. They cover similar topics and provide additional insights.

Webdev
4 min read

Optimize Your Astro Site's <head> with astro-capo

Automatically improve your Astro site's performance using astro-capo

Oct 19, 2024
Read article
Webdev
3 min read

CSS @supports: Write Future-Proof CSS

Detect CSS feature support and provide smart fallbacks with @supports

Dec 6, 2024
Read article
Webdev
5 min read

WebAssembly (Wasm): When (and When Not) to Use It

Understanding the real use cases for WebAssembly beyond the performance hype

Nov 25, 2024
Read article
Webdev
3 min read

HTML Details Element: The Native Accordion You're Not Using

Discover how the HTML details element can replace your JavaScript accordions and why it might be better than your current solution

Dec 10, 2024
Read article
Webdev
3 min read

Improve PageSpeed Insights Score with Lazy Loading Iframes

How to save bandwidth and speed up your site by lazy-loading iframes

Sep 13, 2024
Read article
Webdev
6 min read

Inside the CSS Engine: CSSOM Explained

A deep dive into how browsers parse and manipulate CSS, its impact on web performance, and why it matters

Oct 25, 2024
Read article
Webdev
4 min read

How To Implement Content Security Policy (CSP) Headers For Astro

Content Security Policy (CSP) acts like a shield against XSS attacks. These attacks are sneaky - they trick your browser into running malicious code by hiding it in content that seems trustworthy. CSP's job is to spot these tricks and shut them down, while also alerting you to any attempts it detects.

Oct 16, 2024
Read article
Webdev
4 min read

LH and RLH: The CSS Units That Make Vertical Spacing Easy

Exploring new CSS line-height units that eliminate guesswork from vertical rhythm

Dec 3, 2024
Read article
Webdev
3 min read

Preloading Responsive Images

How to properly preload responsive images to improve initial page load

Nov 28, 2024
Read article

This article was originally published on https://www.trevorlasn.com/blog/details-content-pseudo-element. It was written by a human and polished using grammar tools for clarity.