Select Input
Form select inputs are used when the user has a choice of many options eg choosing a country or a county
Intended behaviour
If you use the component for settings, you can make an option pre-selected by default when users first see it.
If you use the component for questions, you should not pre-select any of the options in case it influences users’ answers.
When to use this component
The select component allows users to choose an option from a long list. The select component should only be used as a last resort in public-facing services because research shows that some users find selects very difficult to use.
When not to use this component
The select component allows users to choose an option from a long list. Before using the select component, try asking users questions which will allow you to present them with fewer options.
Variations
Minimal input
open this example in its own window
<label for="ds-id-0" class="form-label">Lorem ipsum</label>
<select id="ds-id-0" class="form-select" aria-label="Lorem ipsum">
<option value="maecenas">Maecenas</option>
<option value="donec">Donec</option>
<option value="curabitur">Curabitur</option>
</select>
Options to the selectInput()
macro
{% from 'macros/component/select-input.html' import selectInput %}
{{ selectInput({
'label': 'Lorem ipsum',
'options': {
'maecenas': 'Maecenas',
'donec': 'Donec',
'curabitur': 'Curabitur'
}
}) }}
Required input
open this example in its own window
<label for="ds-id-1" class="form-label">Lorem ipsum</label>
<select id="ds-id-1" class="form-select" aria-label="Lorem ipsum" required>
<option value="maecenas">Maecenas</option>
<option value="donec">Donec</option>
<option value="curabitur">Curabitur</option>
</select>
Options to the selectInput()
macro
{% from 'macros/component/select-input.html' import selectInput %}
{{ selectInput({
'label': 'Lorem ipsum',
'options': {
'maecenas': 'Maecenas',
'donec': 'Donec',
'curabitur': 'Curabitur'
},
'required': true
}) }}
Invalid input
open this example in its own window
<label for="ds-id-2" class="form-label">Lorem ipsum</label>
<select id="ds-id-2" class="form-select is-invalid" aria-label="Lorem ipsum">
<option value="maecenas">Maecenas</option>
<option value="donec">Donec</option>
<option value="curabitur">Curabitur</option>
</select>
Options to the selectInput()
macro
{% from 'macros/component/select-input.html' import selectInput %}
{{ selectInput({
'label': 'Lorem ipsum',
'options': {
'maecenas': 'Maecenas',
'donec': 'Donec',
'curabitur': 'Curabitur'
},
'invalid': true
}) }}
Disabled input
open this example in its own window
<label for="ds-id-3" class="form-label">Lorem ipsum</label>
<select id="ds-id-3" class="form-select" aria-label="Lorem ipsum" disabled>
<option value="maecenas">Maecenas</option>
<option value="donec">Donec</option>
<option value="curabitur">Curabitur</option>
</select>
Options to the selectInput()
macro
{% from 'macros/component/select-input.html' import selectInput %}
{{ selectInput({
'label': 'Lorem ipsum',
'options': {
'maecenas': 'Maecenas',
'donec': 'Donec',
'curabitur': 'Curabitur'
},
'disabled': true
}) }}
Prepopulated input
open this example in its own window
<label for="ds-id-4" class="form-label">Lorem ipsum</label>
<select id="ds-id-4" class="form-select" aria-label="Lorem ipsum">
<option value="maecenas">Maecenas</option>
<option value="donec">Donec</option>
<option value="curabitur" selected>Curabitur</option>
</select>
Options to the selectInput()
macro
{% from 'macros/component/select-input.html' import selectInput %}
{{ selectInput({
'label': 'Lorem ipsum',
'options': {
'maecenas': 'Maecenas',
'donec': 'Donec',
'curabitur': 'Curabitur'
},
'value': 'curabitur'
}) }}