Components
Search
Search allows users to quickly find relevant content on a website or in an application. The component consists of a search field, with or without a search button.
Search is deprecated and will be removed in the next major version. Read Search is being removed, what should you do? to see how you can make your own search field.
<input class="ds-input" type="search" aria-label="Search"/>const PreviewEn = () => { return <Input type='search' aria-label='Search' />; }; render(<PreviewEn />)
Use search when
- users need help finding relevant information quickly on a website or in an application
- users are expected to enter keywords or phrases to locate the most relevant content
Avoid search when
- the content is easy to navigate without search
- it replaces good navigation — search should complement navigation, not be the only method
Example
With clear button
Use Suggestion with Suggestion.Clear when users need a button to clear the search field. The button is shown when the field has a value.
<ds-suggestion class="ds-suggestion">
<input
class="ds-input"
type="search"
placeholder=""
aria-label="Search"
/>
<button hidden="" type="reset"></button>
</ds-suggestion>const WithClearEn = () => { return ( <EXPERIMENTAL_Suggestion> <EXPERIMENTAL_Suggestion.Input type='search' aria-label='Search' /> <EXPERIMENTAL_Suggestion.Clear /> </EXPERIMENTAL_Suggestion> ); }; render(<WithClearEn />)
With search button
Add a search button after the field when the search should be submitted with a button. The button can be primary or secondary.
<ds-suggestion class="ds-suggestion">
<input
class="ds-input"
type="text"
placeholder=""
aria-label="Search"
/>
<button hidden="" type="reset"></button>
<button class="ds-button" type="submit">Search</button>
</ds-suggestion>
<hr
aria-hidden="true"
class="ds-divider"
style="margin-top:var(--ds-size-4)"
/>
<ds-suggestion class="ds-suggestion">
<input
class="ds-input"
type="text"
placeholder=""
aria-label="Search"
/>
<button hidden="" type="reset"></button>
<button
class="ds-button"
data-variant="secondary"
type="submit"
>Search</button>
</ds-suggestion>const WithSearchButtonEn = () => { return ( <> <EXPERIMENTAL_Suggestion> <EXPERIMENTAL_Suggestion.Input type='text' aria-label='Search' /> <EXPERIMENTAL_Suggestion.Clear /> <Button type='submit'>Search</Button> </EXPERIMENTAL_Suggestion> <Divider style={{ marginTop: 'var(--ds-size-4)' }} /> <EXPERIMENTAL_Suggestion> <EXPERIMENTAL_Suggestion.Input type='text' aria-label='Search' /> <EXPERIMENTAL_Suggestion.Clear /> <Button type='submit' variant='secondary'> Search </Button> </EXPERIMENTAL_Suggestion> </> ); }; render(<WithSearchButtonEn />)
Guidelines
The width of the search field should reflect the length of the search terms users typically enter. The size of the field signals what users can type. For example, a search field for national identity numbers should match the length of such a number. A main search field for a website should be wider so users can see several words at once. To avoid forcing users to scroll within the field, ensure it is not so short that parts of the text become hidden.
Text
Placeholder text should be used with caution, as it disappears when users start typing and may cause confusion. It must also meet accessibility contrast requirements, which may make it difficult to distinguish from entered text. Screen readers handle placeholder text inconsistently, so information should instead be provided through a label or description.
You should use a label above the search field when it is not obvious what users are expected to search for, or when the search field is part of a form.
Read more about labels, descriptions and placeholder text in forms.
<ds-field class="ds-field">
<label class="ds-label">Search for cats</label>
<ds-suggestion class="ds-suggestion">
<input
class="ds-input"
type="text"
placeholder=""
name="cat-search"
/>
<button hidden="" type="reset"></button>
<button class="ds-button" type="submit">Search</button>
</ds-suggestion>
</ds-field>const WithLabelEn = () => { return ( <Field> <Label>Search for cats</Label> <EXPERIMENTAL_Suggestion> <EXPERIMENTAL_Suggestion.Input type='text' name='cat-search' /> <EXPERIMENTAL_Suggestion.Clear /> <Button type='submit'>Search</Button> </EXPERIMENTAL_Suggestion> </Field> ); }; render(<WithLabelEn />)