search
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
- Multiple search landmarks on one page (generally use only one)
Basic Examples
Simple Search Input
Search with Form
Wrap a form inside <search> for server-side search functionality.
Variants
.inline
Search input with button side-by-side using flexbox.
.compact
Smaller search for headers or sidebars.
.rounded
Pill-shaped search input.
.expanded
Full-width search input.
.header
Constrained width for header placement.
.with-icon
Search with an icon inside the input.
Styling
CSS Implementation
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 |
Form Patterns
GET Form for Server Search
Use GET method so search queries appear in the URL and can be bookmarked/shared.
Client-Side Filtering
For client-side filtering, omit the form and handle input events directly.
Search with Additional Filters
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-labelattribute on the input
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
If a page has multiple search regions, use aria-label to distinguish them:
Keyboard Support
| Key | Action |
|---|---|
| Enter | Submit the search form (when in form context) |
| Escape | Clear the search input (browser-dependent) |
Related Elements
<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.