Skip to content
Haze UI

Slider

Native range input over a thin track with a filled part and a round thumb; a small script keeps the fill current.

pnpm dlx shadcn@latest add @haze/slider
Open preview in a new tab
Livesmall script

When to use

  • Picking an approximate value on a bounded scale, such as quality or volume
  • Settings where the exact number matters less than direction and size

When not to use

  • The user must type an exact value; use input with type number
  • A choice from a few named steps; use radio-group or toggle-group

Installation

Add the Haze registry to components.json once, then install Slider with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.

pnpm dlx shadcn@latest add @haze/slider
First time? Registry and theme setup

1. Add to components.json:

{
  "registries": {
    "@haze": "http://localhost:4329/r/{name}.json"
  }
}

2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";

API reference

PropTypeDefaultDescription
id*string–Input id; reference it from a label or Field.
namestringidForm field name.
minnumber0Lowest value.
maxnumber100Highest value.
stepnumber1Increment between values.
valuenumber50Initial value.
disabledboolean–Dims the slider and blocks input.
classstring–Extra classes on the wrapper around the track and input.
...restattributes–Any other input attribute, for example aria-valuetext or aria-describedby.

Keyboard interactions

Arrow LeftArrow Down
Decreases the value by one step
Arrow RightArrow Up
Increases the value by one step
HomeEnd
Jumps to the minimum or maximum
Page UpPage Down
Changes the value by a larger step

Accessibility

  • The browser exposes the value to assistive technology; add aria-valuetext when the number needs units, such as "80 percent".
  • Under forced colors the custom track and fill are hidden and the native range control is used, so the track and thumb stay visible.
  • The track and fill are aria-hidden divs behind the input; the input stays the only control. Without script the fill is hidden and the track shows no filled part.
  • The control shows no number. Print the value next to it if exact values matter, because a thumb position alone is hard to read precisely.
  • The thumb is 16 px with a 24 px tall hit area on the input, which meets the minimum target size.

Notes for AI

Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.

  • Install and use

    Install the Haze UI component "Slider" with `npx shadcn@latest add @haze/slider`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Slider from "@/components/haze/ui/slider.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/slider.md

  • Customize with real content

    Adapt the Haze slider ui for our product. Replace the demo values of these props with our real content: id, name, min, max, step, value, disabled, class, ...rest. Keep the layout, the heading level rules and these accessibility details: The browser exposes the value to assistive technology; add aria-valuetext when the number needs units, such as "80 percent". Under forced colors the custom track and fill are hidden and the native range control is used, so the track and thumb stay visible. The track and fill are aria-hidden divs behind the input; the input stays the only control. Without script the fill is hidden and the track shows no filled part. The control shows no number. Print the value next to it if exact values matter, because a thumb position alone is hard to read precisely. The thumb is 16 px with a 24 px tall hit area on the input, which meets the minimum target size. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using slider, check it fits: use it when picking an approximate value on a bounded scale, such as quality or volume; settings where the exact number matters less than direction and size. Avoid it when the user must type an exact value; use input with type number; a choice from a few named steps; use radio-group or toggle-group. Alternatives: @haze/input, @haze/toggle-group, @haze/field.

Dependencies

  • @haze/utils
  • @haze/theme (one-time setup)

Source · Original Haze UI work.

Catalog

↑↓ moveEnter openEsc close

Keyboard shortcuts

CtrlK
Command palette
/
Focus search
←↑→↓
Move between cards
jk
Next / previous card
ci
Copy code / install command (detail page)
[]
Previous / next entry
?
This help
Esc
Close dialog