The Search Element and Input Type Search: Semantic Search UI for Free

The HTML search element and input type=search: the search landmark, browser support, GET forms, clear buttons, result counts, and styling quirks.

Executive Summary: HTML now has a <search> element that marks a search or filtering region as a landmark, replacing role="search" on a form or div. It shipped in Safari 17 and Firefox 118 in September 2023 and in Chrome 118 in October 2023. Pair it with <input type="search">, a real label and a GET form, and you get a landmark screen reader users can jump to, a search keyboard on phones, a clear button, Escape-to-clear and shareable result URLs, with almost no code.
Search bar with a magnifier icon representing the HTML search element

Search is one of the most-used controls on any site, and one of the most hand-rolled. A typical implementation is a div with an unlabeled text input, a magnifying-glass icon with a click handler, results loaded with JavaScript and a URL that never changes. Screen reader users cannot find it with landmark navigation, the phone shows a Return key instead of Search, and nobody can share or bookmark a results page.

The <search> element represents the part of a page that contains controls for searching or filtering. Browsers map it to the ARIA search landmark role automatically. <input type="search"> is a text field specialized for search terms, exposed to assistive technology as a search box. One gives the region meaning; the other gives the field its behavior.

How does the search element work?

<search>
  <form action="/search" method="get">
    <label for="site-search">Search articles</label>
    <input id="site-search" name="q" type="search" enterkeyhint="search">
    <button>Search</button>
  </form>
</search>

Before this element existed, the accessible way to mark a search region was <form role="search">. That still works, but it required authors to know about ARIA, and many never added it. The new element brings search in line with nav, main and aside: a native element with a built-in landmark role. Screen reader users can press a single key, such as D in NVDA or the rotor in VoiceOver, to jump straight to it.

What belongs inside

  • Site search in the header.
  • Filtering controls on a listing page: the search box, category select and price range that narrow a product list all describe the same task.
  • In-page search, such as filtering a table of contents or a long FAQ.

Search results do not belong inside it; they are content and usually live in main. Put the <search> element around the form, not inside it, and use one per distinct search feature. If a page has two, such as site search and a product filter, give each a name with aria-label so users can tell them apart in the landmark list.

Older browsers

Browsers released before autumn 2023 treat <search> as an unknown element: it renders as an inline box with no role. If you still have a meaningful share of such visitors, two small additions cover them during the transition:

search { display: block; }   /* unknown elements default to inline */

<search role="search">...</search>  <!-- explicit role for older assistive tech -->

Validators flag role="search" on <search> as redundant. That is true for current browsers, and you can remove it once your analytics show older versions have faded out.

What does input type=search add?

A search input behaves like a text input with a few useful differences:

Behavior type="text" type="search"
Role exposed to screen readers Text box Search box
Clear button when there is text No Yes in Chrome, Edge and Safari
Escape clears the value No Yes in most browsers
Virtual keyboard Enter key Return Search or Go on many phones
Fires a search event No Chromium and Safari, on Enter or clear (non-standard)

Add enterkeyhint="search" to make the Enter key label consistent across mobile keyboards. Use the standard input and submit events in your code rather than the non-standard search event, which Firefox does not fire.

Label it, even when you hide the label

A placeholder of “Search” and a magnifying glass are not a label. Keep a <label> and hide it visually if the design has no room, as described in the accessible forms guide. If the submit button is an icon, give it text too:

<button>
  <svg aria-hidden="true" focusable="false">...</svg>
  <span class="visually-hidden">Search</span>
</button>

Styling quirks

WebKit and Blink give search inputs extra built-in styling, such as rounded corners in older Safari and the clear button. To control them:

input[type="search"] {
  -webkit-appearance: none;
  appearance: none;
}

/* Restyle or hide the built-in clear button */
input[type="search"]::-webkit-search-cancel-button {
  cursor: pointer;
}

Think twice before hiding the clear button. It is a quick, accessible way to reset the field, especially on touch screens.

Why should search use GET and real URLs?

A search form should almost always use method="get". The query ends up in the URL, as /search?q=wireless+headphones&amp;sort=price, so results can be bookmarked, shared, opened in a new tab and navigated with the Back button. Analytics tools pick up the search terms automatically from the URL.

If you enhance the form with JavaScript to show results without a page load, keep the URL in sync with history.replaceState or pushState, and read the query from the URL on page load so a shared link shows the same results. The plain form remains a working fallback if the script fails.

How do you announce live search results?

When results update as the user types, sighted users see the list change. Screen reader users hear nothing unless you tell them. A polite live region with the result count solves it:

<p id="result-count" role="status"></p>

<script>
  let timer;
  input.addEventListener("input", () => {
    clearTimeout(timer);
    timer = setTimeout(async () => {
      const results = await runSearch(input.value);
      renderResults(results);
      document.getElementById("result-count").textContent =
        results.length === 0 ? "No results" : `${results.length} results`;
    }, 300);
  });
</script>

role="status" creates a polite live region: the screen reader announces the new count once the user pauses, without interrupting what they are typing. The 300-millisecond debounce keeps both the announcements and the network requests from firing on every keystroke.

Suggestion dropdowns are a bigger step. A list of suggestions that users can arrow through is an ARIA combobox, one of the hardest widget patterns to get right across screen readers. If you need one, start from a well-tested implementation rather than building it from scratch, and keep the plain form submit working underneath.

A complete, small search component

<search aria-label="Articles">
  <form action="/search" method="get" class="search">
    <label for="q" class="visually-hidden">Search articles</label>
    <input id="q" name="q" type="search" enterkeyhint="search"
           autocomplete="off" spellcheck="false" placeholder="e.g. dialog element">
    <button>
      <svg aria-hidden="true" focusable="false" width="20" height="20">...</svg>
      <span class="visually-hidden">Search</span>
    </button>
  </form>
</search>

autocomplete="off" is reasonable here, since the browser’s history of past queries is rarely useful in a site search box and can cover your own suggestions. The other attributes come from the autocomplete and inputmode guide.

Frequently Asked Questions

What is the HTML search element?

The search element is an HTML element that wraps controls used for searching or filtering, such as a search form or a set of filters. Browsers expose it as an ARIA search landmark, so screen reader users can jump to it directly, without needing role=”search”.

Which browsers support the search element?

Safari 17 and Firefox 118 added it in September 2023, and Chrome and Edge 118 in October 2023. Older browsers treat it as an unknown inline element, so add display: block in CSS and, if you support them, role=”search” as a temporary fallback.

What is the difference between input type=search and type=text?

A search input is exposed as a search box to assistive technology, shows a clear button in Chromium and Safari, can be cleared with Escape, and often triggers a Search key on mobile keyboards. Otherwise it behaves like a text input.

Should a search form use GET or POST?

GET. It puts the query in the URL, so results pages can be bookmarked, shared, reloaded and navigated with the Back button, and analytics can read the search terms. POST is for actions that change data.

Small markup, real benefits

A good search box is mostly a matter of using the elements built for it: <search> for the landmark, type="search" for the field, a label for its name and a GET form for shareable URLs. Add a live result count if results update as people type, and you have search that works for keyboard, screen reader and mobile users before you write any custom behavior. For the full reference, see the MDN search element reference and the search element section of the HTML Standard. Related reading on this site: HTML5 input types and ARIA landmarks.

Originally posted on 12 December 2023 and post last modified on 12 December 2023

Accessibility Forms Front-End Development HTML5 Search Element

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *