Example Disclosure (Show/Hide) for Answers to Frequently Asked Questions
The following example demonstrates using the disclosure design pattern to create a set of frequently asked questions where the answers may be independently shown or hidden.
Similar examples include:
- Example Disclosure (Show/Hide) for an Image Description
- Example Disclosure Navigation Menu
- Example Disclosure Navigation Menu with Top-Level Links
Example
Parking FAQs
Accessibility Features
-
The semantic structure of the FAQ is conveyed with native
dl
,dt
anddd
elements. To ensure the list structure is communicated to assistive technologies, instead of applying a button role to thedt
element, abutton
element is contained within thedt
element. Similarly, eachdiv
element containing answer content that can be shown or hidden by the button is a child of add
element. Since all thedd
elements are present in the DOM even if some answers are hidden, thedl
structure is always complete. - To help people with visual impairments identify the disclosure as interactive and make it easier to perceive that clicking either the disclosure button or its label changes the expanded state, when a pointer hovers over the button or its label, the background color changes, a border appears, and the cursor changes to a pointer.
- Because transparent borders are visible on some systems with operating system high contrast settings enabled, transparency cannot be used to create a visual difference between the element that is focused an other elements. Instead of using transparency, the focused element has a thicker border and less padding. When an element receives focus, its border changes from 0 to 2 pixels and padding is reduced by 2 pixels. When an element loses focus, its border changes from 2 pixels to 0 and padding is increased by 2 pixels.
-
To ensure the inline SVG arrow graphics in the CSS have sufficient contrast with the background when high contrast settings invert colors, the color of the arrows are synchronized with the color of the text content.
For example, the color of the arrow is set to match the foreground color of high contrast mode text by specifying the CSS
currentColor
value for thestroke
andfill
properties of thepolygon
elements used to draw the arrows. If specific colors were instead used to specify thepolygon
properties, those colors would remain the same in high contrast mode, which could lead to insufficient contrast between the arrows and the background or even make the arrows invisible if the color matched the high contrast mode background.
Note: The SVG element needs to have the CSSforced-color-adjust
property set toauto
for thecurrentColor
value to be updated in high contrast mode. Some browsers do not useauto
for the default value.
Keyboard Support
Key | Function |
---|---|
Tab | Moves keyboard focus to the disclosure button. |
Space or Enter |
Activates the disclosure button, which toggles the visibility of the answer to the question. |
Role, Property, State, and Tabindex Attributes
Role | Attribute | Element | Usage |
---|---|---|---|
aria-controls="ID_REFERENCE"
|
button |
Identifies the element controlled by the disclosure button. | |
aria-expanded="false"
|
button
|
|
|
aria-expanded="true"
|
button
|
|
Javascript and CSS Source Code
- CSS: disclosure-faq.css
- Javascript: disclosureButton.js
HTML Source Code
<h3>
Parking
<abbr title="Frequently Asked Questions">
FAQ
</abbr>
s
</h3>
<dl class="faq">
<dt>
<button type="button"
aria-expanded="false"
aria-controls="faq1_desc">
What do I do if I have a permit for an assigned lot, but can't find a space there?
</button>
</dt>
<dd>
<div id="faq1_desc" class="desc">
Park at the nearest available parking meter without paying the meter
and call 999-999-9999 to report the problem. We will note and approve your alternate
location and will investigate the cause of the shortage in your assigned facility.
</div>
</dd>
<dt>
<button type="button"
aria-expanded="false"
aria-controls="faq2_desc">
What do I do if I lose my permit or if my permit is stolen?
</button>
</dt>
<dd>
<div id="faq2_desc" class="desc">
You should come to the Parking office and report the
loss. There is a fee to replace your lost permit. However, if your permit was stolen, a
copy of a police report needs to be submitted along with a stolen parking permit form for a fee replacement exemption.
</div>
</dd>
<dt>
<button type="button"
aria-expanded="false"
aria-controls="faq3_desc">
Is there free parking on holidays?
</button>
</dt>
<dd>
<div id="faq3_desc" class="desc">
All facilities are restricted from 2:00 am - 6:00 am on all days. No
exceptions are made for any holiday or recess except those officially listed as a
<q>
Holidays
</q>
in the calendar. Please note: 24-hour rental spaces, 24-hour rental lots, and
disabled parking is enforced at all times.
</div>
</dd>
<dt>
<button type="button"
aria-expanded="false"
aria-controls="faq4_desc">
Do all parking facilities have the same enforcement rules?
</button>
</dt>
<dd>
<div id="faq4_desc" class="desc">
Some parking facility restrictions differ from others. Be sure to
take note of the signs at each lot entrance.
</div>
</dd>
</dl>