大网数据广告活动
Web 标准与前端开发

ARIA: searchbox role

· 52CE 我爱测

The `searchbox` role indicates an element is a type of `textbox` intended for specifying search criteria.

The searchbox role indicates an element is a type of textbox intended for specifying search criteria.

Description

The searchbox can be used instead of textbox when the text box is within an element with role search. A searchbox is the semantic equivalent is HTML's input of type search, <input type="search">, which should be used instead if possible.

The searchbox must have an accessible name. If the searchbox role is applied to an HTML input element, an associated label should be used. Otherwise, use aria-labelledby if a visible label is present, or aria-label if a visible label is not present.

The screen reader will announce "search box", "search edit", or "search field" plus the accessible name. This can be redundant if "search" is included in the label.

Examples

<div tabindex="0" aria-label="search" role="searchbox" contenteditable></div>

While the above is valid, it is simpler, more concise, and less redundant to the screen reader user to write:

<input type="search" />

The following is a search form with a searchbox and button, ARIA live region, and container for search results.

<form role="search">
  <input
    type="search"
    role="searchbox"
    aria-description="search results will appear below"
    id="search"
    value="" />
  <label for="search">Search this site</label>
  <button>Submit search</button>
</form>
<div aria-live="polite" role="region" aria-atomic="true">
  <div class="sr-only"></div>
</div>
<div id="search-results"></div>

Including role="searchbox" when the form is a search and the label indicates the element is a search may result in assistive technology announcing something along the lines of "search search this site search box", which is redundant. The inclusion of role="searchbox" is not necessary:

<input
  type="search"
  aria-description="search results will appear below"
  id="search"
  value="" />

Specifications

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。