-
Purpose:
aria-label
is used to provide a text label for an element when there is no visible label, making it accessible for users of assistive technologies. -
Usage: Assign a value to
aria-label
that succinctly describes the purpose or action associated with the element. -
Example:
<button aria-label="Close">X</button>
In this example, the button is labeled "Close," indicating that clicking it will perform a closing action.
-
Best Practices:
- Use
aria-label
when an element lacks visible text and its purpose needs to be communicated. - Keep the label descriptive and concise.
- Avoid redundant use on elements already containing visible text unless additional clarification is needed.
- Use
-
Testing: Verify the effectiveness of
aria-label
by testing your application with screen readers to ensure that the intended information is conveyed.
Using aria-label
appropriately enhances the accessibility of your web content for all users.