Example Disclosure (Show/Hide) for Answers to Frequently Asked Questions
- -About This Example
-- The following example demonstrates using the Disclosure Pattern to create a set of frequently asked questions where the answers may be independently shown or hidden. -
-Similar examples include:
- -Example
-Parking FAQs
-
@@ -86,158 +44,5 @@
Accessibility Features
--
-
-
- The semantic structure of the FAQ list is conveyed with native
ulandlielements. - To ensure the list structure is communicated to assistive technologies, abuttonelement containing the question and adivelement containing answer are children of anlielement. NOTE: Thebuttonactions are used to hide and show thedivelement with the answer. -
- - 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 and 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
currentcolorvalue for thestrokeandfillproperties of thepolygonelements used to draw the arrows. - If specific colors were instead used to specify thepolygonproperties, 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-adjustproperty set toautofor thecurrentcolorvalue to be updated in high contrast mode. - Some browsers do not useautofor 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
- |
-
-
|
-
Assistive Technology Support
-Learn how to interpret and use assistive technology support data
- -JavaScript and CSS Source Code
- --
-
- - CSS: - disclosure-faq.css - -
- - JavaScript: - disclosureButton.js - -
HTML Source Code
-To copy the following HTML code, please open it in CodePen.
- -
-
-
-