Select
BetaFormsOpen in the workshop
One value from a list of up to about fifteen known options.
.xg-select (styled native <select>) · --smExample and markup
Live, from xg-ui.css and xg-ui.js. Switch the brand and mode on the example itself, or for the whole site in the header.
Markup
<div class="xg-row" style="align-items:flex-end">
<div class="xg-field" style="width:220px">
<label class="xg-label" for="fmt">Ad format</label>
<select class="xg-select" id="fmt">
<option>Banner</option>
<option selected>Video (VAST)</option>
<option>Native</option>
<option>Audio</option>
<option>CTV</option>
</select>
</div>
<div class="xg-field" style="width:220px">
<label class="xg-label" for="int">Integration</label>
<select class="xg-select" id="int">
<option>Prebid</option>
<option>OpenRTB</option>
<option>Tags</option>
</select>
</div>
<div class="xg-field" style="width:180px">
<label class="xg-label" for="cur">Currency</label>
<select class="xg-select" id="cur" disabled>
<option>USD</option>
</select>
</div>
</div>States
Hover, focus and pressed are forced here with .is-hover, .is-focus and .is-active so they can be seen side by side; in a product they come from :hover, :focus-visible and :active.
| State | Select |
|---|---|
| Default | |
| Hover | |
| Focus | |
| Error | |
| Disabled |
When to use it
Use it for
currency, time zone, ad format, integration type.
Not for
two or three options (Segmented control or Radio); long searchable lists (a combobox, on the roadmap); several values (Checkboxes or tags).
Rules
- Native <select> by default: it is accessible, keyboard-complete and right on touch devices.
- Order options by frequency or logic, not alphabetically, unless the list is long.
- A first option like “Choose…” only when no sensible default exists.
Accessibility
- Label with <label for>. The chevron is drawn in CSS from currentColor and is decorative.
Every color pair this component uses is measured for both brands in light and dark on the Accessibility page.
Related
Also in Forms: Input, Textarea, Checkbox, Radio, Switch, Segmented control, Search field, Date-range picker, Form layout. Used in the patterns Reporting table, Onboarding and sign-up, Forms and overlays.
Status Beta: usable; class names may still change in a minor release, with a note (see Releasing).