References

Beginner-friendly references for web development, with live, editable examples.

The HTML aria-required attribute

ARIA Accessibility
In short

Setting aria-required="true" tells assistive technology that a widget needs input before its form is submitted. Nothing enforces it, so an empty field with only this attribute still submits. On native fields, the HTML required attribute exposes the same state and blocks the submission too.

Overview

With aria-required, a widget declares that it needs user input before its form can be submitted. It mainly serves custom controls such as a <div role="textbox">, which can't use HTML's required attribute. It can go on HTML form elements too, not only on elements with an ARIA role.

It's supported on checkbox, combobox, gridcell, listbox, radiogroup, spinbutton, textbox and tree. The radio role isn't there, so in a custom radio group the attribute belongs on the radiogroup. Roles such as searchbox and switch inherit it.

A form whose empty input, select and checkbox carry aria-required="true" still submits, with no invalid event. The input's valueMissing stays false and checkValidity() returns true.

A custom textbox sits even further from the form. A contenteditable <div> isn't a form control, so it's absent from form.elements and from FormData. If such a box is empty, your script has to stop the submission. When it holds text, the script has to send that text as well.

Authors may use aria-required wherever HTML allows required, but ARIA in HTML names the native attribute first. It discourages pairing the two with true, and bans pairing them with false. Inputs in a novalidate form can keep required too, since they're still exposed as required.

Syntax

<span id="msg-label">Gift message *</span>
<div role="textbox" contenteditable="true" style="border:1px solid"
     aria-labelledby="msg-label" aria-required="true"
     aria-multiline="true"></div>

Values

Value
true | false

Example

Live example
<form id="gift">
  <p id="label" style="margin:0 0 4px">Gift message *</p>
  <div id="message" role="textbox" contenteditable="true" aria-labelledby="label" aria-required="true" aria-multiline="true" style="border:1px solid #767676;padding:6px;min-height:32px"></div>
  <p style="margin:8px 0"><button>Send gift</button></p>
  <p id="out" role="status" style="overflow-wrap:anywhere"></p>
  <p>Press Send gift with the box empty, then type a message and press it again. The * marks a required field.</p>
</form>
<script>
const form = document.getElementById('gift');
const box = document.getElementById('message');
const out = document.getElementById('out');
form.addEventListener('submit', function (e) {
  e.preventDefault();
  const text = box.innerText.trim();
  box.setAttribute('aria-invalid', String(!text));
  out.textContent = text
    ? 'Sent: ' + text
    : 'The script stopped this. aria-required alone would have let it through.';
});
</script>

Best practices

  • Mark an aria-required field visibly as well, such as with an asterisk, since color isn't enough.
  • When the visible label already contains the word required, leave the attribute out, so screen readers don't read the word twice.
  • Put it on the element with the form-control role, such as the textbox a user has to fill in, not on a plain wrapper around it.
  • Report a missing value with aria-invalid once the user has tried to submit, not before.

Frequently asked questions

Does aria-required do the same job as the required attribute?
No, aria-required only tells assistive technology that input is needed, while required also makes the browser stop the form. In some browsers, that block comes with a native error message.
Should a native radio button use aria-required?
On a native radio button, use required, because ARIA in HTML and WAI-ARIA 1.2 disagree on aria-required. The first permits it wherever required is allowed, while the second doesn't list it for the radio role.
Do optional fields need aria-required=false?
No, optional fields can leave out aria-required, whose default is false. That value means input isn't necessary to submit the form.
Which selector styles a field marked with aria-required?
Style a field marked with aria-required through the attribute selector [aria-required=true]. CSS :required matches input, select and textarea elements with the required attribute, so aria-required alone doesn't trigger it.
Can aria-required block a form at all?
No, nothing in aria-required blocks a form, so add a submit listener that checks the widget. Call preventDefault() there when it's empty.
Is an empty aria-required field invalid?
No, aria-required sets no invalid state, so an empty input with it isn't exposed as invalid. Setting aria-invalid after a failed submit is up to your script.