Slider
A draggable track for choosing a number or a range.
@garn/ui/sliderDefault
A single-value slider with a label.
Sizing
Thumb/track scale — fixed --garn-box-* geometry; intentionally not affected by density (the handle is a hit target).
smmdlgStates
Interactive states, toggled live.
<Slider />State
Installation
garn is copy-in — the garn CLI writes this component's source into your project, so you own and can edit it. It resolves any base files and installs the npm dependencies below for you.
npx garn-ui add slider- Registry
slider- Source
- slider.tsx
- Deps
@radix-ui/react-sliderclass-variance-authority- Registry deps
utils
Import
import { Slider } from "@garn/ui/slider";Props
Generated from the component's TypeScript types.
size- Description
- No description.
- Type
"lg" | "md" | "sm"- Default
md
Plus 293 inherited native HTML attributes.
Styling
Target these data-slots and remap these tokens to restyle without forking the component.
[data-slot="slider"]| Property | Token | Tier |
|---|---|---|
thumbSize | --garn-box-md | semantic · identity |
ring | --garn-ringbrandable | semantic |
Private instance vars (never externalize): --st--tk
Overview
Slider lets a person pick a number — or a range, with one thumb per value — where the approximate position matters more than an exact figure: volume, brightness, a price band. The filled range gives instant feedback on how far along the value sits. When the precise number is what matters (a quantity, a price to the cent), a number field is clearer; for a few discrete choices, use a RadioGroup or Select.
Guidelines
Give the slider an accessible name and visible value. A bare track tells a screen-reader user nothing — wire a Label and surface the current value (a readout or tooltip) so the number isn't hidden in the handle position. For a range, label both thumbs ("minimum"/"maximum").
Match step and bounds to the real range. Choose a step that makes every reachable value sensible and set min/max to the true limits; arrow keys nudge by one step, so a too-fine step makes keyboard use tedious. Keep the track wide enough to be draggable on touch.
Don't use a slider for precision or for two states. Exact entry → a number input beside it; on/off → a Switch. Avoid long sliders where a 1px drag changes the value a lot — pair coarse dragging with keyboard fine-tuning.
Best practices
- Give the slider an accessible label; set sensible
min/max/step. - Pass two values for a range, and label each thumb.
- Show the current value nearby when the exact number matters.
- Don't use a slider when an exact value is required — pair it with a number input or use one.
- Don't leave it unlabeled.
- Don't use it to show progress — that's the progress bar.
Content guidelines
- Give the slider a label that names what it controls (“Volume”, “Price range”).
- Show the current value and units nearby when the exact number matters.
- Label the ends or each thumb when min/max or the handles aren't self-evident.
Accessibility
- Role
slider- ARIA APG
- slider
- Focus
- 1px ring on the focused thumb.
Enforceable contracts
Give the slider an accessible name (aria-label or a <label>).
when the Slider has no aria-label / aria-labelledby / associated <label>
Keyboard
| ArrowLeftArrowDown | Decrease by one step. |
| ArrowRightArrowUp | Increase by one step. |
| HomeEnd | Jump to min / max. |
| PageUpPageDown | Step by a larger increment. |
- • Each thumb is role=slider with aria-valuenow/min/max; give the control an accessible name (aria-label or a <label>).
- • For a range, label the thumbs (e.g. aria-label "Minimum"/"Maximum") so they're distinguishable.
- Status
- Stable
- Version
v0.3.0- Introduced
v0.1.0
garn doesn't yet record a per-release version history. This reflects the component's current lifecycle state; full changelog entries will appear once the metadata pipeline emits a lifecycle.history field.