Keyframery

Slider

The thumb grows while you drag, the fill springs to new values and the digits roll.

See it as an AI agent does.

Resize preview. Focus the handle and use the left or right arrow keys. Hold Shift for larger steps.— px
Customize1 controls
Animation speed1×

Installation

npx shadcn@latest add @keyframery/slider

This adds components/keyframery/slider.tsx and its primitive to your project, and installs UI SDK. The motion tokens are added to your global CSS the first time you install a component.

Usage

import { Slider, SliderControl, SliderIndicator, SliderThumb, SliderTrack } from "@/components/keyframery/slider"

export default function Usage() {
  return (
    <Slider defaultValue={50} aria-label="Volume">
      <SliderControl>
        <SliderTrack>
          <SliderIndicator />
          <SliderThumb />
        </SliderTrack>
      </SliderControl>
    </Slider>
  )
}

Anatomy

How the parts fit together:

Slider
└── SliderControl
    └── SliderTrack
        ├── SliderIndicator
        └── SliderThumb

Examples

With a value

SliderValue shows the number, and format takes Intl.NumberFormat options.

Range

Pass two values for two thumbs. minStepsBetweenThumbs keeps them apart.

Vertical

orientation="vertical" stands it up, for an equaliser or a zoom control.

Motion

MoveWhat you see
PopThe thumb grows while you hold it.
SpringThe fill and thumbs travel on a spring when the value jumps.
RollThe value rolls to the new number.

Timing and springiness follow the motion style you set. To change how fast this slider moves, pass speed:

<Slider speed="fast">
  …
</Slider>

"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.

Theming

Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.

VariableWhat it changesDefault
--slider-trackEmpty track--muted; --accent in dark
--slider-fillFilled range--primary
--slider-thumbThumb face--background; foreground mixed with 8% background in dark
--slider-thicknessTrack thickness0.375rem
--slider-thumb-sizeThumb diameter1rem
--slider-radiusTrack and thumb corners9999px

API reference

Every part takes className and children. Parts from UI SDK also take render, to draw your own element, and a function of their state for className and style. Props not listed here are in the UI SDK slider reference.

Slider

Renders a <div>, and takes its props too.

Prop

Type

SliderThumb

Renders a <div>, and takes its props too.

Prop

Type

Other parts

These take the props of the element they render, and nothing else:

  • SliderControl: a <div>
  • SliderTrack: a <div>
  • SliderIndicator: a <div>
  • SliderValue: a <output>

Keyboard

KeyWhat it does
← →Moves the focused thumb a step.
Shift + ←Moves ten steps at a time.
Page UpMoves ten steps.
HomeMoves to the minimum.
EndMoves to the maximum.

Accessibility

Keyboard, focus and screen-reader behaviour come from UI SDK and are not changed. More in Accessibility.

Swap the import

Already using UI SDK's slider with your own styles? Keep your markup and change one line. The primitive adds motion and nothing else.

// Before
import { … } from "@ui-sdk/react/slider"

// After: same parts, same props, now animated
import { … } from "@/components/keyframery/primitives/slider"

Questions

How does the animated Slider for UI SDK move?

Pop: The thumb grows while you hold it. Spring: The fill and thumbs travel on a spring when the value jumps. Roll: The value rolls to the new number.

Do I need Motion or Framer Motion for the animated Slider?

No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.

Can I keep my own styling and only take the motion?

Yes. Import from @/components/keyframery/primitives/slider instead. It has the same parts and props as @ui-sdk/react/slider and adds motion only.

What happens to the Slider when someone turns on reduced motion?

Nothing moves. State changes happen at once, or with a short fade.

All components

On this page