LESSON 17 · INTERMEDIATE4 min read

Native Interactive Disclosures: <details> and <summary>

Build zero-JavaScript interactive accordions and disclosures: <details>, <summary>, open attribute state synchronization, toggle events, and accessible disclosure patterns.

HTML5 / Living StandardFree to readModule 4 of 8
YOUR NEXT SMALL WINS

By the end, you’ll be able to…

  • Implement native collapsible widgets using <details> and <summary> without requiring custom JavaScript
  • Style the disclosure triangle marker using CSS ::marker and customize open/closed states via [open] selectors
  • Listen to native toggle events to coordinate multi-panel accordion logic and state persistence

01The Zero-JavaScript Accordion Revolution

Historically, creating an interactive FAQ accordion or expandable drawer required tens of lines of JavaScript: tracking expanded boolean state, adding click event listeners, calculating element heights, and manually synchronizing aria-expanded attributes for accessibility.

HTML5 eliminated this complexity by introducing the native disclosure widget: <details> and <summary>. When placed in an HTML document, the browser automatically provides fully accessible, keyboard-operable expand/collapse functionality with zero external script dependencies.

The <summary> element serves as the disclosure's interactive button label. Clicking the summary (or focusing it and pressing Enter or Space) toggles the open boolean attribute on the parent <details> element, seamlessly revealing or hiding all remaining children.

index.htmlHTML
<!-- Native Accessible FAQ Accordion --><details name="faq-group">    <summary>What is Coursepodia's learning philosophy?</summary>    <div class="content">        <p>Coursepodia focuses on deep, textbook-grade text-first engineering education, combining comprehensive theoretical rigor with interactive terminal simulations.</p>    </div></details><details name="faq-group">    <summary>Do I need prior programming experience?</summary>    <div class="content">        <p>Our foundational tracks are designed for absolute beginners, while our systems engineering tracks progress to advanced memory mechanics.</p>    </div></details>

02The Exclusive Accordion Feature (name Attribute)

In modern HTML (standardized in 2024 across Chrome 120+, Safari 17.2+, and Firefox), multiple <details> elements can share a common name attribute (e.g. name="faq-group").

When details elements share a name attribute, the browser automatically enforces an Exclusive Accordion pattern: opening one panel automatically closes any other open panel in that group! This previously required complex JavaScript DOM querying, now handled natively by the browser engine.

03Styling and Customizing the Disclosure Triangle

By default, browsers render a small disclosure triangle next to the <summary> text. Developers can style this using the summary::marker pseudo-element or disable it entirely with summary { list-style: none; } and summary::-webkit-details-marker { display: none; }.

To style the expanded state, use the CSS attribute selector details[open]. Additionally, <details> elements fire a native toggle event whenever their open state changes, making it effortless to log analytics or persist state to localStorage.

04Native Disclosure Characteristics

Comparing native <details> with custom JavaScript accordions:

Always prefer native <details> unless highly customized animation curves require JavaScript orchestration.

notes.txtPlain text
+-----------------------+---------------------+-----------------------------------------+| Feature               | Native <details>    | Custom JS Accordion                     |+-----------------------+---------------------+-----------------------------------------+| JavaScript Needed     | Zero KB             | 2-10 KB state management script         || Keyboard Navigation   | Native Space/Enter  | Requires manual onkeydown handlers      || Screen Reader Support | Built-in a11y role  | Requires manual aria-expanded tracking  || Find-in-Page (Ctrl+F) | Native auto-expand  | Hidden content typically inaccessible   |+-----------------------+---------------------+-----------------------------------------+

05Production Standards & Real-World Engineering Trade-Offs

From a browser engine rendering perspective, understanding how the HTML parser interacts with the critical rendering path is essential for front-end performance engineering. As the browser streams bytes from the network, it passes them through tokenization, tree construction, and layout phases. If external stylesheet links or blocking synchronous scripts interrupt the HTML tokenizer, the browser cannot proceed with layout or paint, resulting in white-screen delays that directly impair user conversion rates.

Furthermore, modern browser engines (Blink, Gecko, WebKit) enforce strict speculation rules. Preload scanners parse ahead in raw HTML byte streams to discover and fetch high-priority subresources—such as hero fonts, responsive images, and critical style sheets—long before the main DOM tree construction reaches those elements, cutting First Contentful Paint (FCP) times dramatically.

LET IT CLICK

The ideas worth keeping.

  • <details> and <summary> provide fully accessible, zero-JavaScript expandable widgets.
  • Use the name attribute on multiple <details> elements to create native exclusive accordions.
  • Closed details elements automatically open when matching user Find-in-Page searches.
TURN UNDERSTANDING INTO SOMETHING YOU CAN DO

Make it yours.

Edit the starter, press Preview, and see your page render in the browser preview. Compare with the worked solution when ready.

01

Exercise 1: Write a semantic FAQ section containing two

Write a semantic FAQ section containing two <details> elements grouped with the name attribute 'product-faq' so only one panel can be open at a time.

your_turn_1.html🌐HTML
Ctrl + ↵
Preview
Press Preview to render your page
Press Preview to render your HTML in the browser preview.
Explore a worked solution
one_possible_solution.htmlHTML
<section aria-labelledby="faq-title">    <h2 id="faq-title">Frequently Asked Questions</h2>    <details name="product-faq" open>        <summary>Is there an offline mode available?</summary>        <p>Yes, all course text and interactive notes are cached locally for offline study.</p>    </details>    <details name="product-faq">        <summary>Can I export my certificate of completion?</summary>        <p>Certificates can be exported as digitally signed PDFs upon completing the capstone project.</p>    </details></section>

Use name="product-faq" on both <details> elements to create an exclusive accordion.

02

Exercise 2: Explain how native details elements interac

Explain how native <details> elements interact with the browser's Find-in-Page (Ctrl+F / Cmd+F) search feature.

your_turn_2.html🌐HTML
Ctrl + ↵
Preview
Press Preview to render your page
Press Preview to render your HTML in the browser preview.
Explore a worked solution
one_possible_solution.htmlHTML
// Modern browser engines index text inside closed <details> elements.// When a user presses Ctrl+F and searches for a phrase located inside a collapsed <details>,// the browser automatically expands the <details> element, scrolls it into view,// and highlights the matching phrase. Custom JavaScript accordions hidden with display:none fail this.

Browsers automatically open collapsed details when search terms match inside.

A SMALL QUESTION. A USEFUL NEXT STEP.

What stayed with you?

Check the ideas while they’re fresh. Your answers stay in this page and feedback appears as you go.

A LITTLE ACTIVE RECALL0 / 3 answered
01Which HTML element serves as the visible, clickable toggle heading inside a <details> container?
02What modern HTML feature allows multiple <details> elements to act as an exclusive accordion where only one panel opens at a time?
03Which DOM event is fired when a <details> element is opened or closed?

Keep exploring.

The official references behind this lesson, when you want a second angle or the full details.

One lesson closer.

Reading is a start. Trying it yourself makes the connection.

Completion is saved in this browser. It records reading and hands-on practice progress.