There isn't a native HTML way to indicate an expandable/collapsable element so you have to use ARIA.
The first rule of ARIA says if there's a native HTML way to achieve your results, then use HTML. If there's not, then ARIA is the next best thing. ARIA isn't inherently bad but treat it like salt. A little ARIA adds a nice flavor but too much ARIA ruins the app.
In this case, aria-expanded
is the best way to represent an expandable section.
If you really didn't want an ARIA attribute, you could have visually hidden text that describes the element as "expanded" or "collapsed". I would not recommend this approach because aria-expanded
has better built in accessibility support. When you change the value of aria-expanded
, the screen reader will automatically announce the state change "for free". You don't have to do anything. If you have visually hidden text instead, you'd be responsible for changing the hidden text when the state changes and you'd have to make the announcement for the screen reader (typically with aria-live
).
It's a lot of work to not use aria-expanded
.
Regarding aria-controls
, unfortunately, that attribute doesn't buy you much. It's semantically correct to use it but most screen readers don't really do anything with it. For fun, check this out - https://heydonworks.com/article/aria-controls-is-poop/