Range Slider
A range slider allows users to choose an approximate number from a range.
Default
Component Preview
Component Code
<form class="usa-form"> <label class="usa-label" for="range-slider-example">Range slider</label> <input id="range-slider-example" class="usa-range" type="range" min="0" max="100" step="10" value="20" /> </form>
Guidance
When to use the range slider component
- When the range is more important than precision.
- For instance, it could be more important for a target price selector to communicate where the target price falls within a certain range than the precise dollar amount selected.
- When a relative value is more important than an exact value.
- For instance, a volume slider is typically more focused on the relative loudness of the output rather than the specific decibel level.
When to consider something else
- Use a regular text input if a user needs to enter a precise number.
Usability guidance
- Highlight the control when selected.
- The slider control should change color to indicate it is active when a user selects it.
- The control must be draggable.
- Users should be able to drag the slider control or select somewhere along the slider itself to change the value.
- Label the limits of the range.
- When appropriate, label the ends of the slider with the limits of the range (for example: "0/100", "small/large" or "less expensive/more expensive").
- Don't be too granular.
- In a range slider, the relative value is more important than the specific value, so set the step attribute so it's not too granular. By setting the step to a value of 10-20% of the total range you prevent unnecessary precision and cognitive strain in your users. For example, set
step="10"in a total range of 100.
Accessibility guidance
- Customize form controls accessibly.
- If you customize this component, ensure that it continues to meet the accessibility requirements that apply to all form controls.
Using the range slider component
- Set the
minandmaxattribute of theinputelement to correspond to the instructions or labels that accompany the slider.
USWDS Documentation
For more guidance, view the USWDS Range Slider Component Documentation.
Initialization Properties
| Property | Description | Default |
|---|---|---|
data-text-unit
|
Adds a unit to screen reader callouts. The unit will be read after the current value. For example, adding a value of "stars" enables a readout like "3.5 stars of 5." |
Undefined |
data-text-preposition
|
Changes the preposition between current value and max value in screen reader readouts. For example, adding a value with the Spanish translation "de" enables a readout like "20 de 100". |
of |