Know the “search” Element
Published on June 19, 2024, filed under Development (RSS feed for all categories).
You know that at the moment, there are 112 elements in HTML (not counting math
, svg
, and custom elements, which is important to note). Do you know element #112, i.e., the latest member of the HTML elements family?
What element? The
search
element—as of this writing, the latest element addition to HTML, which became part of HTML on March 24, 2023.What does it do? What does it mean?
Here’s its definition:
The
search
element represents a part of a document or application that contains a set of form controls or other content related to performing a search or filtering operation. This could be a search of the website or application; a way of searching or filtering search results on the current web page; or a global or Internet-wide search function.However, note:
It’s not appropriate to use the
search
element just for presenting search results, though suggestions and links as part of “quick search” results can be included as part of a search feature. Rather, a returned web page of search results would instead be expected to be presented as part of the main content of that web page.Now, can we find the element in use somewhere?
From searching GitHub,
search
doesn’t seem popular yet. However, there are implementations of it. Here’s one:<search> <form action="./search/"> <label for="movie">Find a Movie</label> <input type="search" id="movie" name="q" /> <button type="submit">Search</button> </form> </search>
Is this valid?
Yes. Likewise, at the time of this chapter’s writing (March 2024), the W3C validator complains (“Element
search
not allowed as child of elementbody
in this context”), but that looks like an issue with the validator (cf. validator issue #1569). That is, this code isn’t per se bad.However, it’s not the maximum—or minimum, I suppose—we could get out of this, either. That would look more like the following:
<search> <form action=./search/> <label for=movie>Find a movie</label> <input type=search id=movie name=q> <button>Search</button> </form> </search>
What changed?
Dropped quotes: If this is the first book you’re reading from this series, all superfluous code (except for whitespace) is being removed. That includes quotes that aren’t strictly necessary. A basic rule I like to work with is that when an attribute value doesn’t contain equal signs or spaces, it’s usually okay to skip the quotes. (It’s not precise, but works well enough.)
Removed value defaults: There’s no need to set attributes with values that match the respective attribute’s default. In the case of the
button
element, this istype=submit
(more accurately, the “Submit Button” state.Tweaked case: Assuming the label is not a heading, using title case seems unusual. I’ve adjusted to sentence case.
This isn’t necessarily all we could do. For example, the
label
could surround theinput
, allowing us to save the label–input association (id
andfor
). But that’s something we don’t know, and while I do like to make some guesses and assumptions, I’d stop here. Hisearch
element!
This is from a short book, Upgrade Your HTML V, which I released just six weeks ago.
If you like this, check out the book; if you more-than-like this, check out the series (Amazon, Apple Books, Kobo, Google Play Books, Leanpub)! Cheers!
About Me
I’m Jens (long: Jens Oliver Meiert), and I’m a frontend engineering leader and tech author/publisher. I’ve worked as a technical lead for companies like Google and as an engineering manager for companies like Miro, I’m a contributor to several web standards, and I write and review books for O’Reilly and Frontend Dogma.
I love trying things, not only in web development (and engineering management), but also in other areas like philosophy. Here on meiert.com I share some of my experiences and views. (Please be critical, interpret charitably, and give feedback.)
Read More
Maybe of interest to you, too:
- Next: The Essence of Veganism
- Previous: The Price of a Dream
- More under Development
- More from 2024
- Most popular posts
Looking for a way to comment? Comments have been disabled, unfortunately.
Get a good look at web development? Try WebGlossary.info—and The Web Development Glossary 3K. With explanations and definitions for thousands of terms of web development, web design, and related fields, building on Wikipedia as well as MDN Web Docs. Available at Apple Books, Kobo, Google Play Books, and Leanpub.