Semantic landmark element for search functionality. Wraps search forms and controls to provide accessibility and structural meaning.
Description
The <search> element is a semantic landmark that identifies content related to searching or filtering. It's the recommended way to mark up search functionality, replacing the older pattern of <form role="search">.
As a landmark element, <search> allows screen reader users to quickly navigate to search functionality using landmark navigation.
When to Use
- Site-wide search: Main search functionality in headers
- Page search: Search within specific content (tables, lists)
- Filter controls: Filter interfaces that narrow displayed content
- Search results pages: Wrap the search input on results pages
When Not to Use
- For login forms - use
<form> with appropriate labels
- For general data input - use standard form elements
Basic Examples
Simple Search Input
<search> <input type="search" placeholder="Search..." aria-label="Search" /></search>
Search with Form
Wrap a form inside <search> for server-side search functionality.
<search> <form action="/search" method="get"> <label for="site-search" class="visually-hidden">Search</label> <input type="search" id="site-search" name="q" placeholder="Search..." /> <button type="submit">Search</button> </form></search>
Variants
Every variant styles the input and button as children of <search> or of its direct <form> child (:is(search, search > form) > input). Use the form version whenever there is a submit button: a <button type="submit"> does nothing without a form.
.inline
Search input with button side-by-side using flexbox.
<search class="inline"> <form action="/search" method="get"> <input type="search" name="q" placeholder="Search..." aria-label="Search" /> <button type="submit">Search</button> </form></search>
.compact
Smaller search for headers or sidebars.
<search class="compact inline"> <form action="/search" method="get"> <input type="search" name="q" placeholder="Quick search..." aria-label="Search" /> <button type="submit">Find</button> </form></search>
.rounded
Pill-shaped search input.
<search class="inline rounded"> <form action="/search" method="get"> <input type="search" name="q" placeholder="Search..." aria-label="Search" /> <button type="submit">Go</button> </form></search>
.expanded
Full-width search input.
<search class="expanded"> <form action="/search" method="get"> <input type="search" name="q" placeholder="Search the entire site..." aria-label="Search" /> </form></search>
.header
Constrained width for header placement.
<search class="header inline"> <form action="/search" method="get"> <input type="search" name="q" placeholder="Search..." aria-label="Search" /> <button type="submit" class="small">Go</button> </form></search>
.with-icon
A decorative icon positioned at the inline start of the input. The icon is a sibling placed before the input (svg, .icon or <icon-wc>), and the input gets extra start padding. Combine with .rounded for a pill field.
<search class="with-icon rounded"> <form action="/search" method="get"> <icon-wc name="search" size="sm"></icon-wc> <input type="search" name="q" placeholder="Search..." aria-label="Search" /> </form></search>
Variant Classes Summary
| Class |
Description |
.inline |
Flexbox layout with input and button side-by-side |
.compact |
Smaller sizing for dense interfaces |
.rounded |
Pill-shaped input with full border radius |
.expanded |
Full-width search input |
.header |
Constrained max-width for header placement |
.with-icon |
Positioned icon inside the input |
Styling
Each variant matches controls that are direct children of <search> or of its direct <form>. Abridged from src/native-elements/search/styles.css:
search { display: block;} search.inline { &, & > form { display: flex; gap: var(--size-xs); } & > form { flex: 1; } & > input, & > form > input { flex: 1; }} search.expanded { inline-size: 100%; & > input, & > form > input { inline-size: 100%; }} search.compact { &, & > form { display: flex; gap: var(--size-2xs); } & > input, & > form > input { padding-block: var(--size-xs); font-size: var(--font-size-s); } & > button, & > form > button { padding-block: var(--size-xs); padding-inline: var(--size-s); font-size: var(--font-size-s); }} search.with-icon { position: relative; & > form { position: relative; } & > input, & > form > input { padding-inline-start: var(--size-xl); } & > :is(svg, .icon, icon-wc), & > form > :is(svg, .icon, icon-wc) { position: absolute; inset-inline-start: var(--size-s); inset-block-start: 50%; transform: translateY(-50%); pointer-events: none; }} search.rounded { & > input, & > form > input { border-radius: var(--radius-full); padding-inline-end: var(--size-m); } &:not(.with-icon) > input, &:not(.with-icon) > form > input { padding-inline-start: var(--size-m); }} search.header { max-inline-size: 300px; }
Form Patterns
GET Form for Server Search
Use GET method so search queries appear in the URL and can be bookmarked/shared.
<search class="inline"> <form action="/search" method="get"> <label for="search-products" class="visually-hidden">Search products</label> <input type="search" id="search-products" name="q" placeholder="Search products..." /> <button type="submit">Search</button> </form></search>
Client-Side Filtering
For client-side filtering, omit the form and handle input events directly.
<search> <input type="search" placeholder="Filter results..." aria-label="Filter results" id="filter-input" /></search> <script> const input = document.getElementById('filter-input'); input.addEventListener('input', (e) => { filterContent(e.target.value); });</script>
Accessibility
Landmark Navigation
The <search> element is a landmark, meaning screen reader users can jump directly to it using landmark navigation. This replaces the older pattern of <form role="search">.
Labeling
Always provide a label for the search input. Options include:
- Visible
<label> element
- Visually hidden
<label> using .visually-hidden
aria-label attribute on the input
<label for="search">Search</label><input type="search" id="search" /> <label for="search" class="visually-hidden">Search</label><input type="search" id="search" /> <input type="search" aria-label="Search" />
input[type="search"] vs input[type="text"]
Always use type="search" for search inputs. It provides:
- Clear button in some browsers
- Appropriate keyboard on mobile (search button instead of enter)
- Semantic meaning for assistive technologies
- Search-specific styling opportunities
Multiple Search Landmarks
A page can have more than one search landmark, for example a site search in the header and a filter above a table. Give each one an aria-label so landmark lists can tell them apart:
<search aria-label="Site search"> ...</search> <search aria-label="Filter table results"> ...</search>
Keyboard Support
| Key |
Action |
| Enter |
Submit the search form (when in form context) |
| Escape |
Clear the search input (browser-dependent) |
Site Search Component
<site-search> builds a full search experience (dialog, keyboard shortcut, results) on top of this element. For its no-JavaScript fallback, use a plain <search><form action="/search" method="get"> that submits to your search page, so the landmark and the form work before the component upgrades (not the older <form role="search">). Use <search> on its own for simple GET forms and filters; use <site-search> when you want the instant-results dialog.
Related
<site-search> - Site-wide search dialog that uses a search landmark as its fallback
<input type="search"> - The search input element inside the search landmark
<form> - For wrapping search with server submission
<button> - Submit button for search forms
<nav> - Another landmark element (for navigation)
Browser Support
The <search> element is supported in all modern browsers. For older browsers, it degrades gracefully as a generic container while still functioning correctly.