Sub topic 10
Progressive disclosure for secondary content
This chapter assumes you can write semantic HTML and basic CSS, and that you have already ranked your page content by user need. Progressive disclosure uses that ranking. The most important content is shown first. Secondary content stays one tap away.
What progressive disclosure means
Progressive disclosure is a design technique that shows only what the user needs right now and reveals the rest on request. On a small screen, vertical space is the scarce resource. A long block of shipping terms, specifications, or legal notes pushes the primary action far down the page.
The goal is not to hide content. The content stays in the page and stays reachable. It simply does not compete for attention with the content that matters most.
Deciding what to disclose
Use your content ranking from the earlier chapter. Good candidates for disclosure are:
- Details that only some users need, such as returns policy or size charts.
- Long reference material, such as full specifications.
- Answers in a FAQ, where users usually want one answer out of many.
Do not hide content that most users need to complete the main task. If nine out of ten visitors need the price, show the price.
The native details element
The details element gives you a disclosure widget with no JavaScript. The summary element is the always-visible label. Clicking or tapping it toggles the rest of the content.
<details>
<summary>Shipping and returns</summary>
<p>Orders ship within two working days. Unused items can be returned within 30 days.</p>
</details>Using the native element has practical benefits:
- Browsers make it keyboard accessible, so Enter and Space toggle it.
- Assistive technologies announce whether it is expanded or collapsed.
- It works before any script loads, which helps on slow mobile connections.
- Browser find-in-page can reach into collapsed content in current browsers that support it.
Styling the summary for touch
The summary is the control the user taps, so it needs a comfortable touch target. Apply the sizing rule from the touch targets chapter.
<details class="disclosure">
<summary>Shipping and returns</summary>
<p>Orders ship within two working days. Unused items can be returned within 30 days.</p>
</details>
<style>
.disclosure summary {
min-block-size: 44px;
display: flex;
align-items: center;
padding-inline: 1rem;
cursor: pointer;
}
.disclosure[open] summary {
font-weight: 600;
}
.disclosure p {
padding-inline: 1rem;
}
</style>The [open] attribute selector lets you style the expanded state. The browser adds the open attribute when the user expands the element.
Showing everything on larger screens
On a wide screen there is room for the content, and a collapsed panel becomes an unnecessary extra step. A common approach is to open the element by default on large viewports. You can do this in a small script, since CSS alone cannot set the open attribute.
<script>
const query = window.matchMedia("(min-width: 64em)");
function syncDisclosure() {
document.querySelectorAll("details.disclosure").forEach((el) => {
el.open = query.matches;
});
}
syncDisclosure();
query.addEventListener("change", syncDisclosure);
</script>This follows the mobile-first pattern. The base experience, collapsed panels, works without script. The script enhances the page when more space is available. Note that this resets any panel the user toggled by hand whenever the viewport crosses the breakpoint, so use it only where that is acceptable.
Common errors
- Hiding the primary action. A "Buy" button inside a collapsed panel will cost you conversions.
- Vague summaries. "More" or "Details" tells the user nothing. Name the content: "Shipping and returns".
- Tiny tap areas. A small arrow icon as the only target is hard to hit. Make the whole summary row tappable.
- Custom widgets without semantics. A
divwith a click handler lacks keyboard support and state announcements. Preferdetails. - Deep nesting. Panels inside panels make content hard to find. Keep disclosure to one level where you can.
Disclosure and the layout flow
Exercise
A product page has a price, an "Add to basket" button, a 30-line specifications table, and a returns policy. Which of these should go inside details elements on a small screen, and why should the others stay visible?
Show answer
Put the specifications table and the returns policy in details elements, each with a descriptive summary such as "Full specifications" and "Returns policy". Most visitors do not need them to decide or act, and they take a lot of vertical space. The price and the "Add to basket" button stay visible because nearly every user needs them for the main task, and hiding them would slow or block that task.