Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Slider examples · Styled

Colored Slider for React

A Success Rate slider whose fill and thumb border use the success color.

Framework
UI library

Color can say what a value means. The fill and the thumb's border use the theme's success color, and the percentage sits beside the label. Use it where the color carries a status.

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 is it colored?

The slider's class sets bg-success on the part with data-slot="slider-range" and border-success on the part with data-slot="slider-thumb". Both follow the theme.

How does the readout follow the thumb?

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

How do I use another color?

Swap the tokens, such as bg-destructive or bg-warning. Keep to theme tokens so dark mode still works.

How is the slider named?

The Success Rate 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 range does it cover?

0 to 100. 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.