In the not-too-distant past, even fundamental accordion-like interactions needed JavaScript occasion listeners or some CSS … hoax. And, depending upon the option utilized, modifying the underlying HTML might get made complex.
Now, the << information>>
and << summary>>
components (which integrate to form what’s called a “disclosure widget”) have actually made production and upkeep of these parts fairly minor.
At my task, we utilize them for things like regularly asked concerns.

There are a number of problems to think about
Since expand-and-collapse interactivity is currently baked into the << information>>
and << summary>>
HTML tags, you can now make disclosure widgets without any JavaScript or CSS. However you still may desire some. Left unstyled, << information>>
disclosure widgets provide us with 2 problems.
Problem 1: The << summary>>
cursor
Though the << summary>>
area welcomes interaction, the component’s default cursor is a text choice icon instead of the pointing finger you might anticipate:

Problem 2: Embedded block components in << summary>>
Nesting a block-level component (e.g. a heading) inside a << summary>>
component presses that material down listed below the arrow marker, instead of keeping it inline:

The CSS Reset repair
To fix these problems, we can include the following 2 designs to the reset area of our stylesheets:
information summary {
cursor: tip;
}
information summary > > * {
display screen: inline;
}
Keep Reading for more on each concern and its particular option.
Altering the << summary>>
cursor worth
When users hover over a component on a page, we constantly desire them to see a cursor “that shows the anticipated user interaction on that component.”
We touched briefly on the reality that, although << summary>>
components are interactive (like a link or type button), its default cursor is not the pointing finger we normally see for such components. Rather, we get the text
cursor, which we generally anticipate when getting in or choosing text on a page.
To repair this, change the cursor’s worth to tip
:
information summary {
cursor: tip;
}
Some noteworthy websites currently include this home when they design << information>>
components. The MDN Web Docs page on the component itself does precisely that. GitHub likewise utilizes disclosure widgets for particular products, like the actions to enjoy, star and fork a repo.

cursor: tip
on the << summary>>
component of its disclosure widget menus. I’m thinking the default cursor: text
worth was selected to suggest that the summary text can (together with the rest of a disclosure widget’s material) be chosen by the user. However, in many cases, I feel it’s more crucial to suggest that the << summary>>
component is interactive.
Summary text is still selectable, even after we have actually altered the cursor worth from text
to tip
Keep in mind that altering the cursor just impacts look, and not its performance.
Showing embedded << summary>>
contents inline
Inside each << summary>>
area of the Frequently Asked Question entries I shared previously, I generally confine the concern in a suitable heading tag (depending upon the page summary):
<< information>>.
<< summary>>.
<< h3>> Will my kid's 504 Strategy be executed?<.
<.
<< p>> Yes. Comparable to the Spring, case supervisors will connect to trainees.<.
<
Nesting a heading inside << summary>>
can be practical for a couple of factors:
- Constant visual styling. I like my Frequently Asked Question concerns to appear like other headings on my pages.
- Utilizing headings keeps the page structure legitimate for users of Web Explorer and pre-Chromium variations of Edge, which do not support
<< information>>
components. (In these web browsers, such material is constantly noticeable, instead of interactive.) - Appropriate headings can assist users of assistive innovations browse within pages. (That stated, headings within
<< summary>>
components position a distinct case, as described in information listed below. Some screen readers translate these headings as what they are, however others do not.)
Headings vs. buttons
Bear in mind that the << summary>>
component is a little an odd duck. It runs like a button in numerous methods. In reality, it even has implicit function= button
ARIA mapping. However, quite unlike buttons, headings are enabled to be embedded straight inside << summary>>
components.
This postures us-- and web browser and assistive innovation designers-- with a contradiction:
- Headings are allowed in
<< summary>>
components to supply in-page navigational help. - Buttons remove the semantics out of anything (like headings) embedded within them.
Sadly, assistive innovations are irregular in how they have actually managed this scenario. Some screen-reading innovations, like NVDA and Apple's VoiceOver, do acknowledge headings inside << summary>>
components. JAWS, on the other hand, does not.
What this implies for us is that, when we put a heading inside a << summary>>
, we can design the heading's look. However we can not ensure our heading will really be analyzed as a heading!
Simply put, it most likely does not harmed to put a heading there. It simply might not constantly assist.
Inline all the important things
When utilizing a heading tag (or another block component) straight inside our << summary>>
, we'll most likely wish to alter its display screen
design to inline
Otherwise, we'll get some undesirable wrapping, like the expand/collapse arrow icon showed above the heading, rather of next to it.
We can utilize the following CSS to use a display screen
worth of inline
to every heading-- and to any other component embedded straight inside the << summary>>
:
information summary > > * {
display screen: inline;
}
A couple notes on this strategy. Initially, I suggest utilizing inline
, and not inline-block
, as the line covering concern still accompanies inline-block
when the heading text extends beyond one line.
2nd, instead of altering the display screen
worth of the embedded components, you may be lured to change the << summary>>
component's default display screen: list-item
worth with display screen: flex
A minimum of I was! Nevertheless, if we do this, the arrow marker will vanish. Whoops!
Bonus offer pointer: Omitting Web Explorer from your designs
I discussed previously that Web Explorer and pre-Chromium (a.k.a. EdgeHTML) variations of Edge do not support << information>>
components. So, unless we're utilizing polyfills for these web browsers, we might wish to make certain our customized disclosure widget designs aren't looked for them. Otherwise, we wind up with a scenario where all our inline styling garbles the component.

<< summary>>
headings might have odd or unwanted results in Web Explorer and EdgeHTML. Plus, the << summary>>
component is no longer interactive when this takes place, suggesting the cursor's default text
design is better than tip
If we choose that we desire our reset designs to target just the proper web browsers, we can include a function question that avoids IE and EdgeHTML from ever having our designs used. Here's how we do that utilizing @supports
to discover a function just those web browsers assistance:
@supports not (- ms-ime-align: vehicle) {
information summary {
cursor: tip;
}
information summary > > * {
display screen: inline;
}
/ * Plus any other << information>>/<< summary> > designs you desire IE to disregard.
}
IE really does not support function inquiries at all, so it will disregard whatever in the above block, which is great! EdgeHTML does assistance function inquiries, however it too will not use anything within the block, as it is the only web browser engine that supports - ms-ime-align
The primary caution here is that there are likewise a couple of older variations of Chrome (specifically 12-27) and Safari (macOS and iOS variations 6-8) that do assistance << information>>
however do not support function inquiries. Utilizing a function question implies that these web browsers, which represent about 0.06% of worldwide use (since January 2021), will not use our customized disclosure widget designs, either.
Utilizing a @supports selector( information)
block, rather of @supports not (- ms-ime-align: vehicle)
, would be a perfect option. However selector inquiries have even less web browser assistance than property-based function inquiries.
Last ideas
Once we have actually got our HTML structure set and our 2 CSS reset designs included, we can beautify all our disclosure widgets nevertheless else we like. Even some easy border and background color designs can go a long method for looks and use. Feel in one's bones that tailoring the << summary>>
markers can get a little complex!