In short and in plain language
Many pages have questions and answers that open. Many pages also have tabs. A tab shows one part. The other parts are hidden.
Often this only works with a mouse. It does not work with a keyboard. A screen reader then does not know if a part is open or closed.
A real button in the code is better. The button says if the part is open. You press Enter or the space bar. Then the part opens.
Hidden text should be easy to find. Then the search in the browser also finds answers that are closed. The browser opens them for you.
Tabs do not suit every kind of content. You may want to compare things. Or you have to read it all. Then open text is better.
Many product pages have tabs for description, specifications and shipping, and many service pages end with an FAQ accordion. Both are surprisingly often built as a clickable div: it opens with a mouse, but stays out of reach for the keyboard, tells the screen reader neither role nor state, and hides its answers so thoroughly that the browser's own search cannot find them. How common it is to retrofit widgets with attributes shows in the annual analysis of one million home pages: 82.7 percent (WebAIM Million 2026) use ARIA, not counting landmarks. This article shows how to build FAQ accordions and tabs that work with the keyboard, screen readers and find in page: with details and summary where that is enough, with a heading and a button where more is needed, and with hidden="until-found" for answers that should be found. It also covers what tabs need on narrow screens and when they are the wrong choice.
Key takeaways
- Every accordion header needs a real button inside a heading that carries aria-expanded set to true or false; the W3C lists a clickable div without a role as a failure of WCAG 4.1.2 (W3C, F59).
- For simple FAQs, details with summary is enough, the browser supplies focus, Enter, Space and state; the name attribute that keeps only one item open is available from Chrome 120, Firefox 130 and Safari 17.2 (MDN browser-compat-data).
- With display: none, Ctrl+F cannot find collapsed answers; hidden="until-found" makes them findable and opens them on a match, from Chrome 102, Firefox 139 (fully from 148) and Safari 26.2, still with limitations there (MDN browser-compat-data).
- Tabs consist of tablist, tab and tabpanel: only the active tab sits in the Tab sequence, left and right arrows switch tabs, and both the selection and the focus ring need a contrast of at least 3:1 (W3C, Understanding 1.4.11).
- On narrow screens, tabs wrap, scroll within their own area or turn fully into an accordion, roles included; every target needs at least 24 by 24 CSS pixels or enough spacing (W3C, WCAG 2.2).
- Tabs do not fit when content has to be compared, read in full or searched; menus, tabs and dialogs that behave unexpectedly ranked second among the problems screen reader users report (WebAIM 2024).
The clickable div and what it lacks
A div with a click handler looks like a control in the browser, but it is not one. It has no role, it cannot receive focus, Enter and Space do nothing, and the open or closed state exists only as a CSS class. Success criterion 4.1.2 Name, Role, Value requires the opposite: for all user interface components, explicitly including those generated by scripts, name and role must be programmatically determinable, states and values that users can set must be programmatically settable, and changes to them must be passed on to assistive technologies (W3C, WCAG 2.2). The W3C even documents the clickable div as a failure technique of its own: a div or span turned into a control by script without being given a role (W3C, F59).
How often roles get attached to generic elements after the fact can only be measured indirectly. The button role appears on 53 percent of desktop sites and 54 percent of mobile sites (Web Almanac 2025). The chapter authors read this as a sign that div or span elements are often repurposed as buttons, or that real button elements carry the role a second time. Home pages carry 4.8 role="button" attributes on average (WebAIM Million 2026). And home pages with ARIA had 59.1 detected errors on average, home pages without ARIA 42 (WebAIM Million 2026). That does not mean ARIA caused the errors; the pages with ARIA are also more complex. It does show that more attributes do not by themselves mean more accessibility.
For screen reader users this is not a fringe issue. In a non-representative survey with 1,539 valid responses from screen reader users (WebAIM 2024), interactive elements like menus, tabs and dialogs that do not behave as expected ranked second among the most problematic items, right behind CAPTCHAs (WebAIM 2024). The following example shows what such an accordion typically looks like in an existing site.
<!-- Not like this: looks like an accordion, but is not one -->
<div class="faq-question" onclick="this.nextElementSibling.classList.toggle('open')">
Can I change my order after placing it?
<span class="icon-chevron"></span>
</div>
<div class="faq-answer">
Yes, as long as the order has not been shipped.
</div>
<style>
.faq-answer { display: none; }
.faq-answer.open { display: block; }
</style>What is missing only becomes apparent with a keyboard and a screen reader. The question is not a Tab stop, it is read out as plain text, and whether the answer is open remains unknown. If the control holds only an arrow icon instead of the question text, a missing name comes on top: empty buttons appear on 30.6 percent of home pages (WebAIM Million 2026), more on that in the article on empty links and buttons. And display: none hides the answer so completely that the browser's search does not find it. All three gaps can be closed, with less code than the example.
The native solution: details and summary
A simple FAQ often needs no script of its own. According to the HTML standard, the details element represents a disclosure widget from which users can obtain additional information or controls (WHATWG, HTML Standard). The first summary inside it is the visible header, the rest is the content. The browser supplies the essentials: the header is reachable with Tab, Enter and Space open and close it, and the open or closed state is passed on to the operating system's accessibility interface. The element has been available in all major browsers for years (MDN browser-compat-data).
<h2 id="faq-delivery">Questions about delivery</h2>
<details name="faq-delivery">
<summary>How do I find out when my parcel arrives?</summary>
<p>Once the order ships, you receive an email with the tracking number.</p>
</details>
<details name="faq-delivery">
<summary>Can I have the order delivered to another address?</summary>
<p>Yes, you can change the delivery address in the shipping step.</p>
</details>
<style>
summary { cursor: pointer; }
summary:focus-visible { outline: 3px solid #4a2281; outline-offset: 3px; }
</style>The name attribute turns several details elements into a group in which only one can be open at a time; the standard calls this an exclusive accordion (WHATWG, HTML Standard). It is available from Chrome 120, Firefox 130 and Safari 17.2 (MDN browser-compat-data). Older browsers ignore the attribute and simply leave several items open, which harms no one. Whether the group makes sense is still worth weighing: the standard itself warns that an exclusive accordion can frustrate users who have to open many items or who want to read several answers side by side (WHATWG, HTML Standard). For an FAQ with related questions, the open variant without name is usually the better one.
Another advantage: the browser's find in page also searches closed details elements and opens the element on a match (WHATWG, HTML Standard). Chrome has done this since version 97, Firefox since 139 and with correct scrolling to the match since 148, Safari from 26.2, where the compatibility data still lists limitations when scrolling to the match (MDN browser-compat-data). You can style the header freely as long as two things remain: a clearly visible focus ring and a sign that shows the state, such as an arrow that rotates.
details has limits in three places. First, it is explicitly meant for disclosure content only: the standard calls it incorrect to build tabs or menus with details (WHATWG, HTML Standard). Second, summary does not get a role of its own; according to the W3C, role="button" on it is unnecessary and can prevent the state from being exposed correctly (W3C, ARIA in HTML). Third, it is uncertain how assistive technologies treat a heading inside summary. HTML allows it (WHATWG, HTML Standard), but the role a summary is exposed with depends on the browser and the assistive technology (W3C, ARIA in HTML). If users should jump to the questions through their screen reader's heading list, the pattern in the next section is the more reliable choice.
When details is not enough: a heading with a button
The accordion pattern in the W3C's ARIA Authoring Practices Guide describes a structure that works reliably with assistive technologies. According to it, an accordion is a vertically stacked set of interactive headings, each representing a section of content (W3C, APG Accordion Pattern). The title of each header sits in an element with the button role, and this button is the only element inside a heading (W3C, APG Accordion Pattern). Other visible elements, such as a link next to the question, stay outside the heading. Which level the heading gets depends on where the component is placed; how to solve that in components is shown in the article on headings in components.
The button carries the state: aria-expanded="true" when the panel is visible, aria-expanded="false" when it is hidden, plus aria-controls with the panel's ID (W3C, APG Accordion Pattern). Optionally, each panel gets the region role with aria-labelledby pointing to its button. The pattern advises against this when more than approximately 6 panels can be expanded at the same time, because too many landmarks would result (W3C, APG Accordion Pattern). For a long FAQ, that means panels without region.
On the keyboard the pattern is simple. Enter or Space on a header opens or closes the panel, Tab and Shift+Tab move through all focusable elements of the accordion in the normal page order (W3C, APG Accordion Pattern). Because the header is a real button, Enter and Space work without a keyboard script of your own. The pattern does not list arrow keys, Home or End for accordions; they belong to tabs. How tab order and roving tabindex work in composite widgets in general is covered in the article on keyboard navigation.
<h2>Questions about shipping</h2>
<div class="accordion">
<h3>
<button type="button" id="faq-abroad-btn"
aria-expanded="false" aria-controls="faq-abroad">
Do you also ship abroad?
<span class="chevron" aria-hidden="true"></span>
</button>
</h3>
<div id="faq-abroad" class="accordion-panel" hidden="until-found">
<div class="accordion-body">
<p>Yes. You see the shipping costs in the cart before you order.</p>
</div>
</div>
</div>// One script for every accordion on the page
document.querySelectorAll('.accordion button[aria-controls]').forEach((button) => {
const panel = document.getElementById(button.getAttribute('aria-controls'));
const setOpen = (open) => {
button.setAttribute('aria-expanded', String(open));
if (open) panel.removeAttribute('hidden');
else panel.setAttribute('hidden', 'until-found');
};
button.addEventListener('click', () => {
setOpen(button.getAttribute('aria-expanded') !== 'true');
});
// Find in page or a fragment link opens the panel itself: sync the state
panel.addEventListener('beforematch', () => setOpen(true));
});The script sets state and visibility in one single function. That is what matters: an accordion whose aria-expanded stays at false after the click tells the screen reader the opposite of what happens on screen. This defect is harder to spot than a missing button, because mouse and eye notice nothing. What is new in the example is the interplay with find in page through hidden="until-found" and the beforematch event; that is the subject of the next section.
Hidden content and find in page
On long pages, screen reader users mostly jump through headings: 71.6 percent of respondents choose this route first to find information (WebAIM 2024). In second place comes the find feature with 13.6 percent (WebAIM 2024), and according to the survey, beginners are 2.5 times more likely to use it than advanced users (WebAIM 2024). Add to that everyone who searches with Ctrl+F without a screen reader. For an FAQ, this means the answers have to be findable through find in page, even when they are collapsed.
With display: none or the plain hidden attribute, that does not work: content in this state is not rendered (WHATWG, HTML Standard), and find in page does not find it. The value hidden="until-found" solves this. An element in this state is hidden as with hidden, but its content remains accessible to find in page and to fragment navigation (WHATWG, HTML Standard). When the search finds a match inside it, the browser fires the beforematch event, removes the attribute and scrolls to the match. The script above uses the event to keep aria-expanded in sync.
hidden="until-found" is supported from Chrome 102; Firefox has known the value since 139 and scrolls to the match correctly since 148, Safari supports it from 26.2, according to the compatibility data still with limitations when scrolling (MDN browser-compat-data). The beforematch event is available from Chrome 102, Firefox 139 and Safari 26.2 (MDN browser-compat-data). Browsers without support render the element as with display: none (WHATWG, HTML Standard). The accordion keeps working there as before, only the search does not find the collapsed answers.
The standard itself names two pitfalls. In the until-found state the element keeps its box, so borders, margin and padding are still drawn (WHATWG, HTML Standard). Spacing therefore belongs on an inner element, .accordion-body in the example. And style sheets should not change the panel's display or content-visibility (WHATWG, HTML Standard): in browsers without support, a rule such as .accordion-panel { display: block } cancels the hiding, and with display: none, inline or contents, find in page does not reveal the panel (WHATWG, HTML Standard).
/* Spacing goes inside so the collapsed panel shows no empty gap */
.accordion-panel { margin: 0; padding: 0; border: 0; }
.accordion-body { padding: 0.75rem 1rem 1rem; }
/* Do not set display on the panel, or hidden=until-found will not work as intended */
.accordion button {
display: flex;
justify-content: space-between;
width: 100%;
min-height: 2.75rem;
text-align: start;
}
.accordion button:focus-visible { outline: 3px solid #4a2281; outline-offset: 2px; }
.accordion button[aria-expanded="true"] .chevron { transform: rotate(180deg); }Building tabs right: tablist, tab and tabpanel
According to the W3C, tabs are a set of layered sections of content, of which one panel is displayed at a time (W3C, APG Tabs Pattern). HTML has no element for this, which makes it one of the patterns where ARIA is needed. The container has the tablist role, each tab the tab role, each panel the tabpanel role (W3C, APG Tabs Pattern). The active tab carries aria-selected="true", all others aria-selected="false". Each tab points to its panel with aria-controls, each panel points back to its tab with aria-labelledby, and the tablist gets a name from a visible label or aria-label (W3C, APG Tabs Pattern). A button with role="tab" works well as the tab element, because Enter and Space then trigger a click on their own. The basic markup is in the article on ARIA roles and states; this section is about operation.
The Tab key moves into the tab list and lands on the active tab; the next press of Tab leaves the list and moves into the panel (W3C, APG Tabs Pattern). Left arrow and right arrow switch between tabs, and at the end focus wraps back to the start; Home and End optionally jump to the first and last tab (W3C, APG Tabs Pattern). Technically this means: only the active tab has tabindex="0", all others have tabindex="-1", and the script moves focus. If a panel contains nothing focusable, the panel itself gets tabindex="0" so it can be reached with Tab (W3C, APG Tabs Pattern).
Whether a tab switches as soon as it receives focus or only after Enter or Space is a decision with consequences. The pattern recommends automatic activation as long as the panels are displayed without noticeable latency. If they have to be loaded first, automatic switching slows down every arrow key movement, and manual activation is then the better option (W3C, APG Tabs Pattern). The following script implements the automatic variant.
// Tabs with automatic activation (all panels are already loaded)
const tablist = document.querySelector('[role="tablist"]');
const tabs = [...tablist.querySelectorAll('[role="tab"]')];
function activate(tab) {
tabs.forEach((item) => {
const selected = item === tab;
item.setAttribute('aria-selected', String(selected));
item.tabIndex = selected ? 0 : -1;
document.getElementById(item.getAttribute('aria-controls')).hidden = !selected;
});
tab.focus();
}
tablist.addEventListener('click', (event) => {
const tab = event.target.closest('[role="tab"]');
if (tab) activate(tab);
});
tablist.addEventListener('keydown', (event) => {
const index = tabs.indexOf(document.activeElement);
const target = {
ArrowRight: index + 1,
ArrowLeft: index - 1,
Home: 0,
End: tabs.length - 1,
}[event.key];
if (index < 0 || target === undefined) return;
event.preventDefault();
activate(tabs[(target + tabs.length) % tabs.length]);
});Visible focus matters twice over with tabs, because two states have to be visible: which tab is active and which one currently has focus. Both are visual information about a state, and that needs a contrast of at least 3:1 against adjacent colors (W3C, Understanding 1.4.11). Anyone who switches off the browser's focus ring has to replace it; 67 percent of sites explicitly remove the default focus outline (Web Almanac 2025). Also, do not mark the active tab with background color alone, but additionally with a line or a different font weight. In forced colors mode the system replaces the page's colors, so a color-only marker is lost there; more on that in the article on forced colors mode.
Tabs on narrow screens
A tab list that fits comfortably on one line on the desktop bursts the width on a smartphone. Three ways out are common, and each comes with a condition.
- Wrap: The list wraps onto a second line with
flex-wrap: wrap. This is usually the most robust solution for a few short labels, as long as the active tab stays clearly marked and the relationship to the panel remains recognizable. - Scroll within its own area: The list scrolls horizontally inside its own container. Then it has to be visible that more tabs exist, for example through a partly cut-off last tab, and the focused tab has to move into view when switching with the arrow keys. The page itself must not scroll sideways; how to prevent that is covered in the article on reflow and layout breaks.
- Turn into an accordion: Below a certain width, the tabs become accordion headers. Then roles and attributes have to change completely as well: tab becomes button inside a heading, aria-selected becomes aria-expanded, and the tablist goes away. A hybrid in which elements with the tab role expand below each other is announced by the screen reader as tabs, but behaves like an accordion.
For all three approaches, every tab needs a target size of at least 24 by 24 CSS pixels or enough spacing to its neighbor (W3C, WCAG 2.2). Shorten the labels rather than shrinking the font, and do not hide tabs behind an icon without a name. If the tabs end up stacked on the smartphone anyway, the more honest solution is often to build them as an accordion or as open sections at every width. The following CSS shows the wrapping variant with a marker that does not depend on color alone.
/* Tab list that wraps on narrow screens */
[role="tablist"] {
display: flex;
flex-wrap: wrap;
gap: 0.25rem;
border-bottom: 1px solid #b0aec0;
}
[role="tab"] {
min-height: 2.75rem;
padding: 0.5rem 1rem;
border: 0;
background: none;
}
/* Active tab: line and font weight, not color alone */
[role="tab"][aria-selected="true"] {
font-weight: 700;
text-decoration: underline;
text-decoration-thickness: 3px;
text-underline-offset: 0.45em;
}
[role="tab"]:focus-visible {
outline: 3px solid #4a2281;
outline-offset: 2px;
}When tabs are the wrong choice
Tabs hide content behind a decision. That is good when users need exactly one section and the sections differ clearly. In many other cases, hiding costs more than it saves in space. Before building tabs, check whether one of the following patterns fits better.
| Situation | Better suited | Why |
|---|---|---|
| Content is meant to be compared, such as plans or specifications | Table or columns side by side | Tabs show one section at a time, comparing means switching back and forth and remembering everything |
| Everyone should read the content, such as notes on returns or safety | Open section with a heading | What sits behind the second tab is easily overlooked |
| The tabs actually lead to other pages | Navigation with links and aria-current | A page change is not tab operation, otherwise the screen reader announces arrow keys that do not apply |
| Many or long labels | Accordion or table of contents with jump links | The list wraps several times or scrolls, and the link to the panel gets lost |
| Steps of a process, such as an order or an application | Separate steps with a progress indicator | Tabs allow any order, a process does not |
| The content should be found through find in page | Accordion with hidden=until-found or open sections | Panels hidden with hidden are not found by Ctrl+F |
The third row deserves a closer look. If tabs lead to separate URLs, that is navigation and not a tablist: the current page is marked with aria-current="page", and operation runs through Tab and Enter like any link. How such navigation is built is shown in the article on accessible navigation. On product pages, the second row deserves a close look: what is said about returns, delivery time or safety belongs in an open section rather than behind the third tab.
FAQ accordions: content and structure
An FAQ accordion is only as good as its questions. Phrase each header as a complete question, the way customers ask it, not as a keyword. The question is the name of the button and at the same time the entry in the heading list; anyone navigating by headings hears only the question. Group long FAQs under topical subheadings instead of stacking everything into a single accordion, and set the headers one level below.
Three details make the difference in everyday use. First, every answer should have its own fragment identifier so that customer service, emails and internal links can point straight to it. If the fragment points to an element inside the answer, the browser opens a panel with hidden="until-found" on its own when the URL is opened (WHATWG, HTML Standard). Second, additional controls do not belong in the header: a link or a second button next to the question stays outside the heading, because the button is the only element inside it (W3C, APG Accordion Pattern). Third, an answer that everyone needs to know should not be collapsed in the first place.
For long FAQs, a button that opens and closes all answers at once helps. It has to update every aria-expanded and remove every hidden, otherwise display and announcement no longer match. If a page has several accordions, give the button a name that says which group it opens, such as "Open all shipping questions".
Testing accordions and tabs
Whether an accordion or a tab list works can be determined without special tools. The mouse stays put; the work is done with the keyboard, a screen reader and the browser's find feature.
- With Tab, every accordion header receives focus, the focus ring is clearly visible, and both Enter and Space open and close it.
- The screen reader announces the header as a button with a state, expanded or collapsed, and the state changes when it is activated.
- In the screen reader's heading list, the FAQ questions appear as headings at the appropriate level.
- Ctrl+F with a word from a collapsed answer opens the panel and shows the match; without details or hidden=until-found, the search finds nothing.
- In the tab list, only the active tab is in the Tab sequence, left and right arrows switch tabs, and Tab moves into the panel.
- At high magnification and on a smartphone, all tabs remain reachable, and every target measures at least 24 by 24 CSS pixels or has enough spacing (W3C, WCAG 2.2).
What screen readers announce exactly differs by program and browser. Test with more than one combination; what a structured test looks like is described on our page on screen reader testing. A complete WCAG audit also maps the findings to the success criteria, so you know which component fails which criterion.
What the BFSG has to do with it
Under Section 3 (1) of the German Accessibility Strengthening Act, products and services are accessible when people with disabilities can find, access and use them in the generally customary way, without particular difficulty and, in principle, without outside help (BFSG). For an online shop covered by the act, an FAQ on shipping and returns or a tab with product data is part of exactly that service; under Section 3 (3), micro-enterprises that provide services are exempt (BFSG). The act regulates the details through an ordinance, and under Section 4, offerings that comply with harmonized standards whose references are published in the Official Journal of the EU are presumed to meet the requirements, to the extent the standards cover them (BFSG).
For web content, the technical reference is a European standard that builds on the WCAG criteria; which version of it applies is described in the article on the standard behind the BFSG. Which obligations apply in detail and to whom is set out on our page on BFSG requirements. For accordions and tabs, this means in practice: implementing role, state, keyboard operation and visible focus according to WCAG 2.2 addresses the criteria an audit of these components starts from.
How we rebuild accordions and tabs
In existing websites, accordions and tabs rarely sit in just one place. They come from a component, a theme or a page builder and reappear on many product and service pages. That is exactly where the leverage lies: once the component is built right, every place it is used is, as a rule, fixed at the same time. How this carries over to an entire component system is described in the article on the accessible design system.
- Inventory: We locate every use of accordions, tabs and disclosure elements and test them with the keyboard, a screen reader and find in page.
- Pattern decision: For each use, we decide whether details is enough, whether a heading with a button is needed or whether tabs are better replaced by another pattern.
- Rebuild in the component: Roles, states, keyboard operation, hidden=until-found and focus ring are created in one place in the code, not separately in every template.
- Verification: Every use is tested again after the rebuild, and the results go into the audit report according to WCAG 2.2.
In online shops where product tabs and shipping FAQs appear on many pages, this belongs in the review of the product template; more on that on the page on the accessible shop. Teams that maintain components themselves can work through the patterns on their own code in a training session. We take on the rebuild itself as part of accessible web development, in the existing code and without rebuilding the site.
Sources
Related Articles
Focus Not Obscured: Fixing Sticky Bars for WCAG 2.4.11
Sticky headers, promo bars, chat and mini carts often hide keyboard focus. How to test WCAG 2.4.11 and fix failure F110 with scroll-padding following C43.
Accessible Tooltips: Content on Hover or Focus (1.4.13)
Success Criterion 1.4.13 asks for three things at once: dismissible, hoverable, persistent. This article takes the wording apart and shows the BITV test path.
Accessible Appointment Booking Without Barriers
Self-built date pickers fail on keyboard, focus and target size. How to make appointment booking operable under WCAG 2.2 for screen reader and keyboard users.