@krushnasinnarkar
Posted
Hi @alvarozama,
Congratulations on successfully completing the challenge! Your solution looks nice.
Sure, I can help clarify the use of ARIA (Accessible Rich Internet Applications) attributes to improve the accessibility of your webpage. Here are explanations and examples for the most commonly used ARIA attributes:
aria-label: The aria-label
attribute defines a string that labels the current element. It is often used when the element itself does not have a visible label.
<button aria-label="Close menu">ā</button>
aria-labelledby: The aria-labelledby
attribute identifies the element (or elements) that label the current element. It is used to reference other elements' IDs.
<h2 id="section1">Introduction</h2>
<div aria-labelledby="section1">
Content labeled by the heading with id="section1"
</div>
aria-expanded: The aria-expanded
attribute indicates whether the element, or another grouping element it controls, is currently expanded or collapsed.
<button aria-expanded="false" aria-controls="menu" onclick="toggleMenu()">Menu</button>
<nav id="menu" hidden>
Menu content
</nav>
Here, aria-expanded
should be updated dynamically using JavaScript when the menu state changes:
function toggleMenu() {
const menuButton = document.querySelector('button[aria-controls="menu"]');
const menu = document.getElementById('menu');
const isExpanded = menuButton.getAttribute('aria-expanded') === 'true';
menuButton.setAttribute('aria-expanded', !isExpanded);
menu.hidden = isExpanded;
}
role: The role
attribute defines the role of an element in an application. Common roles include button
, navigation
, dialog
, and alert
.
<div role="alert">
This is an important message.
</div>
aria-hidden: The aria-hidden
attribute indicates that the element and all of its descendants are not visible or perceivable to any user as part of the accessible user interface.
<div aria-hidden="true">
This content will be hidden from screen readers.
</div>
Explanation:
aria-label
: Used for labeling elements with a descriptive text that is not visually presented (e.g., button to open the menu).aria-labelledby
: Reference an ID of an element that labels the current element (not used in the example but useful for complex widgets).aria-expanded
: Indicates the current state (expanded or collapsed) of a collapsible element like the menu.role
: Specifies the role of elements (e.g.,role="img"
for non-decorative images).aria-hidden
: Used to hide elements from screen readers (not used in the example but useful for decorative images or elements).
By correctly using these ARIA attributes, your webpage becomes more accessible to users who rely on assistive technologies like screen readers.
I hope you find this helpful, and I would greatly appreciate it if you could mark my comment as helpful if it was.
Feel free to reach out if you have more questions or need further assistance.
Happy coding!
Marked as helpful