Sub topic 10
Progressive disclosure for secondary content
This chapter assumes you can write semantic HTML, you know basic CSS (selectors, the box model, units), and you have used browser developer tools. It also assumes you have ranked your content as described in the earlier chapter on content prioritisation. Here you will use that ranking to decide what to hide, how to hide it, and what can go wrong.
What progressive disclosure is
Progressive disclosure means showing the content most users need first and keeping the rest one deliberate action away. The user decides whether to reveal it. On a small screen this keeps the page short and scannable without deleting information.
The principle sits between two failure modes:
- Showing everything produces a very long page. Users scroll past material they did not want to find what they did.
- Removing secondary content entirely, a habit of poorly executed mobile sites, leaves users without details they sometimes need, such as returns policies or specifications.
Progressive disclosure keeps the content in the page and reduces its visual cost until someone asks for it.
Choosing what to disclose
Use your content ranking. Content falls into roughly three tiers:
- Primary content answers the main reason a visitor came. Never hide it. Examples: a product name, price and the buy button; an article's body; opening hours on a restaurant page.
- Secondary content is needed by some users some of the time. Candidates for disclosure: shipping and returns, full specifications, FAQs, legal text, long author biographies.
- Tertiary content is rarely needed. Consider whether it belongs on the page at all, or whether a link to another page is better.
A useful test is to ask what share of visitors need this content to complete their task. If most do, it is primary. If few do but those who do would be stuck without it, it is a disclosure candidate.
The native details element
The simplest accessible mechanism is the HTML details element with a summary child. It needs no JavaScript.
<details>
<summary>Shipping and returns</summary>
<p>Orders ship within two working days. Unused items can be returned within 30 days.</p>
</details>The browser provides the following without any extra code:
- The
summaryis keyboard focusable and toggles with Enter or Space. - Assistive technology announces the expanded or collapsed state.
- The
openattribute is added and removed as the user toggles, so you can style ondetails[open]. - The content is still in the DOM. Search engines can read it, and in current browsers find-in-page can search inside closed sections and open them to show a match. Support varies by browser, so check the ones you target.
Compare this with a hand-built accordion made from div elements. You would have to add button semantics, aria-expanded, aria-controls, focus handling and the toggle script yourself, and each is a place for bugs.
Styling a disclosure section for touch
A default summary is a thin line of text with a small triangle. That is a poor touch target. Apply the target-size guidance from the touch targets chapter, and make the whole row tappable:
details {
border-block-end: 1px solid #c8c8c8;
}
summary {
display: flex;
align-items: center;
justify-content: space-between;
min-block-size: 44px;
padding-inline: 1rem;
cursor: pointer;
list-style: none;
}
summary::-webkit-details-marker {
display: none;
}
summary::after {
content: "+";
font-size: 1.5rem;
}
details[open] > summary::after {
content: "\2212";
}
details > :not(summary) {
padding: 0 1rem 1rem;
}
summary:focus-visible {
outline: 3px solid #1a5fb4;
outline-offset: -3px;
}Points to notice in this stylesheet:
list-style: noneremoves the marker in modern browsers. The::-webkit-details-markerrule covers older Safari versions.- The plus and minus signs come from generated content, so they are not read as part of the heading text by most screen readers. The state is already announced by the browser.
details > :not(summary)pads every child other than the summary, so you can place paragraphs, lists or tables inside without adding wrapper elements.- Never remove the focus outline without replacing it.
:focus-visibleshows it for keyboard users and generally not for pointer taps.
Exclusive groups
Sometimes you want only one section open at a time, as in an accordion. Current browsers support the name attribute on details. Elements that share a name form a group, and opening one closes the others:
<details name="product-info" open>
<summary>Description</summary>
<p>A lightweight rain jacket with taped seams and a packable hood.</p>
</details>
<details name="product-info">
<summary>Materials and care</summary>
<p>100% recycled nylon. Machine wash cold and hang to dry.</p>
</details>
<details name="product-info">
<summary>Shipping and returns</summary>
<p>Orders ship within two working days.</p>
</details>In a browser without support for name, the sections simply behave independently. Nothing breaks, so it degrades well. Do not use exclusive groups when users may need to compare two sections side by side, such as two sets of specifications.
Mobile-first: closed on small screens, open on large ones
In a mobile-first workflow, the base state is the small screen. Secondary content starts collapsed. On a wide screen there is room, and forcing users to click to see a returns policy is needless friction.
CSS alone cannot set the open attribute, so use a short script that follows a media query. Keep the query value the same as the breakpoint used in your layout:
const wide = window.matchMedia("(min-width: 64em)");
function syncDetails(isWide) {
document.querySelectorAll("details[data-open-wide]").forEach((el) => {
el.open = isWide;
});
}
syncDetails(wide.matches);
wide.addEventListener("change", (event) => syncDetails(event.matches));<details data-open-wide>
<summary>Technical specifications</summary>
<p>Weight: 340 g. Waterproof rating: 20,000 mm.</p>
</details>Without JavaScript, the section stays closed and the user can still open it. This is progressive enhancement: the basic behaviour works everywhere, and the script improves it. One caveat: the script resets a section every time the viewport crosses the breakpoint, including when a user rotates a tablet. If that is a problem, run syncDetails only once on load.
Other disclosure patterns and when to use them
| Pattern | Best for | Main risk |
|---|---|---|
| `details` and `summary` | FAQs, specifications, policies, any labelled block | Hidden content users never find if labels are vague |
| Tabs | A small set of parallel views of the same item | Needs careful keyboard and ARIA handling; poor with many tabs on narrow screens |
| "Read more" truncation | A long block of running text | Truncated text can break mid-sentence; needs a script or CSS line clamp |
| Modal dialog | A short task that needs full attention | Interrupts the user; focus must be trapped and restored |
| Link to another page | Rarely needed, long content | Extra page load on a slow connection |
Prefer the lowest-cost pattern that works. Native details is the default choice for most secondary content.
Failure modes and gotchas
Hiding primary content. If the page's main purpose sits inside a collapsed section, the design has failed. Check your ranking: only secondary and tertiary content should be collapsed.
Vague labels. A summary reading "More" or "Details" gives users no reason to open it. Use specific labels such as "Shipping and returns" or "Battery and charging". Users scan labels the way they scan headings.
Too many sections. Ten collapsed sections in a row turn the page into a menu that users must open one at a time. If every part of a page is collapsed, the page structure is probably wrong. Group related items, or split the content onto separate pages.
Interactive controls inside the summary. A link or button inside summary competes with the toggle action and behaves inconsistently across browsers and assistive technology. Keep the summary as plain text, with at most an icon from CSS.
Headings. A summary is not a heading. If the section is a major part of the page outline, you can place a heading inside the summary, but be careful: some assistive technology flattens the summary's role. For ordinary FAQ-style sections, plain summary text is fine.
Content that matters for printing. Closed details content may not print. If the page is likely to be printed, such as a receipt or terms page, test the print output, and consider opening sections for print with a small script on the beforeprint event.
Animation. Animating the height of details is awkward because the content is not rendered when closed. If you add motion, keep it short and respect the prefers-reduced-motion media query. A plain instant toggle is acceptable and robust.
Lost state. The open state is not saved when users navigate away and come back. For long forms or checkout steps, consider whether collapsing would force users to reopen sections repeatedly.
Checking your work
Verify the following in device emulation and on a real phone:
- Each summary row is at least about 44 CSS pixels tall and tappable across its full width.
- You can open and close every section with the keyboard alone, and the focus outline is visible.
- A screen reader announces each summary with its expanded or collapsed state.
- With JavaScript disabled, every section is still reachable.
- Resizing across your breakpoint opens or closes the
data-open-widesections as intended.
Exercise
A product page has four blocks: the product name with price and buy button, a 600-word description, a table of 30 technical specifications, and a returns policy. Which blocks would you collapse on a phone, which would you show by default, and what would you label each collapsed section?
Show answer
Show the name, price and buy button by default because they are primary content that most visitors need. The description is borderline: show a short summary or its first paragraph by default and keep the rest readable, since many buyers read it. Collapse the specifications table under "Technical specifications" and the returns policy under "Shipping and returns", because only some visitors need them and both labels say exactly what is inside. On wide screens, open the specifications section by default with a media-query script, since there is room.
Exercise
Why is a native details element usually a better choice than a div-based accordion, and name one situation where the name attribute on details would be the wrong choice.
Show answer
The native element gives keyboard support, focus handling and expanded or collapsed announcements for free, and it works without JavaScript, so there is less code to get wrong. The name attribute, which makes sections exclusive, is wrong when users need to compare two sections at once, such as the specifications of two product variants, because opening one would close the other.