Details
Last updated
Last updated
A region of content that can be expanded and collapsed, forcing any adjacent content to be pushed down the page.
Details are often used to declutter secondary content (e.g. 'Show more'), navigation links or form options.
HTML provides a details tag by default, however it is not supported in Internet Explorer or Edge browsers.
You can take a look at the details pattern in action on our examples site.
Must be opened and closed via a summary element.
Must not be opened by a link, radio button or checkbox.
Can be closed programmatically via the open
property.
Pressing ENTER or SPACE on summary element will expand or collapse content accordingly.
Clicking or tapping the summary element will expand or collapse the content accordingly.
With virtual cursor on summary element, screen reader will announce current expanded/collapsed status.
When content is expanded, screen reader will announce new expanded state of button or summary element.
This guide explains how to "polyfill" the details tag so that it can be used in non-supported browsers. It also explains how to show a custom icon, using CSS.
Here's an example where we keep a list of "Buying Activity" related links inside of a details pattern:
Internet Explorer and Edge will have no idea what to do with the details and summary pattern, and so we will require CSS and JavaScript to fix that.
The first thing we must do, in order to fix layout, is let IE and Edge know that the details tag is a block-level element:
Next we are going to hide the browser's default icon for ALL browsers.
Then show a custom icon. Again for ALL browsers.
Here we are simply using the ::before
pseudo-selector to create unicode content, but you could also use SVG markup or a span with background image if you prefer.
The goal of the JavaScript is to polyfill the functionality of the details tag for browsers that do not support it.
We can summarise the requirements as:
Support open
property state
Ensure summary element is keyboard focusable
Ensure summary element has appropriate role
Support toggle on click
Support toggle on ENTER and SPACEBAR
Ensure that a toggle
event or custom event is triggered
Fortunately some clever individual has already gone and done that and given it the very excellent name of details-element-polyfill.