The HTML details element creates a disclosure: a visible summary that a visitor can activate to show or hide additional content. Use it for optional explanations, FAQ answers, and supporting technical notes when visitors can understand the page without opening every item.
A native disclosure needs little code, but it still needs release testing. A CSS reset can hide its marker, a fixed-height panel can clip its answer, and a framework handler can toggle it twice. This guide shows a small implementation and a browser test you can adapt before sharing a portfolio, documentation site, or product page.
HTML details element launch checklist
- Put a descriptive
summaryfirst inside eachdetailselement. - Keep essential instructions and the primary action visible outside collapsed content.
- Let the browser manage expansion unless your task requires additional behavior.
- Test the closed and open states with pointer, touch, and keyboard input.
- Verify the label and state with your supported screen-reader/browser combinations.
- Check long answers, links, narrow widths, and increased text spacing.
- Save a focused regression test and review the surrounding public page.
For the wider release review, use the accessibility checks before launch. A working disclosure is one component of that review.
Start with native details and summary markup
The summary names the disclosure. Put the answer after it, using ordinary paragraphs, lists, and links:
<details id="audit-scope" class="faq-item">
<summary>Which pages should I audit before launch?</summary>
<div class="faq-answer">
<p>
Start with the public landing page, then check the routes
needed to complete your main visitor task.
</p>
<a href="/launch-checklist">Read the launch checklist</a>
</div>
</details>
The HTML Standard's details definition describes a summary followed by additional information or controls. Its native disclosure behavior lets this example open without a JavaScript click listener.
Use a real question or a useful topic as the summary. Repeating “More” across six disclosures makes visitors open each one to discover its purpose. The accessible name guide explains why visible labels should communicate the action or destination.
Keep this simple summary as plain text. Place answer links inside the revealed panel rather than inside the trigger, where separate navigation and expansion actions can be confusing. Avoid adding role="button", tabindex, or a manually maintained aria-expanded to this native example. Extra state code creates another value that can drift from the actual open state.
A custom disclosure button is a different implementation. The W3C disclosure pattern describes the button role and synchronized aria-expanded state for that approach. Choose it when the required interaction cannot be expressed with native details, and implement its full keyboard and state behavior.
Set the details open attribute correctly
A disclosure starts closed when open is absent. Add open to show its content initially:
<details open>
<summary>Supported deployment environments</summary>
<p>This example accepts a public HTTPS deployment.</p>
</details>
The attribute is Boolean: open="false" still means open. Remove it to close the element. In application code, set the DOM property, such as details.open = false, or let your framework render the Boolean attribute correctly. MDN's details attribute reference documents this behavior.
When a disclosure will not stay open, inspect the rendered open state and event listeners. A click handler that reverses the state can conflict with the browser's default action. Also check whether a rerender replaces the node or restores a stale initial value. Remove unnecessary toggling before adding event cancellation or timing workarounds.
For multiple FAQ items, independent disclosures let visitors compare answers. A shared name attribute can create an exclusive group where opening one closes another. The HTML Standard cautions that this can frustrate people who need several answers at once. If you choose grouping, verify its behavior in every browser you support and test the task that motivated it; do not assume exclusivity improves usability.
Style the trigger without hiding its purpose
Start by preserving the browser's disclosure marker. Add spacing, an obvious focus indicator, and enough room for a wrapped label:
.faq-item {
border: 1px solid #697586;
border-radius: 0.5rem;
margin-block: 1rem;
}
.faq-item > summary {
padding: 0.875rem 1rem;
cursor: pointer;
overflow-wrap: anywhere;
}
.faq-item > summary:focus-visible {
outline: 3px solid #005fcc;
outline-offset: 3px;
}
.faq-item[open] > summary {
border-bottom: 1px solid #697586;
}
.faq-answer {
padding: 1rem;
overflow-wrap: anywhere;
}
This example leaves summary at its native display value so the marker remains available. MDN's summary styling notes explain its default list-item presentation. A broad reset that changes it to flex or removes list markers needs a deliberate replacement indicator and open-state styling.
Inspect the result against your actual backgrounds; these sample colors are not a guarantee for every theme. Avoid a fixed answer height or overflow: hidden added solely to preserve a card shape. Open the longest real answer and confirm the next section moves down without overlap.
Repeat the check at a narrow width and with the text spacing accessibility overrides. Include a long summary and an answer containing a link. Text expansion can expose a failure that short placeholder answers conceal.
Test keyboard access and announced state
Reload the deployed route and reach the summary with Tab. Confirm the focus indicator is visible, then test expansion and collapse using Enter and Space in your supported browsers. Move into a link in the open answer, return with Shift+Tab, and close the disclosure from its summary. Continue to the next control to check that navigation remains usable.
Collapsed answer links should not remain in the sequential keyboard path. If they do, inspect CSS that overrides the native closed presentation or a custom panel left visible while its indicator says closed. Use the keyboard accessibility testing checklist to review the surrounding sequence as well.
With a screen reader, verify that the summary has a useful name, that expansion and collapse are communicated, and that the answer is available when open. Record the browser, operating system, screen reader, and version. MDN's summary accessibility warning describes differences in exposed roles across browsers, including how headings inside a summary can lose their heading semantics. A plain-text summary avoids relying on those nested heading semantics, but still needs testing.
Essential error messages, required form instructions, and information needed to choose the main action should remain easy to discover. If visitors must open every item to understand the page, reconsider whether those sections should be collapsed.
If a custom disclosure triggers an axe finding, follow the aria-valid-attr-value troubleshooting guide to check its expanded state and panel reference.
Add HTML details element testing to Playwright
Use the markup above on an owned fixture or replace the route, ID, and expected link with your deployed component. This test checks both activation keys and a short focus path:
import { test, expect } from '@playwright/test';
test('FAQ disclosure opens, exposes its link, and closes', async ({ page }) => {
await page.goto('https://your-site.example/faq');
const details = page.locator('#audit-scope');
const summary = details.locator('summary');
const answerLink = details.getByRole('link', {
name: 'Read the launch checklist',
includeHidden: true,
});
await expect(summary).toHaveText(
'Which pages should I audit before launch?'
);
await expect(details).not.toHaveAttribute('open');
await expect(answerLink).toBeHidden();
await summary.press('Enter');
await expect(details).toHaveAttribute('open', '');
await expect(answerLink).toBeVisible();
await page.keyboard.press('Tab');
await expect(answerLink).toBeFocused();
await page.keyboard.press('Shift+Tab');
await expect(summary).toBeFocused();
await page.keyboard.press('Space');
await expect(details).not.toHaveAttribute('open');
await expect(answerLink).toBeHidden();
});
Playwright's locator press method focuses the matched element before sending a key. That makes this a component activation test; it does not prove the summary is reachable through the full page's Tab sequence. Keep that manual pass, or add a separate assertion from a stable preceding control.
Run the test in your configured Chromium, Firefox, and WebKit projects when those match your support policy. Add a pointer activation check and a case for any exclusive group you ship. Keep the test with your website regression testing checks, and retain manual evidence for focus appearance, spoken state, and readable long content.
Check the surrounding public release with Slop Audit
Once the disclosure works, run Slop Audit on the public page to review the surrounding launch conditions. When Browser Run completes, its report includes axe accessibility findings, bounded forward-Tab observations, mobile layout checks, and viewport screenshots. Use the evidence and coverage labels to decide which issue to repair next.
Slop Audit does not currently open every details element, test both disclosure activation keys, or verify screen-reader announcements. A screenshot of the closed page cannot establish that every answer works. Keep the open-state browser checks alongside the audit report, then rescan the public route after repairs to collect fresh launch evidence.