Actions and inputs
Search field
A native <input type="search"> in .kui-search: a pill with a magnifier before the text and the browser’s clear button after it. Put it in a <form role="search"> when it searches the site.
Examples
Search the site
The form has role="search", so it is a landmark a screen reader can jump to. The label is visually hidden because the magnifier and the place say what the field is.
<form class="kui-search" role="search" action="#search-results">
<label class="kui-visually-hidden" for="search-site">Search the documentation</label>
<div class="kui-input-wrap">
<svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#search"></use></svg>
<input class="kui-input" id="search-site" name="q" type="search" placeholder="Search the documentation" autocomplete="off" enterkeyhint="search">
</div>
</form>
With a search button
A button is useful where a search costs time, such as a large archive. Enter submits the form either way.
<form class="kui-search kui-search--button" role="search" action="#search-results">
<label class="kui-visually-hidden" for="search-archive">Search the invoices</label>
<div class="kui-input-wrap">
<svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#search"></use></svg>
<input class="kui-input" id="search-archive" name="q" type="search" placeholder="Invoice or customer" enterkeyhint="search">
</div>
<button class="kui-button kui-button--primary" type="submit">Search</button>
</form>
Filtering a list on the page
A field that filters what is already shown is not a search landmark: it is a plain field with a visible label. Say how many items are left in a polite status line next to it.
3 of 248 customers
<div class="kui-field kui-search">
<label class="kui-label" for="search-filter">Filter customers</label>
<div class="kui-input-wrap">
<svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#filter"></use></svg>
<input class="kui-input" id="search-filter" type="search" value="Đorđević" aria-describedby="search-filter-count">
</div>
<p class="kui-hint" id="search-filter-count" role="status">3 of 248 customers</p>
</div>
In other scripts
The field takes any text. The placeholder wraps nowhere, so keep it short in every language.
<form class="kui-search" role="search" action="#search-results" lang="sr-Cyrl">
<label class="kui-visually-hidden" for="search-cyrl">Претрага</label>
<div class="kui-input-wrap"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#search"></use></svg><input class="kui-input" id="search-cyrl" name="q" type="search" placeholder="Претражите прописе" enterkeyhint="search"></div>
</form>
<form class="kui-search" role="search" action="#search-results" lang="zh">
<label class="kui-visually-hidden" for="search-zh">搜索</label>
<div class="kui-input-wrap"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#search"></use></svg><input class="kui-input" id="search-zh" name="q" type="search" placeholder="搜索文档" enterkeyhint="search"></div>
</form>
States
Every state
Hover darkens the outline; focus shows the ring. With text, the browser shows its clear button, and Escape clears the field. Disabled is the native attribute.
<div class="kui-form kui-form--wide">
<div class="kui-form__row">
<div class="kui-field kui-search"><label class="kui-label" for="search-s1">Empty</label><div class="kui-input-wrap"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#search"></use></svg><input class="kui-input" id="search-s1" type="search" placeholder="Search"></div></div>
<div class="kui-field kui-search"><label class="kui-label" for="search-s2">With text</label><div class="kui-input-wrap"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#search"></use></svg><input class="kui-input" id="search-s2" type="search" value="Kraftfahrzeughaftpflichtversicherung"></div></div>
<div class="kui-field kui-search"><label class="kui-label" for="search-s3">Disabled</label><div class="kui-input-wrap"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#search"></use></svg><input class="kui-input" id="search-s3" type="search" placeholder="Search" disabled></div></div>
</div>
</div>
Classes and attributes
.kui-search- On the form or the field around the search input: makes the input a pill.
.kui-input-wrap + .kui-icon- The magnifier (search) or the funnel (filter) before the text.
input type="search"- Gives the clear button, Escape to clear, and the search key on a phone.
role="search"- On the form that searches the site or a large collection.
.kui-search--button- The field and a search button in one row.
enterkeyhint="search"- Labels the Enter key on a phone’s keyboard as Search.
Keyboard
- Enter
- Submits the search.
- Escape
- Clears the field (the browser’s own key).
Accessibility
- The field always has a label; a visually hidden one is enough when the magnifier and the place make the purpose clear.
- A search form is a landmark: give it role="search", and only one per region.
- When results change on the page as the person types, say how many there are in a status line.
- The magnifier is aria-hidden; it is not the name of the field.
Do and do not
Do
- Put the site search in the same place on every page.
- Keep what was searched in the field on the results page.
- Say what can be searched in a short placeholder: “Invoice or customer”.
Do not
- Do not use a search field for one value from a known list; use a combobox.
- Do not start a slow search on every key press; wait until the person pauses or presses Enter.
- Do not clear the field when the search finds nothing.