Landmark
HTML 2023
The <search> element represents a part of a document or application that contains search or filtering functionality. It provides a semantic way to identify search interfaces, making them more accessible to assistive technologies and improving the overall structure of your HTML.
Interactive code playground requires JavaScript. Here's the code:
<header>
<h1>My Website</h1>
<search>
<form action="/search" method="get">
<label for="search-input">Search:</label>
<input type="search" id="search-input" name="q" placeholder="Search articles...">
<button type="submit">Search</button>
</form>
</search>
</header>
<!-- Search or filtering interface -->
The <search> element has no element-specific attributes.
This element supports all global attributes .
A simple search form in the header:
Interactive code playground requires JavaScript. Here's the code:
<header style="background: #f5f5f5; padding: 1rem; border-bottom: 2px solid #ddd;">
<div style="max-width: 1200px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center;">
<h1 style="margin: 0; font-size: 1.5rem;">TechBlog</h1>
<search>
<form action="/search" method="get" style="display: flex; gap: 0.5rem;">
<input
type="search"
name="q"
placeholder="Search articles..."
aria-label="Search articles"
style="padding: 0.5rem; border: 1px solid #ddd; border-radius: 4px; width: 250px;"
>
<button type="submit" style="background: #667eea; color: white; border: none; padding: 0.5rem 1rem; border-radius: 4px; cursor: pointer;">
Search
</button>
</form>
</search>
</div>
</header>
<main style="padding: 2rem;">
<h2>Latest Articles</h2>
<p>Browse our latest content or use the search above to find specific topics.</p>
</main>
A search interface with multiple filter options:
Interactive code playground requires JavaScript. Here's the code:
<search style="background: #f9f9f9; padding: 1.5rem; border-radius: 8px; margin-bottom: 2rem;">
<form action="/search" method="get">
<h2 style="margin-top: 0;">Search Products</h2>
<div style="display: grid; gap: 1rem;">
<div>
<label for="product-search" style="display: block; margin-bottom: 0.25rem; font-weight: bold;">
Search:
</label>
<input
type="search"
id="product-search"
name="q"
placeholder="Enter product name..."
style="width: 100%; padding: 0.5rem; border: 1px solid #ddd; border-radius: 4px;"
>
</div>
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem;">
<div>
<label for="category" style="display: block; margin-bottom: 0.25rem; font-weight: bold;">
Category:
</label>
<select id="category" name="category" style="width: 100%; padding: 0.5rem; border: 1px solid #ddd; border-radius: 4px;">
<option value="">All Categories</option>
<option value="electronics">Electronics</option>
<option value="clothing">Clothing</option>
<option value="books">Books</option>
</select>
</div>
<div>
<label for="min-price" style="display: block; margin-bottom: 0.25rem; font-weight: bold;">
Min Price:
</label>
<input
type="number"
id="min-price"
name="min_price"
placeholder="$0"
style="width: 100%; padding: 0.5rem; border: 1px solid #ddd; border-radius: 4px;"
>
</div>
<div>
<label for="max-price" style="display: block; margin-bottom: 0.25rem; font-weight: bold;">
Max Price:
</label>
<input
type="number"
id="max-price"
name="max_price"
placeholder="$1000"
style="width: 100%; padding: 0.5rem; border: 1px solid #ddd; border-radius: 4px;"
>
</div>
</div>
<div style="display: flex; gap: 0.5rem;">
<button type="submit" style="background: #667eea; color: white; border: none; padding: 0.75rem 1.5rem; border-radius: 4px; cursor: pointer; font-weight: bold;">
Apply Filters
</button>
<button type="reset" style="background: #ddd; color: #333; border: none; padding: 0.75rem 1.5rem; border-radius: 4px; cursor: pointer;">
Reset
</button>
</div>
</div>
</form>
</search>
<main>
<h2>Product Results</h2>
<p>Your filtered products will appear here.</p>
</main>
A prominent site-wide search feature:
Interactive code playground requires JavaScript. Here's the code:
<section style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 4rem 2rem; text-align: center;">
<h1 style="font-size: 2.5rem; margin-bottom: 1rem;">Search Our Knowledge Base</h1>
<p style="font-size: 1.2rem; margin-bottom: 2rem; opacity: 0.95;">Find answers to your questions</p>
<search style="max-width: 600px; margin: 0 auto;">
<form action="/search" method="get">
<div style="display: flex; gap: 0.5rem; background: white; padding: 0.5rem; border-radius: 50px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
<input
type="search"
name="q"
placeholder="What can we help you with?"
aria-label="Search knowledge base"
style="flex: 1; padding: 0.75rem 1rem; border: none; border-radius: 50px; font-size: 1rem; outline: none;"
>
<button type="submit" style="background: #667eea; color: white; border: none; padding: 0.75rem 2rem; border-radius: 50px; cursor: pointer; font-weight: bold; font-size: 1rem;">
Search
</button>
</div>
</form>
</search>
<p style="margin-top: 1.5rem; font-size: 0.9rem; opacity: 0.9;">
Popular searches: Getting Started, Billing, API Documentation
</p>
</section>
Search functionality for filtering table data:
Interactive code playground requires JavaScript. Here's the code:
<section>
<h2>User Directory</h2>
<search style="background: #f5f5f5; padding: 1rem; border-radius: 4px; margin-bottom: 1rem;">
<form onsubmit="return false;">
<div style="display: flex; gap: 1rem; align-items: end;">
<div style="flex: 1;">
<label for="name-filter" style="display: block; margin-bottom: 0.25rem; font-size: 0.9rem;">
Filter by Name:
</label>
<input
type="search"
id="name-filter"
placeholder="Enter name..."
style="width: 100%; padding: 0.5rem; border: 1px solid #ddd; border-radius: 4px;"
>
</div>
<div style="flex: 1;">
<label for="role-filter" style="display: block; margin-bottom: 0.25rem; font-size: 0.9rem;">
Filter by Role:
</label>
<select id="role-filter" style="width: 100%; padding: 0.5rem; border: 1px solid #ddd; border-radius: 4px;">
<option value="">All Roles</option>
<option value="admin">Admin</option>
<option value="editor">Editor</option>
<option value="viewer">Viewer</option>
</select>
</div>
<button type="submit" style="background: #667eea; color: white; border: none; padding: 0.5rem 1rem; border-radius: 4px; cursor: pointer;">
Filter
</button>
</div>
</form>
</search>
<table style="width: 100%; border-collapse: collapse;">
<thead>
<tr style="background: #f0f0f0;">
<th style="padding: 0.75rem; text-align: left; border-bottom: 2px solid #ddd;">Name</th>
<th style="padding: 0.75rem; text-align: left; border-bottom: 2px solid #ddd;">Email</th>
<th style="padding: 0.75rem; text-align: left; border-bottom: 2px solid #ddd;">Role</th>
</tr>
</thead>
<tbody>
<tr>
<td style="padding: 0.75rem; border-bottom: 1px solid #eee;">John Doe</td>
<td style="padding: 0.75rem; border-bottom: 1px solid #eee;">john@example.com</td>
<td style="padding: 0.75rem; border-bottom: 1px solid #eee;">Admin</td>
</tr>
<tr>
<td style="padding: 0.75rem; border-bottom: 1px solid #eee;">Jane Smith</td>
<td style="padding: 0.75rem; border-bottom: 1px solid #eee;">jane@example.com</td>
<td style="padding: 0.75rem; border-bottom: 1px solid #eee;">Editor</td>
</tr>
</tbody>
</table>
</section>
Search interface with suggestion list:
Interactive code playground requires JavaScript. Here's the code:
<header style="padding: 1rem; background: #fff; border-bottom: 1px solid #ddd;">
<search style="max-width: 600px; margin: 0 auto; position: relative;">
<form action="/search" method="get">
<label for="search-autocomplete" style="display: block; margin-bottom: 0.5rem; font-weight: bold;">
Search Documentation:
</label>
<div style="position: relative;">
<input
type="search"
id="search-autocomplete"
name="q"
placeholder="Search for topics, guides, or API methods..."
list="search-suggestions"
style="width: 100%; padding: 0.75rem; padding-right: 3rem; border: 2px solid #ddd; border-radius: 4px; font-size: 1rem;"
>
<button type="submit" style="position: absolute; right: 0.5rem; top: 50%; transform: translateY(-50%); background: #667eea; color: white; border: none; padding: 0.5rem 1rem; border-radius: 4px; cursor: pointer;">
đ
</button>
</div>
<datalist id="search-suggestions">
<option value="Getting Started Guide">
<option value="API Reference">
<option value="Authentication">
<option value="Rate Limits">
<option value="Error Handling">
<option value="Best Practices">
</datalist>
</form>
</search>
</header>
Product search with category navigation:
Interactive code playground requires JavaScript. Here's the code:
<div style="background: #f5f5f5; padding: 1.5rem;">
<search>
<form action="/products" method="get">
<div style="display: flex; gap: 0.5rem; max-width: 800px; margin: 0 auto;">
<select name="category" aria-label="Product category" style="padding: 0.75rem; border: 1px solid #ddd; border-radius: 4px; background: white;">
<option value="">All Departments</option>
<option value="electronics">Electronics</option>
<option value="clothing">Clothing</option>
<option value="home">Home & Garden</option>
<option value="sports">Sports & Outdoors</option>
<option value="books">Books</option>
</select>
<input
type="search"
name="q"
placeholder="Search for products..."
aria-label="Search products"
style="flex: 1; padding: 0.75rem; border: 1px solid #ddd; border-radius: 4px;"
>
<button type="submit" style="background: #ff9800; color: white; border: none; padding: 0.75rem 2rem; border-radius: 4px; cursor: pointer; font-weight: bold;">
Search
</button>
</div>
</form>
</search>
</div>
<main style="padding: 2rem;">
<h2>Featured Products</h2>
<p>Use the search above to find specific products.</p>
</main>
A search interface without a traditional form submission:
Interactive code playground requires JavaScript. Here's the code:
<search style="padding: 1rem; background: #f9f9f9; border-radius: 8px;">
<label for="quick-search" style="display: block; margin-bottom: 0.5rem; font-weight: bold;">
Quick Filter:
</label>
<input
type="search"
id="quick-search"
placeholder="Type to filter results..."
oninput="console.log('Filtering:', this.value)"
style="width: 100%; padding: 0.75rem; border: 2px solid #ddd; border-radius: 4px; font-size: 1rem;"
>
<p style="font-size: 0.9rem; color: #666; margin-top: 0.5rem;">
Results update as you type
</p>
</search>
<div style="margin-top: 1rem;">
<h3>Results</h3>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
Understanding when to use <search>:
<!-- Good: Search functionality -->
< input type = " search " name = " q " >
<!-- Good: Filtering interface -->
< label > Filter by category: </ label >
< select onchange = " filterResults ( this . value ) " >
< option > Category 1 </ option >
<!-- Wrong: Contact form (not search) -->
< input type = " text " name = " name " placeholder = " Your name " >
< input type = " email " name = " email " placeholder = " Email " >
<!-- Correct: Use form directly -->
< input type = " text " name = " name " placeholder = " Your name " >
< input type = " email " name = " email " placeholder = " Email " >
Provide clear labeling for accessibility:
<!-- Good: Visible label -->
< label for = " site-search " > Search the site: </ label >
< input type = " search " id = " site-search " name = " q " >
<!-- Good: aria-label when no visible label -->
< input type = " search " name = " q " aria-label = " Search articles " placeholder = " Search... " >
< button aria-label = " Submit search " > đ </ button >
Use type="search" for search inputs:
<!-- Good: type="search" -->
< input type = " search " name = " q " placeholder = " Search... " >
<!-- Avoid: type="text" for search -->
< input type = " text " name = " q " placeholder = " Search... " >
Always provide a way to submit the search:
<!-- Good: Submit button -->
< input type = " search " name = " q " >
< button type = " submit " > Search </ button >
<!-- Also good: Icon button with label -->
< input type = " search " name = " q " aria-label = " Search " >
< button type = " submit " aria-label = " Submit search " > đ </ button >
You can have multiple search elements on a page:
<!-- Site-wide search in header -->
< search aria-label = " Site search " >
< input type = " search " name = " q " aria-label = " Search entire site " >
<!-- Local search within content -->
< search aria-label = " Product search " >
< form action = " /products/search " >
< input type = " search " name = " q " aria-label = " Search products " >
The <search> element creates a search landmark that assistive technologies can identify:
<!-- Creates a search landmark -->
< input type = " search " name = " q " aria-label = " Search " >
Screen reader users can navigate directly to search landmarks using keyboard shortcuts.
When you have multiple search elements, label them distinctly:
< search aria-label = " Main site search " >
< search aria-label = " Product filters " >
<!-- Product filtering -->
Ensure all search controls are keyboard accessible:
<!-- All these elements are focusable and keyboard-accessible -->
< input type = " search " name = " q " >
< button type = " submit " > Search </ button >
Browser Version Chrome 118+ Firefox 118+ Safari 17+ Edge 118+ IE Not supported
For older browsers, you can add ARIA to provide similar functionality:
< input type = " search " name = " q " >
<!-- Fallback for older browsers -->
< input type = " search " name = " q " >
<!-- Wrong: Login form in search element -->
< input type = " email " name = " email " >
< input type = " password " name = " password " >
<!-- Correct: Use form directly -->
< input type = " email " name = " email " >
< input type = " password " name = " password " >
<!-- Incomplete: Input without form -->
< input type = " search " name = " q " >
<!-- Better: Wrap in form -->
< input type = " search " name = " q " >
< button type = " submit " > Search </ button >
< input type = " search " name = " q " >
<!-- Correct: Add label -->
< input type = " search " name = " q " aria-label = " Search the site " >