---
title: "Ruler Slider"
description: "Pick a value on a moving scale: the ticks slide under a fixed line, as in a photo editor. Drag or flick the ruler, and double-click to reset."
url: https://gelatinui.com/components/ruler-slider
markdown_url: https://gelatinui.com/components/ruler-slider.md
access: pro
install: "npx shadcn@latest add @gelatin-ui-pro/ruler-slider"
version: "2026-11-10"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Ruler Slider

> Pick a value on a moving scale: the ticks slide under a fixed line, as in a photo editor. Drag or flick the ruler, and double-click to reset.

Page: https://gelatinui.com/components/ruler-slider

## When to use it

Best for: Pick a value on a moving scale: the ticks move under a fixed line, for an angle or a zoom.

- Use it for an angle, exposure, white balance, or zoom.
- Use `variant` `straight`, `arc`, or `vertical` for the shape.
- Use `origin` for the value that holds the drag and shows a dot.
- Use `onMovingChange` to show something while the ruler moves, such as a grid.

## When not to use it

- To jump to a point on a fixed track, or to pick a range, use a [Slider](https://gelatinui.com/components/slider.md).
- To show a measured value, use a [Meter](https://gelatinui.com/components/meter.md).

## Notes for agents

- `min` and `max` default to -45 and 45. Set them for any other range.
- A drag moves the value by the pointer distance, never to the press point.
- `onValueChange` also runs during a drag and a flick. Use `onValueCommitted` for the final value.
- The children go in the header. With no children, a centered `RulerSliderValue` shows.
- With no `RulerSliderLabel`, pass `aria-label`.
- `labels` does not work on `vertical`. The arc is made for up to 250 ticks.
- A double-click or `RulerSliderValue` resets to `resetValue`.
- `name` sends the value with a form.
- `readOnly` shows and follows a controlled `value`, but takes no input.

## Anatomy

```text
RulerSlider
├─ RulerSliderLabel (0..n)
└─ RulerSliderValue (0..n)
```

## API reference

### RulerSlider

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `number` |  |  |
| `defaultValue` | `number` |  |  |
| `onValueChange` | `function` |  | A value change, from a drag, a flick, a key, a reset, or Escape (`cancel`). |
| `onValueCommitted` | `function` |  | The value at the end of a drag (after the flick), a key press, or a reset. |
| `onMovingChange` | `function` |  | `true` from the press until a flick stops: a host can show a grid while the ruler moves. |
| `min` | `number` | -45 | Default `-45`. |
| `max` | `number` | 45 | Default `45`. |
| `step` | `number` | 1 | The value grid and the arrow-key step. Default `1`. |
| `largeStep` | `number` |  | Shift + arrow and Page Up or Down. Default 10 steps. |
| `tickStep` | `number` |  | The value of one tick (6px). Default: `step`. |
| `majorEvery` | `number` | 5 | A major (long) tick each this many ticks, counted from 0. Default `5`. |
| `origin` | `number \| "center" \| "start"` | "center" | The value with the dot, where a drag holds for 6px: `center` (0, kept inside the range), a number, or `start` (no dot; the span grows from `min`). Default `center`. |
| `resetValue` | `number` |  | The value of a reset. Default: `defaultValue`, else the origin. |
| `labels` | `boolean \| ((value: number) => string)` |  | Numbers on the ticks: `true` (the formatted value), or a function. Not on `vertical`. The arc is made for up to 250 ticks: past half a turn of its circle the ticks overlap. |
| `labelEvery` | `number` |  | A label each this many ticks. Default `majorEvery × 2`. |
| `variant` | `RulerSliderVariant` | "straight" | `straight` (default), `arc` (a curved ruler), or `vertical` (higher values up). |
| `size` | `RulerSliderSize` | "default" |  |
| `format` | `NumberFormatOptions` |  | The number format of the value, the labels, and `aria-valuetext`. |
| `locale` | `LocalesArgument` |  |  |
| `disabled` | `boolean` | false |  |
| `readOnly` | `boolean` | false | The value shows and follows a controlled `value`, but takes no input. |
| `invalid` | `boolean` |  | Shown as invalid (an invalid `Field` around it does the same). |
| `name` | `string` |  |  |
| `form` | `string` |  |  |
| `aria-label` | `string` |  | The name of the slider when there is no `RulerSliderLabel`. |
| `getAriaValueText` | `function` |  | The spoken value. Default: the formatted value. |

### RulerSliderLabel

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  |  |

### RulerSliderValue

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `function` |  | The text: the formatted value by default. Return a unit around it ("5600 K"). |

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| RulerSlider | `ruler-slider` | `aria-disabled`, `data-at-reset`, `data-disabled`, `data-invalid`, `data-moving`, `data-orientation`, `data-part`, `data-readonly` | `--ruler-slider-ink` | `hit-area`, `motion-timing` |
| RulerSliderLabel | `ruler-slider-label` |  |  |  |
| RulerSliderValue | `ruler-slider-value` |  |  |  |

## Usage

Put a `RulerSliderLabel` and a `RulerSliderValue` in the header; the label names the slider, and a press on the value resets it.

```tsx title="straighten-ruler.tsx"
import { RulerSlider, RulerSliderLabel, RulerSliderValue } from "@/components/ui/pro/ruler-slider";

const DEGREES: Intl.NumberFormatOptions = { style: "unit", unit: "degree", unitDisplay: "narrow" };

export function StraightenRuler({ onStraighten }: { onStraighten: (angle: number) => void }) {
  return (
    <RulerSlider
      defaultValue={-7}
      majorEvery={5}
      format={DEGREES}
      onValueCommitted={(angle) => {
        onStraighten(angle);
      }}
    >
      <RulerSliderLabel>Straighten</RulerSliderLabel>
      <RulerSliderValue />
    </RulerSlider>
  );
}
```

## Compose

Rules:

- Compose the parts (`compose-parts`): Build each item from its named parts as children, and pass your text and icons in as parts.
- Every state is designed (`every-state`): Give each view of data its loading, empty, and error states: a skeleton in the final layout, an `Empty` with an illustration and one next action, and an error that says what failed and how to retry.

## Add it

```bash
npx shadcn@latest add @gelatin-ui-pro/ruler-slider
```

It adds 37 registry items: 33 files, 6498 lines, and the npm packages `@base-ui/react`, `@xstate/react`, `clsx`, `motion`, `tailwind-merge`, `tailwind-variants`, `xstate`.

## Built on

- [Direction](https://gelatinui.com/components/direction.md)
- [Slider](https://gelatinui.com/components/slider.md)

## For AI agents

- Every item, one file: https://gelatinui.com/llms.txt
- MCP server (`search_items`, `get_item`, `get_install_plan`): https://gelatinui.com/mcp

## Related

- [Slider](https://gelatinui.com/components/slider.md): Pick Slider to jump to a point on a fixed track, or to pick a range with two thumbs.
- [Image Cropper](https://gelatinui.com/components/image-cropper.md)
- [Field](https://gelatinui.com/components/field.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Arrow keys | Changes the value by one `step`. |
| Shift + arrow keys, Page Up, Page Down | Changes the value by `largeStep`. |
| Home, End | Goes to the minimum or the maximum. |
| Delete, Backspace | Resets the value. |
| Escape | During a drag: cancels the drag and restores the value. |

## Accessibility

It uses a native range input, so the arrow keys step the value and a form can read it with `name`.

The touch target stays 44px high.

No mirror in right to left: more stays to the right, and only the label and the value swap.

The fixed red line marks the value; it turns to the destructive color when the ruler is invalid.

## Motion

| Part | Motion |
| --- | --- |
| Hover | hover · the ticks go from 67% to full on hover, focus, and drag |
| Press | elastic · the ticks grow 15% while held and spring back with one small wobble |
| Release | glide · a key, a reset, or a new value glides the ruler to its tick with the speed it has |
| Origin dot | statusPop · the dot grows when the value lands on the origin |
