Web Platform Atlas
EN⚡RUUA⚡DE⚡FR⚡ES⚡PL⚡PT⚡ZH⚡JA⚡
Каталог / HTML / The search element

4.4.15 The search element

Статический предпросмотр (RU): для MDN, WPT, глоссария и BYOK-перевода откройте интерактивный Атлас.
⚡ Открыть главу в Атласе

4.4.15 The search element

Категории:

потоковое содержимое.

Palpable content.

Контексты, в которых может использоваться этот элемент:

Where flow content is expected.

Контентная модель:

потоковое содержимое.

Опущение тегов в text/html:

Ни один из тегов не может быть опущен.

Атрибуты контента:

глобальные атрибуты

Специфика доступности:

Для авторов.

Для разработчиков.

Санитизация:

Default.

DOM-интерфейс:

Uses HTMLElement.

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 web site or application; a way of searching or filtering search results on the current web page; or a global or Internet-wide search function.

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.

In the following example, the author is including a search form within the header of the web page:

<header> <h1><a href="/">My fancy blog</a></h1> ... <search> <form action="search.php"> <label for="query">Find an article</label> <input id="query" name="q" type="search"> <button type="submit">Go!</button> </form> </search> </header>

In this example, the author has implemented their web application's search functionality entirely with JavaScript. There is no use of the form element to perform server-side submission, but the containing search element semantically identifies the purpose of the descendant content as representing search capabilities.

<search> <label> Find and filter your query <input type="search" id="query"> </label> <label> <input type="checkbox" id="exact-only"> Exact matches only </label> <section> <h3>Results found:</h3> <ul id="results"> <li> <p><a href="services/consulting">Consulting services</a></p> <p> Find out how can we help you improve your business with our integrated consultants, Bob and Bob. </p> </li> ... </ul> <!-- when a query returns or filters out all results render the no results message here --> <output id="no-results"></output> </section> </search>

In the following example, the page has two search features. The first is located in the web page's header and serves as a global mechanism to search the web site's content. Its purpose is indicated by its specified title attribute. The second is included as part of the main content of the page, as it represents a mechanism to search and filter the content of the current page. It contains a heading to indicate its purpose.

<body> <header> ... <search title="Website"> ... </search> </header> <main> <h1>Hotels near your location</h1> <search> <h2>Filter results</h2> ... </search> <article> <!-- search result content --> </article> </main> </body>