October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Build an Exclusive Accordion with Native HTML

A shared name value makes related native HTML disclosures exclusive: open one answer and another closes, without a JavaScript loop.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Want only one answer open at a time? Give related <details> elements the same name value. Click a second question and the first one closes—the browser handles the exclusive behavior without a JavaScript loop.

Make a native exclusive accordion

A <details> element creates a disclosure widget, and its required visible label is a <summary> element. To make several disclosures exclusive, repeat the same name value on each one:

As an Amazon Associate I earn from qualifying purchases.

<details name="faq">
  <summary>Can I change my plan?</summary>
  <p>Explain the answer here.</p>
</details>

<details name="faq">
  <summary>How do I contact support?</summary>
  <p>Explain the answer here.</p>
</details>

The shared name="faq" puts the disclosures in one exclusive group. Opening one closes another member. The answer belongs inside its own <details>, after the summary. For a separate accordion, use a different name, such as name="account-help".

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What the browser does—and what it does not do

Without a shared name, each <details> disclosure can open or close independently. With a shared name, the browser enforces exclusivity for group members; they do not have to sit next to one another in the source. If several members are marked open in the initial HTML, only the first in source order is rendered open.

The name property is listed by MDN as Baseline 2024, with broad availability across current browsers since September 2024. MDN’s browser milestones include Chrome 120, Safari 17.2, and Firefox 130; Firefox has enabled it by default in stable releases since version 130. This does not mean that every legacy browser supports it. If older browsers are in your support target, verify their behavior and decide whether you need a fallback.

When JavaScript is still useful

For basic “one answer open at a time” behavior, the native group replaces the script that would otherwise listen for a disclosure to open and close its siblings. A hand-written loop also needs to select the right items and remain correctly scoped as content changes or groups become nested. Those are maintenance considerations, not measured performance claims.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

JavaScript can still add behavior beyond exclusivity. For example, an application may need to save the open panel across reloads, record analytics, or open a disclosure in response to a separate control. A <details> element emits a toggle event when its open state changes, which scripts can use to respond to those changes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Need Native group Application script
Only one related panel open Use the same name on each <details>. Not needed for this behavior in browsers that support the feature.
Support for browsers without the feature Native exclusivity may not be available. May be needed if those browsers must receive the same behavior.
Persistence, analytics, or an external open control Does not provide these application-specific behaviors by itself. Use script for the additional behavior.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose groups that make sense to users

Use a shared name only when the panels genuinely belong together and opening one should close another. Keep independent topics in distinct groups; exclusivity can be inconvenient when readers need to compare or revisit multiple answers. Although group members can be nonadjacent, placing related disclosures together in the page structure can make the relationship easier to understand.

  • Write descriptive summary text so each disclosure is identifiable.
  • Keep each answer within its own <details> element.
  • Do not treat the shared name as a guarantee of accessibility; the wording and organization still matter.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.