Testing aria-readonly

aria-readonly indicates that a control's value cannot be changed by the user. Unlike a disabled control, a read-only control can still receive focus.

The examples below demonstrate how aria-readonly works with native and custom controls, including correct and incorrect implementations.

Readonly is not the same as disabled

A disabled field cannot receive keyboard focus and its value is not submitted with the form.

A read-only field can still receive focus, and its value can be selected, copied and submitted with a form.

Use readonly when users need to access a value but should not be able to change it. For example, a confirmation number that you cannot edit but may need to copy.

Example 1: readonly on native element

A native input's own readonly attribute needs no ARIA at all. It's mapped to the accessibility tree automatically.

Expected result: The field should be announced as read-only. It should remain focusable, and its value should be selectable and copyable, but not editable.

HTML markup
<input type="text" value="ABC-123-XYZ" readonly>

Recommended: Use the native readonly attribute for supported HTML form controls. It prevents editing and communicates the read-only state to assistive technology.

Example 2: aria-readonly="true" on a native input

Without native readonly, the field remains editable. The aria-readonly attribute communicates the state but does not prevent editing.

Expected result: The field should be announced as read-only, even though typing and pasting still work.

HTML markup
<input type="text" value="ABC-123-XYZ" aria-readonly="true">

Not recommended: The aria-readonly attribute only communicates the state. It does not prevent users from editing the field. Use native readonly instead.

Example 3: aria-readonly="false" on a native input

false is already the default value of aria-readonly, so stating it explicitly changes nothing. Flagged for redundancy, not for being wrong.

Expected result: The field should behave like a normal editable input, with no read-only state announced.

HTML markup
<input type="text" value="ABC-123-XYZ" aria-readonly="false">

Not recommended: The default state is already false, so the attribute is unnecessary on an ordinary editable input.

Example 4: readonly + aria-readonly="true" on a native input

Native readonly already handles both the enforcement and the announcement on its own, so adding aria-readonly="true" duplicates what's already implied. Redundant, not conflicting, both attributes agree.

Expected result: The field should behave like Example 1. It should be announced as read-only, and typing or pasting should not change its value.

HTML markup
<input type="text" value="ABC-123-XYZ" readonly aria-readonly="true">

Not recommended: The native readonly attribute already prevents editing and communicates the state. Adding aria-readonly="true" is redundant.

Example 5: readonly + aria-readonly="false" on a native input

The two attributes disagree. Native readonly is what actually governs behaviour, the browser still blocks typing and paste regardless of what aria-readonly says. But aria-readonly="false" tells assistive technology the opposite of what's actually happening.

Expected result: The field cannot be edited because of the native readonly attribute. Check whether your screen reader announces it as read-only or editable.

HTML markup
<input type="text" value="ABC-123-XYZ" readonly aria-readonly="false">

Do not use: The attributes conflict. Native readonly prevents editing, while aria-readonly="false" indicates that the field is editable. This can cause confusing or inconsistent announcements.

Example 6: aria-readonly="true" on a custom widget

This example uses a custom text field with role="textbox". The aria-readonly="true" attribute communicates the read-only state to assistive technology, while contenteditable="false" prevents editing.

Confirmation number
ABC-123-XYZ

Expected result: The custom field should be announced as read-only and remain focusable. Typing should not change its value.

HTML markup
<div
  role="textbox"
  aria-labelledby="ex6-label"
  aria-readonly="true"
  contenteditable="false"
  tabindex="0"
>ABC-123-XYZ</div>

Recommended for custom widgets: Use aria-readonly to communicate the state and prevent editing through the widget's functionality. Prefer native form controls where possible.

Example 7: aria-readonly="false" on a custom widget

false is already the default value of aria-readonly, so stating it explicitly on a genuinely editable custom widget changes nothing. Same redundancy as Example 3, just on a non-native element.

Confirmation number
ABC-123-XYZ

Expected result: The custom field should be editable, with no read-only state announced.

HTML markup
<div
  role="textbox"
  aria-labelledby="ex7-label"
  aria-readonly="false"
  contenteditable="true"
  tabindex="0"
>ABC-123-XYZ</div>

Not recommended: The default state is already false, so the attribute is usually unnecessary. It may be useful when a custom widget switches between editable and read-only states.

Example 8: invalid value

aria-readonly is a boolean-valued property, only true or false are valid. This example uses a common authoring mistake, echoing the HTML attribute name itself as the ARIA value.

Expected result: The field should remain editable. Check whether the invalid aria-readonly value affects what your screen reader announces.

HTML markup
<input type="text" value="ABC-123-XYZ" aria-readonly="readonly">

Invalid: The value readonly is not supported. The only valid values for aria-readonly are true and false.