docs.rodeo

MDN Web Docs mirror

ARIA: textbox role

{{AccessibilitySidebar}} 

The textbox role is used to identify an element that allows the input of free-form text. Whenever possible, rather than using this role, use an {{HTMLElement("input")}}  element with type=“text”, for single-line input, or a {{HTMLElement("textarea")}}  element for multi-line input.

Description

When an element has the textbox role, the browser sends an accessible textbox event to assistive technologies, which can then notify the user about it.

The default is a single line input, in which Return or Enter submits the form; in this case, it is preferable to use an HTML {{HTMLElement("input")}}  with type="text". To create a multi-line text box which supports line breaks, as in an HTML {{HTMLElement("textarea")}} , set aria-multiline="true". Including the HTML contenteditable attribute ensures the text node is editable.

<!-- Simple text input field -->
<div id="txtboxLabel">Enter your five-digit zip code</div>
<div
  role="textbox"
  contenteditable="true"
  aria-placeholder="5-digit zip code"
  aria-labelledby="txtboxLabel"></div>

<!-- Multi-line text area -->
<div id="txtboxMultilineLabel">Enter the tags for the article</div>
<div
  role="textbox"
  contenteditable="true"
  aria-multiline="true"
  aria-labelledby="txtboxMultilineLabel"
  aria-required="true"></div>

Semantic elements are more concise and require no JavaScript to support textbox features.

<label for="txtbox">Enter your five-digit zip code</label>
<input type="text" placeholder="5-digit zip code" id="txtbox" />

<!-- Multi-line text area -->
<label for="txtboxMultiline">Enter the tags for the article</label>
<textarea id="txtboxMultiline" required></textarea>

Where a text field is read-only, indicated this by setting aria-readonly="true" on the element.

Associated ARIA properties

Keyboard interactions

In a single-line use (when aria-multiline is false or not used), the Return or Enter key submits the form. In a multi-line use (when aria-multiline is true), Return or Enter key inserts a line break.

JavaScript features

All features associated with any and all properties and states must be maintained, and forms submission on enter or return on a single line textbox needs to be handled.

[!NOTE] It is a better practice to use an {{HTMLElement("input")}}  element with type=“text”, or a {{HTMLElement("textarea")}}  element instead of the ARIA textbox role. When using either semantic element, the ARIA textbox role is not necessary. See Notes on Using ARIA in HTML.

Possible effects on user agents and assistive technology

When the textbox role is added to an element, or such an element becomes visible, the user agent should do the following:

Assistive technology products should listen for such an event and notify the user accordingly:

[!NOTE] Opinions may differ on how assistive technology should handle this technique. The information provided above is one of those opinions and may be experienced differently.

Examples

Example 1: Adding the role in the HTML code for single line input

The snippet below shows how the textbox role is added directly into the HTML source code.

<div role="textbox" contenteditable="true"></div>

Example 2: Adding the role in the HTML code for multi-line input

The snippet below shows how the textbox role is added directly into the HTML source code.

<div role="textbox" contenteditable="true" aria-multiline="true"></div>

Best practices

See also

In this article

View on MDN