Select
These examples are used for automated tests and may not follow service manual best practice.
Code
Markup
<div class="nhsuk-form-group">
<h1 class="nhsuk-label-wrapper">
<label class="nhsuk-label" for="example">
Sort by
</label>
</h1>
<select class="nhsuk-select" id="example" name="example">
<option value="published">Recently published</option>
<option value="updated">Recently updated</option>
<option value="views">Most views</option>
<option value="comments">Most comments</option>
</select>
</div>
Macro
Code
Markup
<div class="nhsuk-form-group">
<h1 class="nhsuk-label-wrapper">
<label class="nhsuk-label nhsuk-label--s" for="custom-size">
Sort by
</label>
</h1>
<select class="nhsuk-select" id="custom-size" name="example">
<option value="published">Recently published</option>
<option value="updated">Recently updated</option>
<option value="views">Most views</option>
<option value="comments">Most comments</option>
</select>
</div>
Macro
Code
Markup
<div class="nhsuk-form-group">
<h1 class="nhsuk-label-wrapper">
<label class="nhsuk-label nhsuk-label--m" for="custom-size">
Sort by
</label>
</h1>
<select class="nhsuk-select" id="custom-size" name="example">
<option value="published">Recently published</option>
<option value="updated">Recently updated</option>
<option value="views">Most views</option>
<option value="comments">Most comments</option>
</select>
</div>
Macro
Code
Markup
<div class="nhsuk-form-group">
<h1 class="nhsuk-label-wrapper">
<label class="nhsuk-label nhsuk-label--l" for="custom-size">
Sort by
</label>
</h1>
<select class="nhsuk-select" id="custom-size" name="example">
<option value="published">Recently published</option>
<option value="updated">Recently updated</option>
<option value="views">Most views</option>
<option value="comments">Most comments</option>
</select>
</div>
Macro
Code
Markup
<div class="nhsuk-form-group">
<h1 class="nhsuk-label-wrapper">
<label class="nhsuk-label nhsuk-label--xl" for="custom-size">
Sort by
</label>
</h1>
<select class="nhsuk-select" id="custom-size" name="example">
<option value="published">Recently published</option>
<option value="updated">Recently updated</option>
<option value="views">Most views</option>
<option value="comments">Most comments</option>
</select>
</div>
Macro
Code
Markup
<div class="nhsuk-form-group">
<h1 class="nhsuk-label-wrapper">
<label class="nhsuk-label" for="with-disabled-item">
Sort by
</label>
</h1>
<select class="nhsuk-select" id="with-disabled-item" name="example">
<option value="published">Recently published</option>
<option value="updated">Recently updated</option>
<option value="views">Most views</option>
<option value="comments" disabled>Most comments</option>
</select>
</div>
Macro
Code
Markup
<div class="nhsuk-form-group">
<h1 class="nhsuk-label-wrapper">
<label class="nhsuk-label" for="example">
Sort by
</label>
</h1>
<select class="nhsuk-select" id="example" name="example">
<option value="first-name-ascending">First name (A to Z)</option>
<option value="first-name-descending">First name (Z to A)</option>
<hr>
<option value="last-name-ascending">Last name (A to Z)</option>
<option value="last-name-descending">Last name (Z to A)</option>
</select>
</div>
Macro
Code
Markup
<div class="nhsuk-form-group nhsuk-form-group--error">
<h1 class="nhsuk-label-wrapper">
<label class="nhsuk-label" for="with-error-message">
Choose location
</label>
</h1>
<p class="nhsuk-error-message" id="with-error-message-error">
<span class="nhsuk-u-visually-hidden">Error:</span> Select a location
</p>
<select class="nhsuk-select nhsuk-select--error" id="with-error-message" name="example" aria-describedby="with-error-message-error">
<option value="choose">Choose location</option>
<option value="eastmidlands">East Midlands</option>
<option value="eastofengland">East of England</option>
<option value="london">London</option>
<option value="northeast">North East</option>
<option value="northwest">North West</option>
<option value="southeast">South East</option>
<option value="southwest">South West</option>
<option value="westmidlands">West Midlands</option>
<option value="yorkshire">Yorkshire and the Humber</option>
</select>
</div>
Macro
Select with hint
Open this example in a new tab: Select with hint
This can be different to where you went before
Code
Markup
<div class="nhsuk-form-group">
<h1 class="nhsuk-label-wrapper">
<label class="nhsuk-label" for="with-hint">
Choose location
</label>
</h1>
<div class="nhsuk-hint" id="with-hint-hint">
This can be different to where you went before
</div>
<select class="nhsuk-select" id="with-hint" name="example" aria-describedby="with-hint-hint">
<option value="choose">Choose location</option>
<option value="eastmidlands">East Midlands</option>
<option value="eastofengland">East of England</option>
<option value="london">London</option>
<option value="northeast">North East</option>
<option value="northwest">North West</option>
<option value="southeast">South East</option>
<option value="southwest">South West</option>
<option value="westmidlands">West Midlands</option>
<option value="yorkshire">Yorkshire and the Humber</option>
</select>
</div>
Macro
Select with hint and error
Open this example in a new tab: Select with hint and error
This can be different to where you went before
Code
Markup
<div class="nhsuk-form-group nhsuk-form-group--error">
<h1 class="nhsuk-label-wrapper">
<label class="nhsuk-label" for="with-hint-error">
Choose location
</label>
</h1>
<div class="nhsuk-hint" id="with-hint-error-hint">
This can be different to where you went before
</div>
<p class="nhsuk-error-message" id="with-hint-error-error">
<span class="nhsuk-u-visually-hidden">Error:</span> Select a location
</p>
<select class="nhsuk-select nhsuk-select--error" id="with-hint-error" name="example" aria-describedby="with-hint-error-hint with-hint-error-error">
<option value="choose">Choose location</option>
<option value="eastmidlands">East Midlands</option>
<option value="eastofengland">East of England</option>
<option value="london">London</option>
<option value="northeast">North East</option>
<option value="northwest">North West</option>
<option value="southeast">South East</option>
<option value="southwest">South West</option>
<option value="westmidlands">West Midlands</option>
<option value="yorkshire">Yorkshire and the Humber</option>
</select>
</div>
Macro
Code
Markup
<div class="nhsuk-form-group">
<label class="nhsuk-label" for="without-heading">
Sort by
</label>
<select class="nhsuk-select" id="without-heading" name="example">
<option value="published">Recently published</option>
<option value="updated">Recently updated</option>
<option value="views">Most views</option>
<option value="comments">Most comments</option>
</select>
</div>
Macro
Code
Markup
<div class="nhsuk-form-group">
<h1 class="nhsuk-label-wrapper">
<label class="nhsuk-label" for="with-value">
Sort by
</label>
</h1>
<select class="nhsuk-select" id="with-value" name="example">
<option value="published">Recently published</option>
<option value="updated" selected>Recently updated</option>
<option value="views">Most views</option>
<option value="comments">Most comments</option>
</select>
</div>