Skip to content

shadcn.io is an independent project built on shadcn/ui

Free

Brightness Control Slider for React

A Brightness slider at 80% with a sun icon, a warning-colored fill, and the percentage beside the label.

A sun icon, the word Brightness, and 80% share the row above the track. The filled range uses the warning color.

Use it in display or camera settings. A Switch is enough when the screen is only on or off. In React, Base UI does not draw the sun.

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.
Use email insteadNo credit card

Anatomy

Slider anatomy: root, label, value, track, range, thumb

Usage

<div className="flex w-full max-w-md flex-col gap-2">
  <div className="flex items-center justify-between">
    <div className="flex items-center gap-2">
      <SunIcon aria-hidden="true" className="size-4" />
      <Label>Brightness</Label>
    </div>
    <span className="text-muted-foreground text-sm tabular-nums">
      {value[0]}%
    </span>
  </div>
  <Slider
    aria-label="Brightness"
    className="[&_[data-slot=slider-range]]:bg-warning [&_[data-slot=slider-thumb]]:border-warning"
    onValueChange={handleValueChange}
    value={value}
  />
</div>

FAQ

How is the fill colored?

The slider's class sets bg-warning on the part with data-slot="slider-range" and border-warning on the thumb. It follows the theme, light or dark.

How does the readout follow the thumb?

The value lives in state, starting at 80, 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.

Is the sun icon announced?

No. It has aria-hidden="true"; the Brightness label and the slider's aria-label carry the meaning.

What range does it cover?

0 to 100, read as 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 brightness?

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.

API Reference

Label

No extra props in this demo. The rest is on the Label page.

Slider

Sets aria-label="Brightness", onValueChange={handleValueChange} and value={value}. The rest is on the Slider page.