Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Slider examples · Standard

Slider with Value Display for React

A Quality slider with its percentage shown beside the label as it moves.

Framework
UI library

People see the exact number while they drag. The Quality label and the percentage share a row above the track, and the percentage updates with every step. Use it when the number matters as much as the position.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

How does the readout follow the thumb?

The value lives in state, starting at 65, and goes back to the slider as value. The percentage beside the label prints the first value with a % sign. onValueChange receives the new value, and the handler stores it as an array.

How are the label and number placed?

In a flex items-center justify-between row above the slider. The number is muted and uses tabular-nums, so it keeps its width as digits change.

How is the slider named?

The Quality text is a visible Label, and the slider gets the same name with aria-label, so screen readers announce what it sets. On Base UI, aria-label is one string on the slider.

What scale is the percentage on?

0 to 100 in steps of 1, so the value is already a percentage. min and max set the ends.

Can I move it from the keyboard?

Yes. The thumb takes focus with Tab. The arrow keys move it by one step, Page Up and Page Down by a larger step, and Home and End jump to the ends.

When should I save the quality?

The change callback runs on every step while the thumb moves. Save or fetch from the end-of-change callback, which runs once when dragging stops. On Base UI it is onValueCommitted.