Skip to content
Haze UI

Compare slider

A draggable and keyboard-operable divider that reveals two versions of the same visual.

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

When to use

  • Before and after images share the same dimensions and alignment
  • A change is easier to see by revealing different portions of two views

When not to use

  • Both views have interactive elements or must remain fully visible.
  • Readers need to compare independent rows of facts. Use table.

Installation

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

pnpm dlx shadcn@latest add @haze/compare-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–Unique ID for the native range input.
labelstring"Layout comparison"Heading for the comparison.
beforeLabelstring"Before"Name of the first visual.
afterLabelstring"After"Name of the second visual.
sliderLabelstring"Visible share of the first panel"Visible and accessible range label.
valuenumber50Initial percentage of the first visual, clamped to 0 through 100.
headingLevel2 | 3 | 4 | 5 | 62Heading level for the title.
before slotslot–The first visual or read-only preview.
after slotslot–The second visual with the same proportions.
classstring–Additional classes on the comparison section.

Keyboard interactions

Left or Right
Move the divider by one percentage point.
Home or End
Reveal a full panel.

Accessibility

  • The range has an accessible name and announces the visible percentage of the first visual.
  • Provide descriptions or alt text for both visuals, and keep interactive controls outside the clipped panels.
  • With scripts unavailable, both labelled panels are shown in order.

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 "Compare slider" with `npx shadcn@latest add @haze/compare-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 CompareSlider from "@/components/haze/ui/compare-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/compare-slider.md

  • Customize with real content

    Adapt the Haze compare-slider ui for our product. Replace the demo values of these props with our real content: id, label, beforeLabel, afterLabel, sliderLabel, value, headingLevel, before slot, after slot, class. Keep the layout, the heading level rules and these accessibility details: The range has an accessible name and announces the visible percentage of the first visual. Provide descriptions or alt text for both visuals, and keep interactive controls outside the clipped panels. With scripts unavailable, both labelled panels are shown in order. Do not add raw color classes; use the Haze tokens.

  • Choose the right block

    Before using compare-slider, check it fits: use it when before and after images share the same dimensions and alignment; a change is easier to see by revealing different portions of two views. Avoid it when both views have interactive elements or must remain fully visible.; readers need to compare independent rows of facts. use table.. Alternatives: @haze/slider, @haze/table.

Dependencies

  • npm: @lucide/astro
  • @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