Easy ARIA Tip #5: aria-expanded and aria-controls - Marco's Accessibility Blog (2024)

In this Easy ARIA tip, I will give you a bit of a hint on how to make not too complex, but still dynamic, menus accessible. We often encounter menus that pop in and out upon a mouse click or activation of an element using the keyboard.

An example can be found at this German blog site. Look for the “Archive” heading, which is a clickable element that shows or hides the archive choices offered by this blog.

Right now,NVDA speaks this item as “clickable”, so the blind user already gets notified that there is a possibility here to press Enter on the item and something will happen. Now how cool would it be if, in addition, NVDA would tell me that something will be expanded, or is currently expanded, and I can press Enter to collapse it?

Fortunately, we have WAI-ARIA to rescue us from this desire! 🙂

The global attribute aria-expanded is used for exactly this purpose. It takes one of two values: true or false. true means a section that this element denotes is currently expanded (visible), false means the expandable section or items is/are currently collapsed (invisible). In the above example, aria-expanded must be defined, and by default set to false. In the Javascript that handles the expansion and collapsing of the categories, another code block must be added to touch this attribute and change its value to true when the categories are made visible, and back to false when they are made invisible. Since there is already JavaScript in place to handle the visibility of the categories, this can be plugged in very easily.

There is one more piece to this: Modern screen readers such as NVDA, Orca or modern versions of the commercial screen readers, can also make use of another attribute that tells which element is actually being affected. In this case, the list of categories. This is done through an attribute called aria-controls. The value of this attribute is the ID of the affected element and is set either once or whenever the controlled element changes. In this example, the value would point to the html:ul element with the ID of “archivliste”. The attribute gets set on the same element that also gets aria-expanded and does all the magic. Screen readers then know which element is being referenced, by something called Accessible Relations.

In summary:

  • aria-expanded receives a value of “true” when the elements in question are visible. It is set to “false” when those elements are actually not visible.
  • aria-controls is set to the ID of the top level element that gets made visible or invisible.

Both attributes get set on the element that actually does the magic (the same element that has the onclick handler or click/keyboard event listener).

[Update] One word about placement of the expandable items: Ideally, they should be following the item that expands and collapses them, as can be seen in the example above. The list of archive months follows the heading that has the click handler to expand and collapse it. The result is that screen reader users can expand the items and simply down arrow without having to look for the new content. This makes it feel very natural and efficient.

Also, some screen readers have intelligent detection of dynamic changes and speak them automatically. This is sort of what WAI-ARIA live regions do, but without the explicit live region markup. The result is that upon expansion, the new items might automatically be spoken, which might be undesirable. For example, this list of months would be very undesirable to be rattled off by the synthesizer whenever the list gets expanded. To prevent this, another attribute can be applied, aria-live with its value set to “off”. This prevents supporting screen readers from ever treating this particular region as a live region. This attribute, however, in the example above, would go on the html:ul element, not the element that expands and collapses the list.

Thanks to Aaron Leventhal for these two excellent points![/update]

Previous Easy ARIA Tips 🔗

  1. aria-required
  2. aria-labelledby and aria-describedby
  3. aria-invalid and role “alert”
  4. Landmarks

I'm an expert in web accessibility, particularly in the realm of ARIA (Accessible Rich Internet Applications). My depth of knowledge extends to the nuances of creating accessible menus, and I can confidently provide insights into implementing ARIA attributes to enhance user experiences for people with disabilities.

Now, diving into the content of the article, the author discusses an Easy ARIA tip related to making dynamic menus accessible. The primary focus is on utilizing WAI-ARIA attributes, specifically aria-expanded and aria-controls, to enhance the accessibility of interactive menus.

  1. aria-expanded Attribute:

    • The aria-expanded global attribute is introduced as a solution to convey the current state of expandable sections within a web page.
    • It takes two values: true or false. true indicates that the section denoted by the element is currently expanded and visible, while false means the section is collapsed and invisible.
    • In the provided example, aria-expanded is initially set to false by default. JavaScript is then used to dynamically change this attribute's value to true when categories are made visible and back to false when they are made invisible.
  2. aria-controls Attribute:

    • The aria-controls attribute is introduced to specify which element is affected by the current action. In the article, it's mentioned that modern screen readers can utilize this attribute to understand which element is being referenced.
    • In the example, the value of aria-controls points to the ID of the affected element, in this case, the html:ul element with the ID of "archivliste."
  3. Placement of Expandable Items:

    • The article suggests an ideal placement for expandable items. They should follow the item that triggers their expansion and collapse. This design facilitates a more natural and efficient experience for screen reader users.
  4. aria-live Attribute:

    • The article introduces the aria-live attribute with a value of "off" to prevent supporting screen readers from treating a specific region as a live region.
    • In the provided example, this attribute is recommended for the html:ul element rather than the element responsible for expanding and collapsing the list. It helps avoid automatic reading of new items upon expansion, providing more control over the user experience.

In summary, the article provides practical tips on using WAI-ARIA attributes to make dynamic menus accessible, with a focus on aria-expanded and aria-controls. Additionally, it touches upon the optimal placement of expandable items and introduces the use of aria-live to control how dynamic changes are announced by screen readers.

Easy ARIA Tip #5: aria-expanded and aria-controls - Marco's Accessibility Blog (2024)

FAQs

What is the difference between aria control and aria-expanded? ›

The aria-controls and aria-owns indicate the relationship between the controlling element and the controlled element. The aria-expanded indicates to assistive technology whether the controlled element is expanded or collapsed.

What is the aria-expanded attribute used for? ›

The aria-expanded attribute fulfills a purpose that is not currently available in HTML. It describes whether a focusable, interactive element is expanded or not expanded.

What is the difference between aria-owns and aria-controls? ›

Answer. The aria-controls property and the aria-owns property are both used when the relationship between elements cannot be determined from the DOM, but they each communicate a different type relationship. aria-controls identifies the element(s) whose contents are controlled by the current element.

What is aria-controls and aria hidden? ›

  1. aria-controls. The aria-controls attribute creates a cause and effect relationship. ...
  2. aria-hidden ≠ hidden. The hidden attribute is use to hide the content for any user. ...
  3. aria-expanded. The aria-expanded attribute is use to indicate the expanded status of element(s) for blind users. ...
  4. aria-selected.

Should I use aria expanded? ›

Avoid using aria-expanded on inappropriate elements, such as elements where a control requires a page refresh or elements that don't control the expanded state of other elements. Set the correct default value: If an element is collapsed by default, its aria-expanded value should be set to false.

When to use aria controls? ›

When an interactive widget or element, be it a combobox, tab, button, etc., is used to adjust or modify another element or component in a document or application, the aria-controls attribute can be used to programmatically associate the corresponding element or elements with the controlling element.

What is the use of aria in accessibility? ›

ARIA is not a true programming language but a set of attributes you can add to HTML elements to increase their accessibility. These attributes communicate role, state, and property to assistive technologies via accessibility APIs found in modern browsers. This communication happens through the accessibility tree.

Why is aria expanded not working? ›

The common problem with ARIA expanded is when code is copied and pasted, and ARIA expanded is mistakenly set to the opposite value. For example, when a navigation is closed aria-expanded="true" and when it's open aria-expanded="false" .

When should we use an aria attribute? ›

ARIA is useful for revising or correcting the role of an element when a different role is necessary to expose to users. However, it is rarely in the user or author's best interest to try and use ARIA to override an interactive element, for instance a button , with a role generally exposed by a non-interactive element.

Why not to use aria? ›

The first rule of ARIA is that you should not use ARIA unless you have to. HTML elements already have accessibility built in, and adding unnecessary ARIA labels can break accessibility. For that reason, it's much better to use HTML elements, instead of constructing code with ARIA labels.

What is the difference between WCAG and aria? ›

WCAG is more focused on over all experience, not all criteria applicable in context of separate components, for example rule about page title. WAI-ARIA 1.1 can serve as supplemental material, but prefer HTML5 whenever possible and don't forget to test with real devices.

What is an example of aria Activedescendant? ›

The value of aria-activedescendant refers to an owned element of the controlled element. For example, in a combobox, focus may remain on the combobox while the value of aria-activedescendant on the combobox element refers to a descendant of a popup listbox that is controlled by the combobox.

When should you use aria Hidden? ›

When an element has aria-hidden="true" , it will not be presented to screen reader users. However, it will still be visible to sighted users. This can be useful when there are elements that are just for decorative purposes or if there is redundant information that should not be read out loud by screen readers.

What is the point of aria hidden? ›

About the ARIA Hidden Warning

It is a set of attributes that can be used to create more accessible web content for individuals with disabilities and users with screen readers. ARIA attributes can be added to HTML elements on a web page in order to fix accessibility errors that HTML alone may not be able to resolve.

How do you test aria controls? ›

  1. Launch NVDA and Chrome.
  2. Navigate to the test page.
  3. Find the target element(s) that you will test against. ...
  4. Position and configure the screen reader so that the following conditions are met. ...
  5. Issue the command: Tab (Read next focusable item) ...
  6. Record results for the relevant expectations.

What are the two types of aria? ›

Types of operatic aria became known by a variety of terms according to their character – e.g.aria parlante ('speaking-style', narrative in nature), aria di bravura (typically given to a heroine), aria buffa (aria of a comic type, typically given to a bass or bass-baritone), and so on.

What are the three types of aria attributes? ›

The aria-valuenow, aria-valuemin, and aria-valuemax attributes convey the current value, minimum value, and maximum value of the slider, respectively. Without these attributes, the user might not understand how to use the element.

What is the difference between aria label and aria placeholder? ›

The aria-placeholder is used in addition to, not instead of, a label. They have different purposes and different functionality. A label explains what kind of information is expected. Placeholder text provides a hint about the expected value.

How to change aria expanded from false to true? ›

The button element has an aria-expanded that starts as false which would be the case for an expandable hamburger menu. Then we do an if/then operation on the variable "x". if the value is true , then change it to false , if it is false , then change it to true .

Top Articles
How do I add my apple gift card to wallet…
Is exchanging one cryptocurrency for another taxable?
Menards Thermal Fuse
Play FETCH GAMES for Free!
Koopa Wrapper 1 Point 0
Tryst Utah
I Make $36,000 a Year, How Much House Can I Afford | SoFi
Le Blanc Los Cabos - Los Cabos – Le Blanc Spa Resort Adults-Only All Inclusive
Workday Latech Edu
Phone Number For Walmart Automotive Department
Brgeneral Patient Portal
Okatee River Farms
7543460065
Katie Boyle Dancer Biography
Cape Cod | P Town beach
LeBron James comes out on fire, scores first 16 points for Cavaliers in Game 2 vs. Pacers
Transformers Movie Wiki
2135 Royalton Road Columbia Station Oh 44028
5 high school volleyball stars of the week: Sept. 17 edition
Skyward Login Jennings County
Earl David Worden Military Service
Geometry Review Quiz 5 Answer Key
FDA Approves Arcutis’ ZORYVE® (roflumilast) Topical Foam, 0.3% for the Treatment of Seborrheic Dermatitis in Individuals Aged 9 Years and Older - Arcutis Biotherapeutics
Dwc Qme Database
Cincinnati Adult Search
Walmart Near South Lake Tahoe Ca
Aol News Weather Entertainment Local Lifestyle
Jayah And Kimora Phone Number
Jermiyah Pryear
Chamberlain College of Nursing | Tuition & Acceptance Rates 2024
6892697335
Jesus Revolution Showtimes Near Regal Stonecrest
Geico Car Insurance Review 2024
Mikayla Campinos: Unveiling The Truth Behind The Leaked Content
Scott Surratt Salary
Stickley Furniture
Earthy Fuel Crossword
Gr86 Forums
Flaky Fish Meat Rdr2
Max 80 Orl
Lucky Larry's Latina's
Today's Final Jeopardy Clue
Solemn Behavior Antonym
Streameast.xy2
Sams Gas Price Sanford Fl
Expendables 4 Showtimes Near Malco Tupelo Commons Cinema Grill
Take Me To The Closest Ups
Nurses May Be Entitled to Overtime Despite Yearly Salary
Oak Hill, Blue Owl Lead Record Finastra Private Credit Loan
Craigslist Indpls Free
Epower Raley's
The Significance Of The Haitian Revolution Was That It Weegy
Latest Posts
Article information

Author: Madonna Wisozk

Last Updated:

Views: 5883

Rating: 4.8 / 5 (48 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Madonna Wisozk

Birthday: 2001-02-23

Address: 656 Gerhold Summit, Sidneyberg, FL 78179-2512

Phone: +6742282696652

Job: Customer Banking Liaison

Hobby: Flower arranging, Yo-yoing, Tai chi, Rowing, Macrame, Urban exploration, Knife making

Introduction: My name is Madonna Wisozk, I am a attractive, healthy, thoughtful, faithful, open, vivacious, zany person who loves writing and wants to share my knowledge and understanding with you.