Skip to content
SIMON WARDMUSIC · TECHNOLOGY · CREATION
THE JOURNAL / SIMON WARD

How to Keep Only One HTML Details Panel Open at a Time

26 November 2026 · Simon Ward · 10 min read
Laptop showing three accordion rows with the middle panel expanded.

Give each details element in your accordion the same name to keep only one panel open at a time. When a reader opens another panel, the browser closes the first one. You can still close the current panel, so the group can have one open panel or none. This is useful for a compact FAQ where each answer stands on its own.

The setup takes a few lines of HTML. The checks afterwards matter just as much. In particular, copying the same group name to another part of the page can make two seemingly unrelated accordions affect each other. The example below uses a booking FAQ, followed by checks you can repeat on your own page.

1. Build the first disclosure panel

Start with one question and answer in an ordinary HTML file. Use details for the panel and put summary first inside it. The summary stays visible when the answer is collapsed and acts as the control that opens it. Write the visible question directly in the summary so a reader can work out what it contains without opening it.

Put the answer after the summary. A paragraph is enough to start with. If an answer needs a few steps, use a list inside the answer rather than cramming the instructions into the summary. You can put an ordinary link in the answer too. Click the summary in the browser and confirm that only the answer shows and hides. This gives you a working panel before you introduce grouping.

The browser normally supplies a marker beside the summary. Leave it visible while you test. It helps readers recognise that the line is interactive and provides a visible change when the panel opens. If your existing CSS removes the marker, check that the summary still looks interactive and that its expanded state is clear. Try it on a phone as well as with a mouse.

2. Give related panels the same name

Add another panel and give both the same non-empty name. The following example starts with the first answer open. Copy it into the body of a basic HTML file for a quick test. The snippets on this page display the markup as text so you can copy the angle brackets as well as the words.

<details name="booking-faq" open>
  <summary>When does booking open?</summary>
  <p>Bookings open on Monday morning.</p>
</details>

<details name="booking-faq">
  <summary>Can I change my booking?</summary>
  <p>Use the link in your booking confirmation.</p>
</details>

<details name="booking-faq">
  <summary>Where do I find my reference?</summary>
  <p>Your reference appears near the top of your confirmation email.</p>
</details>

Open the file and select the second question. The first answer should collapse and the second answer should appear. Select the second question again and all the answers should be closed. The shared name controls which panels interact. An identical class name can style several panels, but classes alone do not give them this behaviour.

The value can describe the subject or the section. Use something like booking-faq or delivery-faq. Match the spelling across every item you intend to group. If one item has a trailing space or a different value, check whether it stays open when you open another answer. The HTML Standard's details section defines how matching names form the group.

3. Choose the initial open state

Add the open attribute to one panel if there is a sensible starting answer. If you prefer readers to pick their own question, remove it from every panel. The attribute is Boolean. Writing open="false" still puts the attribute on the element, so remove it altogether when the panel should start closed.

Keep the attribute on at most one member of each group in your source. If you duplicate the default panel in your editor, remove the copied attribute before publishing. A browser may enforce the exclusivity as it processes the markup, but clean source makes it obvious which item you meant to be open.

Refresh the file after the change and check the starting state before clicking anything. Then click through the order you expect readers to use. If you need one panel to remain open even after a reader selects its summary again, this native grouping alone does not offer that behaviour. Decide whether that rule matters before designing the page around it. Most small FAQs work fine when readers can collapse everything.

4. Separate two accordions on the same page

Imagine a page with three booking questions and three parking questions. Give the booking items name="booking-faq" and the parking items name="parking-faq". Open a booking answer and then a parking answer. Both should stay open. Now open a second parking answer and confirm only the first parking answer closes.

Separate headings and wrappers help organise the page, but they do not by themselves split a group of matching names. If both sections use name="faq" in the same document tree, they can still interact even when they are far apart on the page. This is easy to miss when you copied an existing section and changed the headings but left the original names behind.

If the page comes from a template, check what happens when the same component appears twice. Give each instance its own stable group name, while keeping every panel in that instance consistent. If the component has just one independent disclosure, you can omit the group name. There is no related panel for it to close.

Do not nest a panel inside a panel with the same group name. If an answer has its own secondary disclosure, choose a different name for that inner set or leave the name off if it is independent. Look at the markup as well as the screen. Indentation in a code editor can make a nested panel easier to spot before release.

5. Test keyboard use and the narrow layout

Start above the accordion and press Tab until focus reaches the first summary. There should be a visible indication of focus. Activate the focused summary with the keyboard and confirm its answer opens. Move to the next summary and activate it. Check that the previous answer closes and the current control remains easy to find. Repeat with Shift and Tab to check backward navigation.

If an open answer contains a link, tab through it in reading order. Close the answer and repeat the sequence to make sure you can reach the next summary. Do not use CSS that removes the visible focus indicator unless you provide a clearly visible replacement. Check contrast against both the closed and open styles. Dark borders can look clear against a white background and disappear against a dark theme.

On a narrow screen, try the longest summary first. It should wrap naturally without clipping its final words or pushing the page sideways. Check the answer too, especially if it contains a long web address or a wide image. A narrow column can expose an overflow issue that was hidden when you wrote the copy. For a related example, see the guide to fixing long URLs that overflow a flex layout.

Leave enough space around the summary text for comfortable tapping. Open the bottom panel while another panel higher up is expanded. When the first answer collapses, the total height above the bottom panel can shrink, shifting the visible position. If this makes the page awkward on a phone, try shorter answers, split the questions into sections, or allow multiple panels to remain open.

6. Check what happens in older browsers

The native disclosure behaviour and the shared-name behaviour are worth checking separately. A browser can support opening and closing individual panels while letting multiple panels remain open because it does not recognise the grouping attribute. The questions and answers can still work in that situation. Test on the browsers your readers actually use if the distinction matters to your page.

For a small FAQ, having two answers open in an older browser is often acceptable. If you are creating a tightly constrained interface where the rule is essential, decide on a fallback with your browser support requirements in mind. Test both mouse and keyboard behaviour with that fallback. Avoid adding another handler that closes panels in a browser where the native behaviour already does the job unless you have a specific reason and verify the interaction.

Check the published HTML if the group works in your test file but not in your site. A content editor or template can transform a pasted snippet. Inspect the actual details elements and confirm that the name attribute survived. If it is missing or changed, review how you inserted the markup. Your editor may have its own accordion block and its own settings for whether multiple answers can be open.

If no answer toggles, check that you are looking at the live markup and that it was not escaped as a code sample. A code sample should display the tags to the reader. A working accordion should show the summaries as controls. Those are different outcomes. If you want both on a tutorial page, keep the live example and the display-only code in separate blocks and verify each after saving.

7. Decide whether exclusive opening helps readers

A compact group is useful when most people need one answer, such as the time a venue opens. For an answer that depends on another panel, closing the first makes comparison harder. If readers commonly need to compare fees, eligibility rules or specifications, try allowing panels to open independently. Remove the shared name to test how that feels before committing to the layout.

Keep information visible if readers need it before they can choose a question. An important deadline, price or next action can sit just above the group. Put optional details inside the panels where they are easier to scan. Read the collapsed summaries as a list on their own. If several are vague or almost identical, rewrite them so each describes the answer behind it.

As a final check, open the page from a fresh tab, verify the intended default, open two items in the same group in sequence and open an item in a different group. Repeat using the keyboard and a phone-width viewport. That covers the most common issues with names, initial state and layout before you repeat the component elsewhere.

8. Check a copied or repeated version before rollout

Make a second copy of the component on a test page and put it after some ordinary content. Give the copied panels a new shared name before opening either group. Open the first question in the original section, then open the last question in the copy. If both answers remain visible, you have checked the case that often gets missed when a designer tests only a single instance.

Now try the page with the browser zoom increased. Use the keyboard to reach an answer that contains a link, then return to the summary and close it. You should still be able to see which control has focus and where to continue. If the question needs several lines, let the summary grow with the text. A fixed height can cut off the end of a question, leaving readers with two controls that appear to say the same thing.

Finally, save the test file with your template or component notes. Record which attribute sets the group and which panel starts open. The next person who duplicates the section can then check the name and default state without reverse engineering the layout.

Share this post