Skip to content
IndexRequest a UIAboutContact

Range Slider

A slider with a filled track, a value bubble and keyboard support.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Build a custom-styled range slider on top of a native input type="range" (min 0, max 100, value 40) so keyboard, touch and screen-reader support are preserved. Style the track as 6px tall with the portion before the thumb filled with the accent colour by updating a CSS variable --p (percentage) on input. Style the thumb as a 24px white circle with a soft shadow that grows to 28px while dragging. Show a value bubble above the thumb (rounded rectangle with the number) positioned using --p and clamped inside the container; it fades in during pointer press or keyboard focus and out afterwards in 120ms. Also show the numeric value to the right of a label "Volume" for accessibility and set aria-valuetext with a unit. Disable the growth animation under prefers-reduced-motion.

About this pattern

Definition

A control for choosing a number within a range by dragging a thumb along a track. The part of the track behind the thumb is filled, and a bubble above the thumb shows the current value while it is being used.

Purpose & UX principles

  • Best for approximate values where the exact number matters less than the feel (volume, brightness, price range).
  • When precision matters, pair the slider with a number input.
  • Always expose the value as text, not only as a position.

Interaction states

  • Idle, hover (thumb halo), dragging (bubble visible, thumb grows), focus-visible, disabled.
  • Arrow keys step by 1; PageUp and PageDown step by 10 (native input type=range behaviour).

Motion specification

  • Thumb growth and bubble: 120ms ease-out.
  • The fill follows the value directly without easing to feel responsive.
  • Reduced motion: no growth animation.

Responsive behaviour

  • Thumb 24px visual with a 44px touch area; the track is full width.
  • Keep the bubble inside the container at the extremes.

Code

HTML
<div class="rs"><div class="top"><label for="r">Volume</label><output id="o">40%</output></div>
  <div class="wrap"><span class="bub" id="b">40</span><input type="range" id="r" min="0" max="100" value="40"></div></div>

Related patterns

Text Input

↗
Text InputInputs & Forms

Progress Indicator

↗
Progress IndicatorLoading & Progress

Toggle Switch

↗
Toggle SwitchInputs & Forms