Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Slider examples · Styled

With Tooltip Slider for React

A Progress slider with a bubble above the thumb that shows its percentage.

Framework
UI library

The value rides along with the thumb. A small bubble above the track is placed at the same percentage as the value, so it follows the thumb as it moves. Use it where people watch the number while they drag.

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

Is this a Tooltip component?

No. The bubble is a div in a relative pt-6 wrapper, absolute -top-2 with bg-primary and text-primary-foreground. It is always visible and aria-hidden, since the slider already announces its value.

How does the bubble follow the thumb?

Its inline start is set to the value as a percent, and -translate-x-1/2 centers it on that point. It moves on every step, while you drag or use the keys.

How does the readout follow the thumb?

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

What happens to the bubble at 0% and 100%?

The bubble is placed by the raw percent, so near the ends half of it hangs past the track, and it can sit slightly off the thumb. Clamp the position if that matters in your layout.

How is the slider named?

The Progress 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 percent on?

0 to 100, which matches the percent used for the position. min and max set the ends.