brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: the element replaces role="search" on a form

Search
~/tips/tip-html-search-element

cat ~/tips/tip-html-search-element.md

Marks the search or filter part of a page as a landmark without an ARIA role.

Screen reader users jump between landmarks like the navigation, the main content and the search. HTML now has an element that marks the search part without an ARIA role. I’d pick it over the ARIA role for new pages.

Wrap the search or filter controls in <search>:

<header>
  <h1>Movie website</h1>
  <search>
    <form action="/search/">
      <label for="movie">Find a movie</label>
      <input type="search" id="movie" name="q">
      <button type="submit">Search</button>
    </form>
  </search>
</header>

The element has the implicit ARIA role search, so it creates a search landmark. Before this you wrote <form role="search">. The old pattern still works, and the MDN page does not call it wrong, but the new element is clearer, and it also fits things that are not a form, such as a live filter on a table or a list.

Caveats:

  • It is for the search or filter controls, not the results. Results belong in the main content. Quick suggestions that appear while typing can sit inside it.
  • It has no look of its own, so you get no visual change and need your own CSS.
  • It has been available since October 2023. Older browsers and assistive tools may not map it to a landmark, so some people keep role="search" on the form as a belt-and-braces measure.
  • Use it once per page for the main search. Several landmarks with the same role are confusing unless you label each with aria-label.

It is a small change, but it costs nothing and helps people who navigate by landmark.

Further reading: MDN: <search>

Going deeper: Run degoog on Unraid as your own search page, compared with SearXNG and 4get

More Search tips !!wfr Wau Holland zipgrep db_host backup.zip pdfgrep -rin "warranty" ~/Documents "fatal error" repo:github-linguist/linguist is:open involves:@me All Search tips (11) All topics

Link