Sliders

Allow users to select a value or range from a fixed set of options

UsageOverview

Sliders are often the UI control of choice for letting users select a value or range from a fixed set of options. The main purpose of a slider in the first place is to allow users to explore options.

The slider component is often compared to a volume control: the further the thumb or indicator is away from its initial position, the faster, better, or higher the value it is.

Overall, avoid using a slider unless your application and data can absolutely benefit from it. Selecting a precise value using a slider is a difficult task requiring good motor skills.

Before deciding on a slider, ask yourself this: is a slider the right solution for this problem, or should you use radio buttons or checkboxes instead?

How to use How not to use AnatomyElements

States

Content

The wider or the denser the range selectable through a slider, the harder it is to select a precise value.

If the scale of your slider doesn’t account for the distribution of values in your data, then providing an accurate range becomes a frustrating experience.


VariationsContinuous Slider

Discrete Slider

Dual Value Slider


BehaviorValidation & Errors

Validation in the precise input field should be handled by limiting its input type to numbers, <input type="number"> and implementing a max attribute, min="1" max="5" based on the range scale.

Loading

In case it is necessary, use the thumb's loading state to indicate progress.

Tooltip

A tooltip state is shown above the thumb when this is dragged, showing the current value.

Keyboard Navigation

Focus Key Action
Slider label Read the label
Input field ENTER Enter value
Input field (Dual slider) TAB Moves to secondary value input
Thumb Arrow keys HOME END PAGEUP PAGEDOWN Move thumb left and right Move to the start value Move to the end value Jump forward by increment Jump backward by increment
Any element ESC Exits the slider

Order & AlignmentSpacing

To be effective and easy to manipulate, sliders need space but, most importantly, a lot of horizontal space. The thumb has to be large enough and the track has to be wide enough to jump to the tick marks.

According to spacing recommendations in this article:

So, how large is large enough? If you can ensure that the horizontal spacing between critical tick marks is at least 65 pixels — on narrow and wide screens alike — that’s probably a good amount. And then there is the actual thumb and getting comfortable padding around it, so that the thumb is easy to grab and move across the track. In general, experiments show that making the thumb at least 32 × 32 pixels (rectangular or circular), with 3vw** or** 1.5vmax** padding** (the former on narrow screens, the latter on wide screens) around it, seems to work fairly well. In fact, just from going through dozens of slider implementations, we see that the most usable ones hit that sweet spot well.

Grouping

The elements that make up the slider components should always be grouped together and they may be arranged as displayed in the variations section or as displayed below.


Best PracticesAccessibility Responsiveness

As stated in the Spacing section, sliders require ample space to be effective. Always test your sliders in the various breakpoints to ensure they are functional.


Feedback

We would like to get your feedback. Tell us how you use this component in your projects and how we can improve it.

Style

HTML/CSS v2Default
Feature: Slider Background: Single value Given the slider holds a single value
      Scenario: Tooltip on hover When I hover the thumb Then the value tooltip shows
      up Scenario: Tooltip on drag When I drag the thumb Then the value tooltip shows
      up Scenario: Overdrag When I drag the thumb beyond the ruler size Then the thumb
      stays at the edge of the ruler Scenario: Update input field When I update the
      input field Then the thumb moves to the correct field Scenario: Update through
      drag When I drag the thumb And I let go of the thumb Then the input field
      updates with the new value Scenario: Increment through button When I click on
      "+" Then the thumb moves to the next step Scenario: Decrement through button
      When I click on "-" Then the thumb moves to the previous step