Skip to content

    Slider

    Picks a number, or a range of two, by dragging a raised knob along a flat rail: a volume, a price range, a zoom level. The accent range runs from the start to the knob over the soft gray track. variant steps draws a tick under the track at each step and the thumb lands on those ticks. marks puts a tick and a label under the track at each value you name. The arrow keys move it one step. A tooltip over the knob shows the value while it is dragged or moved with the keyboard. showValue prints the value beside the track.

    React

    Preview

    Volume

    Props

    • defaultValue
    • value
    • min
    • max
    • variant
    • step
    • orientation
    • disabled
    • thumbLabels
    • showValue
    • marks
    import { Slider } from "@/components/ui/slider"
    
    <div className="flex w-64 max-w-full flex-col gap-sm">
      <span id="preview-slider-label" className="text-sm font-medium text-text-secondary">Volume</span>
      <Slider aria-labelledby="preview-slider-label" defaultValue={[60]} />
    </div>

    Usage

    When to use

    • Pick a number where the feel matters more than the exact value: volume, zoom, brightness.
    • Pick a range between two values, such as a price filter.

    When not to use

    • An exact number, such as a quantity. Use Input.
    • A few named choices. Use RadioGroup, or Select for a long list.
    • Showing how much of a task is done. Use Progress.

    Platform support

    What each platform has, from the spec. A selected platform is highlighted.

    NameWebiOSAndroidNote
    defaultValueYesYesYes
    valueYesYesYes
    onValueChangeYesYesYes
    onValueCommitYesYesYes
    minYesYesYes
    maxYesYesYes
    variantYesYesYes
    marksYesDeferredDeferredNot generated for iOS and Android.
    stepYesYesYes
    orientationYesDeferredDeferredNot generated for iOS and Android.
    disabledYesYesYes
    nameYesDeferredDeferredNot generated for iOS and Android.
    thumbLabelsYesDeferredDeferredNot generated for iOS and Android.
    showValueYesDeferredDeferredNot generated for iOS and Android.
    formatValueYesDeferredDeferredNot generated for iOS and Android.
    labelNoYesYesOnly on iOS, Android.
    hapticsNoYesYesOnly on iOS, Android.
    value of keyboard: ArrowRight, ArrowUpYesDeferredDeferred
    value of keyboard: ArrowLeft, ArrowDownYesDeferredDeferred
    value of keyboard: PageUp, PageDownYesDeferredDeferred
    value of keyboard: Home, EndYesDeferredDeferred
    value of keyboard: TabYesDeferredDeferred

    Variants

    variant

    default is a smooth track. steps draws a tick under the track at each step, and the thumb lands on those ticks. With no step, the ticks split the range into four even parts.

    • Volume

      defaultdefault

    • Volume

      steps

    import { Slider } from "@/components/ui/slider"
    
    <div className="flex w-64 max-w-full flex-col gap-sm">
      <span id="preview-slider-label-variant-default" className="text-sm font-medium text-text-secondary">Volume</span>
      <Slider aria-labelledby="preview-slider-label-variant-default" defaultValue={[60]} />
    </div>
    <div className="flex w-64 max-w-full flex-col gap-sm">
      <span id="preview-slider-label-variant-steps" className="text-sm font-medium text-text-secondary">Volume</span>
      <Slider aria-labelledby="preview-slider-label-variant-steps" defaultValue={[60]} variant="steps" />
    </div>

    orientation

    horizontal fills the width of its parent. vertical fills the height of its parent, at least 160px.

    • Volume

      horizontaldefault

    • Volume

      vertical

    import { Slider } from "@/components/ui/slider"
    
    <div className="flex w-64 max-w-full flex-col gap-sm">
      <span id="preview-slider-label-orientation-horizontal" className="text-sm font-medium text-text-secondary">Volume</span>
      <Slider aria-labelledby="preview-slider-label-orientation-horizontal" defaultValue={[60]} />
    </div>
    <div className="flex h-48 flex-col items-center gap-sm">
      <span id="preview-slider-label-orientation-vertical" className="text-sm font-medium text-text-secondary">Volume</span>
      <Slider aria-labelledby="preview-slider-label-orientation-vertical" defaultValue={[60]} className="flex-1" orientation="vertical" />
    </div>

    Examples

    Volume

    Volume
    import { Slider } from "@/components/ui/slider"
    
    <div className="flex w-full max-w-xs flex-col gap-sm">
      <span id="volume-label" className="text-sm font-medium text-text-secondary">Volume</span>
      <Slider aria-labelledby="volume-label" defaultValue={[60]} />
    </div>

    Price range

    Two values make two thumbs, each with its own name.

    import { Slider } from "@/components/ui/slider"
    
    <Slider aria-label="Price" thumbLabels={["Minimum price", "Maximum price"]} defaultValue={[20, 80]} step={5} className="max-w-xs" />

    Marks

    marks names a tick and a label under the track at each value. The mark at the current value is emphasised.

    import { Slider } from "@/components/ui/slider"
    
    <div className="w-full max-w-xs">
      <Slider aria-label="Level" defaultValue={[50]} variant="steps" marks={levelMarks} />
    </div>

    Fixed steps

    variant steps lands on even ticks. showValue prints the value beside the track. The tooltip still shows while dragging.

    import { Slider } from "@/components/ui/slider"
    
    <Slider aria-label="Zoom" defaultValue={[50]} variant="steps" showValue className="max-w-xs" />

    Disabled

    import { Slider } from "@/components/ui/slider"
    
    <Slider aria-label="Brightness" defaultValue={[30]} disabled className="max-w-xs" />

    Do and don't

    Do

    • Use it when the exact number matters less than the feel: volume, zoom, a rough price range.
    • Use showValue when the number should stay on screen. The tooltip still shows it while dragging. Offer an Input when an exact number matters.
    • Save in onValueCommit, not in onValueChange, so a drag doesn't send a request per step.

    Don't

    • Don't use it for a precise number such as a quantity; use Input.
    • Don't use it for a few named choices; use RadioGroup or Select.
    • Don't use it to show progress; use Progress.

    Props

    NameTypeValuesDefaultDescription
    defaultValuenumber--One number per thumb, as an array: [40], or [20, 80] for a range. The value on first render, when you don't control it.
    valuenumber--The values as an array, when you control them. Pair it with onValueChange.
    onValueChangefunction--Called with the new values on every step, while dragging too. Update what the slider previews here.
    onValueCommitfunction--Called once when the user lets go or presses a key. Save or fetch here.
    minnumber-0The lowest value.
    maxnumber-100The highest value.
    variantenumdefault | stepsdefaultdefault is a smooth track. steps draws a tick under the track at each step, and the thumb lands on those ticks. With no step, the ticks split the range into four even parts.
    marksstring--Optional { value: number; label: string }[]. A tick and a label under the track at each value (to the right when vertical), in either variant. The mark equal to the current value is emphasised. Labels are decoration for sighted users; screen readers read the value, so use formatValue when a label carries meaning. (The spec schema has no array type, so it is declared as string.) Not generated for iOS and Android.
    stepnumber-1How far one arrow key press moves the thumb. On variant steps this is also the distance between stops. More than 21 ticks are not drawn.
    orientationenumhorizontal | verticalhorizontalhorizontal fills the width of its parent. vertical fills the height of its parent, at least 160px. Not generated for iOS and Android.
    disabledboolean-falseCan't be focused or moved; the range, the grip and the ticks turn to the disabled color and the knob lies flat.
    namestring--Form name. Inside a form, each value is submitted under it. Not generated for iOS and Android.
    thumbLabelsstring--Optional string[] with one accessible name per thumb, in order, for a range (Minimum price, Maximum price). Each name replaces aria-label on its thumb. (The spec schema has no array type, so it is declared as string.) Not generated for iOS and Android.
    showValueboolean-falsePrints the value beside the track, or under it when vertical. The tooltip still shows while dragging or using the keyboard. Not generated for iOS and Android.
    formatValuefunction--(value, index) => string. Writes the value for the tooltip, the printed value and screen readers (aria-valuetext): (value) => `$${value}`. Not generated for iOS and Android.
    label requiredstring--The accessible name, read before the value. On iOS and Android it is the label argument; on the web it is aria-label or aria-labelledby. Only on iOS, Android.
    hapticsboolean-trueWith variant steps, a drag that lands on a new step gives one throttled selection tick. false turns it off. The default variant never gives one. Only on iOS, Android.

    Anatomy

    PartDescription
    rootSlider: a row as wide as its parent (a column when vertical), 24px tall, that holds the track, the range, the ticks and the knobs. It holds the two knob centers as --slider-start and --slider-end. With marks it leaves room below (to the right when vertical) for the labels.
    trackThe flat rail: a 12px, fully round bar in the soft gray fill, the full length of the slider.
    rangeThe accent fill over the track, from the start to the knob, or between the two knobs of a range. Fully round and flat. It ends at the knob's center.
    thumbA knob: a raised key 16px along the track and 24px across, centered on the track. Border-border, background-raised and shadow-low. The focus ring goes around it, and it shrinks to scale-pressed while pressed.
    gripOne 2px line, 12px long, in the middle of the knob, turned to match the orientation. Tertiary text color at rest; accent while the pointer is over the knob, while it has keyboard focus and while it is pressed. Decorative.
    indicatorA tick under the track (to the right when vertical): 1px by 6px, spacing-xs below the slider's bottom edge so the knob never covers it, one at each step with variant steps and at each mark. The tick at a current value is accent.
    labelThe text of a mark: 14px secondary text under its tick, primary and medium while its value is the current one. Decorative: aria-hidden.
    hitAreaTransparent ::before centered on each knob, never smaller than size-target-min.
    valueThe value tooltip: Tooltip's surface (inverse fill, inverse 14px text, radius-element, shadow-med), 4px above a horizontal handle or to the right of a vertical one. It is drawn inside the handle, so a parent with overflow hidden clips it. showValue prints the value beside the track in 14px secondary text, under the track when the slider is vertical.

    Accessibility

    Role: slider

    KeysAction
    ArrowRight, ArrowUpRaises the value by one step.
    ArrowLeft, ArrowDownLowers the value by one step.
    PageUp, PageDownRaises or lowers the value by ten steps.
    Home, EndSets the value to min or max.
    TabMoves to the next thumb; each thumb is its own tab stop.
    • Each thumb is a slider with aria-valuenow, aria-valuemin and aria-valuemax. The type requires aria-label or aria-labelledby on Slider, which every thumb takes; give each thumb of a range its own name with thumbLabels (Minimum price, Maximum price).
    • The value tooltip shows while a thumb is dragged, and while it has keyboard focus; it is aria-hidden, since screen readers read aria-valuenow, or aria-valuetext when formatValue is set. showValue prints the same value beside the track, also aria-hidden.
    • With formatValue, every thumb gets aria-valuetext, so a screen reader says "$40", not "40".
    • The knob is 16px wide and its hit area is at least size-target-min (24px on mouse, 44px on touch); a press anywhere on the slider moves the nearest knob there.
    • The grip lines, the ticks and the mark labels are aria-hidden decoration. A screen reader reads the value (aria-valuenow, or aria-valuetext with formatValue), so a label such as Mid is never the only way to know the value: pass formatValue when a label carries meaning.
    • Disabled slides nowhere and turns the range, the grip line and the ticks to the disabled color; the knob lies flat.

    Install

    npx werewolf-ui add slider

    Run npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.