The <search> element is used for identify a section devoted to searching or filtering. You will run into it while reading other people’s HTML, and it is useful to know what job it does before copying the code.
What does <search> mean?
Identify a section devoted to searching or filtering. The tag gives the browser a specific kind of content to work with. It is more helpful to choose a tag for its meaning than because of its default look.
The search element identifies the region. Submitting the query still requires a working search endpoint.
A working HTML example
Here is a small example you can place in an HTML page and inspect in your browser:
<search>
<form action="/search" method="get">
<label for="site-query">Search this website</label>
<input id="site-query" name="q" type="search">
<button type="submit">Search</button>
</form>
</search>
Reading the example
Find the <search> part first. Notice which elements are around it and how its content or attributes are connected to those other elements.
In this example, <search> appears alongside form, input, button. That context is often just as important as the element itself.
The browser builds its document from these relationships. Any CSS changes appearance, while interactive JavaScript behavior must be provided separately when the example includes it.
When should you use it?
Use <search> when you want to identify a section devoted to searching or filtering. A sensible example of this on a real website is the markup shown above; it gives the browser and accessibility tools a clearer job to work with.
Common companions are form, input, button. Check the nesting requirements before moving the element into a different location.
Try it yourself
Submit a query and inspect the resulting URL; remember that the destination needs a search service.
Common Beginner Mistakes
- A search element is not a search engine by itself.
- Picking
<search>only because it looks a certain way instead of checking what it means. - Forgetting to inspect the surrounding markup when an element does not behave as expected.
Key Takeaways
<search>helps identify a section devoted to searching or filtering.- The search element identifies the region. Submitting the query still requires a working search endpoint.
- Start with meaningful markup, then add styling or scripting only when the page needs it.