Accessibility Best Practice
+
+ This sample demonstrates the correct use of id and for attributes
+ for proper label-input association, which is essential for accessibility:
+
-
+
- Each
<input>element has a uniqueidattribute
+ - The corresponding
<label>has aforattribute that matches the input'sid
+ - This pairing ensures screen readers like JAWS and NVDA can properly announce labels +
- It also allows users to click the label to focus the input, improving usability +
+ Note: The for attribute must match the id attribute,
+ not the name attribute. Using name alone without id breaks
+ screen reader functionality and fails HTML validation.
+