Codectionary / Developer documentation / HTML

<search>

The <search> element is a relatively new HTML5 semantic element that identifies a section of the page containing search or filtering controls — either for the site itself or for the current page's content. It gives assistive technology a reliable landmark to jump straight to search functionality.

Syntax

<search>
  <form role="search">
    <input type="search" name="q">
  </form>
</search>

Examples

Site Search

Wrapping a site-wide search form.

<search>
  <form action="/search" method="get">
    <label for="q">Search Codectionary</label>
    <input type="search" id="q" name="q" placeholder="Search docs...">
    <button type="submit">Search</button>
  </form>
</search>

Filter Controls

Using search to wrap filtering controls for a list of results.

<search>
  <label for="filter">Filter by language:</label>
  <select id="filter">
    <option>All</option>
    <option>HTML</option>
    <option>CSS</option>
  </select>
</search>

Header Search Bar

A compact search bar placed in the site header.

<header>
  <search>
    <input type="search" placeholder="Quick search..." style="padding: 6px 12px; border-radius: 6px; border: 1px solid #d1d5db;">
  </search>
</header>

Best practices

  • Use search to wrap the form and controls for search/filter functionality, not the results themselves
  • It can be used for both site-wide search and in-page filtering — both are valid uses
  • Being a newer element, verify support in your target browsers; it degrades gracefully to an unstyled generic container in older ones
  • Continue using a real form inside it for the actual search input — search is a landmark wrapper, not a replacement for form semantics

At a glance

Purpose
Structure and meaning for web content
File extension
.html · .htm
Runs in
Web browsers
Usually used with
CSS and JavaScript

Specifications & further reading

Related HTML documentation