GooseUI

Components

Slider


Range slider input component with customizable styling

Slider uses a native range input with min, max, step, name and disabled. It supports three sizes, controlled or uncontrolled values, and an optional formatted value label. Use it for selecting a number from a range; Input is better when an exact value needs to be typed.

Browser Support

color-mix()

Colors the hover halo around the thumb.

Your browser:

Preview

Drag the slider to change the value.

53%
Small
Medium
Large
Step: 25
50

Installation

npx shadcn@latest add @gooseui/slider
pnpm dlx shadcn@latest add @gooseui/slider
yarn dlx shadcn@latest add @gooseui/slider
bunx --bun shadcn@latest add @gooseui/slider

Usage

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

export default function Example() {
  const [value, setValue] = useState(50)

  return (
    <Slider
      value={value}
      onValueChange={setValue}
      min={0}
      max={100}
    />
  )
}

Examples

With Value Display

Show the current value next to the slider with custom formatting.

75%
<Slider
  value={value}
  onValueChange={setValue}
  showValue
  formatValue={(v) => `${v}%`}
/>

Animated Sliding Value

Use animateValue for smooth digit transitions powered by SlidingNumber.

50%
<Slider
  value={value}
  onValueChange={setValue}
  showValue
  animateValue
  formatValue={(v) => `${v}%`}
/>

Size Variants

Three size variants: small, medium (default), and large.

Small
Medium (default)
Large
<Slider size="sm" defaultValue={30} />
<Slider size="md" defaultValue={50} />
<Slider size="lg" defaultValue={70} />

Step Increments

Control the step size for discrete value selection.

50

Step: 10 (values: 0, 10, 20, ... 100)

<Slider
  min={0}
  max={100}
  step={10}
  showValue
/>

Custom Formatting

Use formatValue to display units like temperature or currency.

Temperature
22°C
Price Range
$150
<Slider
  min={16}
  max={30}
  showValue
  formatValue={(v) => `${v}°C`}
/>

<Slider
  min={0}
  max={500}
  step={10}
  showValue
  formatValue={(v) => `$${v}`}
/>

Custom Gradient Track

Set the --slider-track, --slider-fill and --slider-thumb CSS variables on the wrapper to restyle the slider.

50

Custom gradient track using CSS overrides

/* Any background works for the track */
.gradient-slider {
  --slider-track: linear-gradient(
    to right,
    var(--chart-1),
    var(--chart-2),
    var(--chart-3),
    var(--chart-4),
    var(--chart-5)
  );
  --slider-fill: transparent;
}

<Slider className="gradient-slider" />

Disabled State

Disabled slider with reduced opacity and non-interactive state.

<Slider defaultValue={40} disabled />

Props

PropTypeDefaultDescription
valuenumber-Controlled value
defaultValuenumber50Default value for uncontrolled mode
minnumber0Minimum value
maxnumber100Maximum value
stepnumber1Step increment
onValueChange(value: number) => void-Callback when value changes
showValuebooleanfalseShow value label next to slider
animateValuebooleanfalseAnimate value with sliding digits (requires showValue)
formatValue(value: number) => stringString(v)Custom value formatter
size"sm" | "md" | "lg""md"Slider size
disabledbooleanfalseDisabled state
labelstring-Accessible label for screen readers (aria-label)
namestring-Field name, so the value goes to FormData
classNamestring-Additional CSS classes

Features

  • Pure CSS — no external animation or UI libraries required
  • Cross-browser — works in Chrome, Firefox, Safari, Edge via vendor prefixes
  • Progress fill — CSS only: border-image on the thumb in WebKit, ::-moz-range-progress in Firefox
  • Keyboard accessible — full arrow key and focus support
  • ARIA attributes — aria-valuemin, aria-valuemax, aria-valuenow, aria-valuetext
  • Customizable — size variants, custom formatting, gradient tracks
  • Animated values — optional SlidingNumber integration for smooth digit transitions
  • Controlled & uncontrolled — works with value/onValueChange or defaultValue