Skip to content

Slider

Pick a value or a range by dragging or with the keyboard: steps, marks, a value bubble and Field-style label.

On this page
Used for
  • Temperature setting
  • Token limit
  • Price range
  • Confidence threshold

Examples

Installation

npx knowns-ui@latest add slider
For Claude Code, Cursor or Codex: installs it and wires the props to your own data.

Props

value / defaultValue
number | [number, number]
Defaultmin / [min, max]
A number gives one thumb, a pair gives a range.
onValueChange
(value) => void
Every change while dragging or pressing keys.
onValueCommit
(value) => void
Once per gesture: on release, or after each key press. Good for saving.
min / max / step
number
Default0 / 100 / 1
Values snap to the step grid that starts at min.
largeStep
number
Default10 × step
PageUp / PageDown jump.
size
"sm" | "md"
Default"md"
Track and thumb size; the hit area stays generous, more so on touch screens.
marks
(number | { value, label? })[]
Ticks on the track; labelled ones show their label underneath.
tooltip
boolean | "always"
Defaultfalse
Value bubble over the thumb while dragging or focused from the keyboard, or all the time.
formatValue
(v: number) => string
DefaultString
Text for the bubble, the readout and screen readers (aria-valuetext).
label / hint
ReactNode
Field-style label with the value on the right, and a muted line underneath.
hideValue
boolean
Defaultfalse
Hide the readout next to the label.
aria-label
string
Name when there is no label.
thumbLabels
[string, string]
Default["Minimum", "Maximum"]
Names of the two thumbs in a range.
name
string
Hidden inputs for forms: name, or name[0] and name[1] for a range.
disabled
boolean
Defaultfalse
Dims the slider and ignores input.

What it handles

  1. 01Picks one number or a from and to pair, decided by whether value or defaultValue is a number or an array, and keeps range thumbs from crossing.
  2. 02Snaps every value to the step grid that starts at min, so a step of 0.1 gives 0.3 and not 0.30000000000000004.
  3. 03Moves by pointer drag or a click on the track, picking the closest thumb, and by key: arrows one step, PageUp and PageDown by largeStep, Home and End to the ends.
  4. 04Calls onValueChange on every change and onValueCommit once per gesture, on release or after each key press.
  5. 05Shows tick marks with optional labels, a value bubble over the thumb while dragging or on keyboard focus or always, and a readout next to the label that formatValue controls.
  6. 06Names each range thumb for screen readers through thumbLabels, and submits one hidden input per thumb when name is set.

States

First render
Nothing. The fill and the thumbs paint at their values
none
Dragging
The active thumb grows to 110% and rises above the other
120ms, ease out
Value bubble
The bubble fades in and rises 4px above the thumb while dragging or focused from the keyboard
120ms, ease out
Value change
The fill and the thumb follow the pointer or the key with no easing
none, at once
Tick marks
A tick changes colour as the fill passes it
120ms, ease out
Disabled
The whole slider dims and takes no input
none, at once
Reduced motion
The thumb scale and the bubble change at once
0ms

Works with

When to use

When to use

  • Choosing a value or range where the rough position matters more than the exact number.

When not to use

  • Exact values such as prices or IDs: use Input.

Using with AI

Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:

  • Add the Knowns UI Slider to my app and wire it to my own data.
  • I need choosing a value or range where the rough position matters more than the exact number. Set that up with the Knowns UI Slider.
  • Which Slider props do I need for a minimal setup? Show me a short example.

With the server connected, your assistant calls get_component({ name: "slider" }) and search_docs({ query: "slider" }).

Need help?

Stuck on Slider, or found something off? We read every message.