Skip to content
Primitives

Slider

Track with a sharp block thumb and a signal range.

● LIVE
npx shadcn@latest add https://okibi.cndr.dev/r/slider.json

Installation

Install the theme first, then add the component:

npx shadcn@latest add https://okibi.cndr.dev/r/slider.json

Install the required dependencies:

npm install @radix-ui/react-slider

Copy the source from the Code tab above into components/ui/slider.tsx. It uses the cn helper and the okibi theme tokens — install the theme first if you haven't.

Usage

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

<Slider defaultValue={[50]} max={100} step={1} />

Examples

Range

Pass two values in defaultValue to render two thumbs and select a range between them.

● LIVE

Disabled

disabled locks the thumb and dims the track.

● LIVE

Vertical

Set orientation="vertical" inside a fixed-height track; give the thumb an aria-label.

● LIVE

Accessibility

  • Built on Radix Slider.Root, so each thumb is a role='slider' with aria-valuemin / max / now; arrow keys step, Home / End jump to bounds.
  • Thumbs carry no visible text — pass aria-label (or aria-labelledby); a two-thumb range with no label defaults to 'Minimum' / 'Maximum'.
  • aria-label / aria-labelledby accept a string (labels every thumb) or an array (labels each thumb positionally).
  • aria-invalid on the root propagates via group/slider to the track, range, and thumb destructive styling.
  • Focus shows the 2px signal ring on the thumb (focus-visible:ring-2 ring-ring ring-offset-2).
  • Supports orientation='vertical'; disabled is disabled:opacity-60, and drag/transition use the fast token (no spring).

Guidelines

Do

  • Give every thumb an aria-label, and distinct labels for the two thumbs of a range.
  • Pass value/defaultValue as an array — [50] for single, [20, 80] for a range.
  • Set min, max, and step so keyboard stepping lands on meaningful values.

Don't

  • Don't render a bare Slider and expect a single thumb — supply defaultValue explicitly.
  • Don't use a slider where a precise number matters more than the gesture — pair it with an input or use a field.
  • Don't omit thumb labels on a range; the screen reader would announce only the number.

On this page