Actions and inputs
Slider and range
A native <input type="range"> with .kui-slider for one value on a scale, and <kui-range> with two of them for a low and a high value on one track. Show the value in an <output> next to it.
Examples
One value, with its output
The filled part of the track follows the value. An <output for="ID" data-kui-auto> shows the value as it moves.
<div class="kui-field">
<label class="kui-label" for="slider-volume">Volume of notifications</label>
<div class="kui-slider-row">
<input class="kui-slider" id="slider-volume" type="range" min="0" max="100" step="5" value="40">
<output for="slider-volume" data-kui-auto>40</output>
</div>
</div>
A range: low and high
Each thumb is its own slider with an aria-label. The low thumb cannot pass the high one. The element writes “low – high” into the output named by its output attribute.
Hotels in Zlatibor and Kopaonik, 12 to 26 December
<div class="kui-field" role="group" aria-labelledby="slider-price-label">
<div class="kui-cluster kui-cluster--between">
<span class="kui-label" id="slider-price-label">Price per night, EUR</span>
<output class="kui-range__values" id="slider-price-out">60 – 180</output>
</div>
<kui-range class="kui-range" output="slider-price-out">
<input class="kui-slider" type="range" min="0" max="300" step="10" value="60" aria-label="Lowest price">
<input class="kui-slider" type="range" min="0" max="300" step="10" value="180" aria-label="Highest price">
</kui-range>
<p class="kui-hint">Hotels in Zlatibor and Kopaonik, 12 to 26 December</p>
</div>
With the ends named
Name the two ends when the scale has no units, so the person knows which way is which.
<div class="kui-field">
<label class="kui-label" for="slider-detail">Detail of the summary</label>
<input class="kui-slider" id="slider-detail" type="range" min="1" max="5" value="3" aria-describedby="slider-detail-ends" aria-valuetext="3 of 5, balanced">
<div class="kui-cluster kui-cluster--between kui-text-sm kui-text-muted" id="slider-detail-ends"><span>Short</span><span>Complete</span></div>
</div>
States
Every state
Hover puts a soft ring around the thumb. Keyboard focus shows the focus ring on the thumb. Disabled fades the slider. Without JavaScript, the two sliders of a range stand one under the other and still work.
<div class="kui-field">
<label class="kui-label" for="slider-s1">At the start</label>
<div class="kui-slider-row"><input class="kui-slider" id="slider-s1" type="range" min="0" max="10" value="0"><output for="slider-s1" data-kui-auto>0</output></div>
</div>
<div class="kui-field">
<label class="kui-label" for="slider-s2">Disabled</label>
<div class="kui-slider-row"><input class="kui-slider" id="slider-s2" type="range" min="0" max="10" value="7" disabled><output for="slider-s2" data-kui-auto>7</output></div>
</div>
Classes and attributes
input type="range".kui-slider- One value. min, max and step set the scale.
.kui-slider-row- The slider and its output in a row.
output for="ID" data-kui-auto- Shows the slider’s value; the kit keeps it up to date.
kui-range.kui-range- Two sliders on one track. Attribute output: the id of the element that shows “low – high”.
.kui-range__values- The style of the range’s value text.
aria-valuetext- What a screen reader says instead of the bare number, such as “3 of 5, balanced”.
Keyboard
- Left or Down
- One step down.
- Right or Up
- One step up.
- Page Up or Page Down
- A larger step.
- Home or End
- To the minimum or the maximum.
Accessibility
- Each slider is a native slider with its own name, so a range has two named controls: “Lowest price” and “Highest price”.
- Show the value as text; the thumb’s position alone is not enough.
- Use aria-valuetext when the number means something else, such as a level or a time.
- The thumb is 24 pixels; the whole track is at least 44 pixels high, which is the target on a phone.
Do and do not
Do
- Use a slider when the exact value matters less than the place on a scale.
- Show the value, and allow typing it in a number field when it must be exact.
- Choose a step that gives few enough positions to reach with the keyboard.
Do not
- Do not use a slider for a value a person must set exactly, such as an amount of money.
- Do not use a range of hundreds of steps without a larger Page step.
- Do not hide the ends of the scale.