aria-required attribute indicates that user input is required on the element before a form may be submitted.
When a semantic HTML
<textarea> must have a value, it should have the
required attribute applied to it. The HTML
required attribute disables submitting the form unless the required form controls have valid values, while ensuring those navigating with the aid of assistive technologies understand which semantic form controls need valid content.
When form controls are created using non-semantic elements, such as a
<div> with a role of
aria-required attribute should be included, with a value of
true, to indicate to assistive technologies that user input is required on the element for the form to be submittable. The
aria-required attribute can be used with HTML form elements; it is not limited to elements that have an ARIA role assigned.
Similar to the HTML
required attribute set on semantic HTML form controls, the
aria-required attribute explicitly conveys to assistive technologies that the element is required before a form may be submitted. The
required attribute on a semantic HTML form control will prevent the form control from being submitted if no value is present — providing native error messaging in some browsers if a required value is invalid when the user attempts to submit the form. The
:optional pseudoclasses match
<textarea> elements based on whether they are required or optional, respectively. When using non-semantic elements as form controls, you don't get this CSS pseudoclass selector benefit. You can, however, use attribute selectors if the attribute is present:
If a form contains both required and optional form elements, the required elements should be indicated visually using a treatment that does not rely solely on color to convey meaning. Typically, descriptive text and/or an icon are used.
Note: Which elements are required should be apparent to all users. Ensure the visual presentation indicates the form control is required in a consistent, visible manner, remembering that color is not enough to convey information.
The attribute should be added to the form-control role. If the user needs to fill in an email address
aria-required="true" on the textbox.
<div id="tbLabel">Email Address *</div> <div role="textbox" contenteditable aria-labelledby="tblabel" aria-required="true" id="email1"></div>
Note: If the field's label already contains the word "required", it is recommended to leave out the
aria-required attribute. This avoids that screen readers read out the term "required" twice.
<label for="email1">Email Address (required)</label> <input type="email" id="email1" required />
The element requires a value or must be checked for the form to be submittable.
The element is not required.
|Accessible Rich Internet Applications (WAI-ARIA) |