Skip to content
All components
Forms

Slider

Adjust a numeric value, or a minimum and maximum, by dragging thumbs along a track or using the arrow keys.

One or several thumbs, horizontal or vertical.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add slider

Then import it from @/components/ui/slider. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

Single value

Adjust one numeric value with a single thumb. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Slider } from "@/components/ui/slider"

export function SliderSingleValue() {
  
  const [value, setValue] = React.useState([40])
  
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-8">
      <div className="flex flex-col gap-3">
        <div className="flex items-center justify-between text-paragraph-sm text-sub-600">
          <span>Single value</span>
          <span className="text-strong-950">{value[0]}</span>
        </div>
        <Slider aria-label="Single value" value={value} onValueChange={setValue} />
      </div>
    </div>
  )
}

Range

Use multiple thumbs for a numeric range. Use its source-defined props and preserve native semantics when adapting this example.

"use client"

import { Slider } from "@/components/ui/slider"

export function SliderRange() {
  
  
  
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-8">
      <div className="flex flex-col gap-3">
        <span className="text-paragraph-sm text-sub-600">Range</span>
        <Slider aria-label="Range" thumbLabels={["Range minimum", "Range maximum"]} defaultValue={[25, 75]} />
      </div>
    </div>
  )
}

Steps

Adjust a value in fixed steps with a visible current value and range ends. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Slider } from "@/components/ui/slider"

export function SliderSteps() {
  const id = React.useId()
  const [value, setValue] = React.useState([40])
  const [discount, setDiscount] = React.useState([15])
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-8">
      <div className="flex flex-col gap-3">
        <div className="flex items-center justify-between gap-4">
          <span id={`${id}-discount`} className="text-label-sm text-strong-950">Discount</span>
          <span className="text-paragraph-sm text-strong-950">
            {discount[0]}%
          </span>
        </div>
        <Slider
          aria-labelledby={`${id}-discount`}
          aria-describedby={`${id}-discount-hint`}
          min={0}
          max={50}
          step={5}
          value={discount}
          onValueChange={setDiscount}
        />
        <div className="flex justify-between text-paragraph-sm text-sub-600" aria-hidden="true">
          <span>0%</span>
          <span>50%</span>
        </div>
        <p id={`${id}-discount-hint`} className="text-paragraph-sm text-sub-600">
          Moves in steps of 5%. Use the arrow keys for one step, Page Up and Page Down for larger jumps.
        </p>
      </div>
    </div>
  )
}

Price range

Set a minimum and maximum with named thumbs and a gap kept between them. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Slider } from "@/components/ui/slider"

export function SliderPriceRange() {
  
  const [value, setValue] = React.useState([40])
  
  const [price, setPrice] = React.useState([20, 80])

  return (
    <div className="flex w-full max-w-sm flex-col gap-8">
      <div className="flex flex-col gap-3">
        <div className="flex items-center justify-between gap-4">
          <span className="text-label-sm text-strong-950">Price per night</span>
          <span className="text-paragraph-sm text-strong-950">
            ${price[0]} to ${price[1]}
          </span>
        </div>
        <Slider
          aria-label="Price per night"
          thumbLabels={["Minimum price per night", "Maximum price per night"]}
          min={0}
          max={200}
          step={10}
          minStepsBetweenThumbs={1}
          value={price}
          onValueChange={setPrice}
        />
      </div>
    </div>
  )
}

Disabled

Inspect the unavailable control using its real disabled semantics. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Slider } from "@/components/ui/slider"

export function SliderDisabled() {
  const id = React.useId()
  
  
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-8">
      <div className="flex flex-col gap-3">
        <div className="flex items-center justify-between gap-4">
          <span id={`${id}-quality`} className="text-label-sm text-strong-950">Export quality</span>
          <span className="text-paragraph-sm text-sub-600">80%</span>
        </div>
        <Slider
          aria-labelledby={`${id}-quality`}
          aria-describedby={`${id}-quality-hint`}
          defaultValue={[80]}
          disabled
        />
        <p id={`${id}-quality-hint`} className="text-paragraph-sm text-sub-600">
          Available on paid plans.
        </p>
      </div>
    </div>
  )
}

Vertical

Arrange the slider vertically with enough layout height. Use its source-defined props and preserve native semantics when adapting this example.

"use client"

import * as React from "react"

import { Slider } from "@/components/ui/slider"

export function SliderVertical() {
  const id = React.useId()
  
  
  

  return (
    <div className="flex w-full max-w-sm flex-col gap-8">
      <div className="flex items-center gap-4">
        <span id={`${id}-volume`} className="text-label-sm text-strong-950">Volume</span>
        <Slider aria-labelledby={`${id}-volume`} orientation="vertical" defaultValue={[60]} />
      </div>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

Slider

Adjust a numeric value or range through movable thumbs.

Slider props
PropTypeDefaultDescription
preserveThumbOrderboolean | undefined—When true, thumbs keep their relative order and won't cross over one another while dragging. Each thumb is constrained to the values of its neighbors instead of swapping positions when dragged past them.
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
thumbLabelsstring[] | undefined—Accessible names for individual thumbs, especially contextual range endpoints.
Inherited props (27)
Slider inherited props
PropTypeDefaultDescription
namestring | undefined—Name used by the control's form submission or primitive form integration.
disabledboolean | undefined—Make the supported control unavailable through its native or primitive disabled semantics. This does not disable arbitrary child links.
orientation("horizontal" | "vertical") | undefined—Horizontal or vertical layout/navigation axis as defined by this primitive.
dir("ltr" | "rtl") | undefined—Reading direction used by the primitive. Keep it consistent with the surrounding content and Direction provider.
minnumber | undefined0Minimum supported numeric value.
maxnumber | undefined100Maximum supported numeric value.
stepnumber | undefined—Numeric increment used for slider or native input changes.
minStepsBetweenThumbsnumber | undefined—Minimum separation between slider thumbs, measured in step increments.
valuenumber[] | undefined—Current value in the shape defined by the source type. For controlled interactive inputs, apply updates from the change callback.
defaultValuenumber[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
onValueChange((value: number[]) => void) | undefined—Receive the next value in the source-defined shape. A controlled parent must apply it to value.
onValueCommit((value: number[]) => void) | undefined—Receive a committed slider value after interaction, separately from intermediate onValueChange updates.
invertedboolean | undefined—Invert the slider's value direction while preserving its orientation and reading-direction semantics.
formstring | undefined—ID of the form associated with this control, including when it is rendered outside that form element.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLSpanElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLSpanElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLSpanElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLSpanElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLSpanElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLSpanElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
asChildboolean | undefined—Merge this part into one child instead of its default element. Preserve that child's semantics, ref support and accessibility attributes.
refReact.Ref<HTMLSpanElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).

Accessibility & usage

From registry/ui/slider.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • Approximate values in a known range where relative position matters more than precision: volume, quality, price filters.
  • A minimum and maximum together with two thumbs.
  • Values that people adjust and immediately see the effect of.

When not to use

  • Exact values people already know, such as a quantity or an amount; use a number-like Input.
  • Very large ranges where one pixel jumps many values.
  • Choosing from a few named options; use a radio group or select.

Anatomy

Slider
The Radix slider root with value or defaultValue (always an array), onValueChange, onValueCommit, min, max, step, minStepsBetweenThumbs, orientation and disabled. Renders one thumb per value.
Track and Range
The full track and the filled part between min (or the first thumb) and the current value.
Thumb
One focusable thumb (role=slider) per value. Named by thumbLabels, or by aria-label with 'minimum'/'maximum' added for two thumbs, or by aria-labelledby; aria-describedby and aria-invalid are forwarded to every thumb.

Keyboard & interaction

  • Arrow keys change the value by one step; Page Up and Page Down, or Shift with an arrow, change it by a larger step; Home and End jump to min and max.
  • Pressing on the track moves the nearest thumb there and starts dragging.
  • Each thumb is a Tab stop and announces its value, minimum and maximum.
  • onValueChange fires while dragging; use onValueCommit for expensive work such as a network request.
  • Disabled sliders ignore pointer and keyboard input.

Responsive behavior

  • Full width horizontally; vertical orientation uses a fixed 176 CSS px height.
  • The thumb looks 16 CSS px but its hit area is 24x24 CSS px (WCAG 2.5.8), and the whole track responds to pointer input. Keep the hit area if you resize the thumb.
  • touch-action is disabled on the slider so horizontal drags do not scroll the page; keep enough space around it to scroll past.
  • Show the current value as text next to the label; it must not depend on hovering the thumb.

Content guidelines

  • Label: what is adjusted ('Discount', 'Price per night').
  • Show the value with its unit ('15%', '$20 to $80') and the range ends when they are not obvious.
  • Hint: the step and how to fine-tune with the keyboard when precision matters.

Alternatives

  • Input — Exact numeric entry with inputMode="numeric" or "decimal".
  • Radio group — A few named, discrete options.
  • Select — Named steps in a compact control.

Resources