---
title: "Compass"
description: "A clear baseplate compass on a map: drag it to move, turn it by its handle, and twist or flick the bezel to set a bearing."
url: https://gelatinui.com/components/compass
markdown_url: https://gelatinui.com/components/compass.md
access: free
install: "npx shadcn@latest add @gelatin-ui/compass"
registry_item: https://gelatinui.com/r/compass.json
version: "2026-11-22"
index: https://gelatinui.com/llms.txt
docs_index: https://gelatinui.com/docs/llms.txt
---

# Compass

> A clear baseplate compass on a map: drag it to move, turn it by its handle, and twist or flick the bezel to set a bearing.

Page: https://gelatinui.com/components/compass

## When to use it

Best for: Set a bearing on a map with a baseplate compass that people move, turn, and twist as they do a real one.

- Use it over a north-up map: with no `heading`, the needle points up the screen while the plate turns.
- Use `heading` with a value from `useDeviceHeading`, a GPS course, or a track, for a live needle.
- Use `onBearingCommitted` to save a bearing once per gesture, and `onPositionChange` and `onRotationChange` to keep the place and the turn.
- Use `name` to send the bearing with a form.

## When not to use it

- For a heading-up phone compass with a target and a turn hint, use a [Compass Dial](https://gelatinui.com/components/compass-dial.md).
- For a plain angle in degrees, such as a gradient direction, use an [Angle Dial](https://gelatinui.com/components/angle-dial.md).

## Notes for agents

- Compose it from `CompassBaseplate`, `CompassBezel`, `CompassNeedle`, and `CompassHandle`, in this order. With no children it renders all four. Leave out `CompassHandle` for a compass that only takes a bearing.
- Give it a host with `position: relative` and place it with `className="absolute"` and `left` and `top`: `position` is a px offset from that place.
- `heading` has three states: no value (north-up map, the needle follows the plate turn), a number (a live heading), and `null` (no reading: the needle parks and greys out).
- `onBearingChange` runs on each step of a twist or a flick. `onBearingCommitted` runs once at the end of a gesture or on a key, not on Escape.
- `data-aligned` is on the root when the needle sits in the orienting arrow (within `tolerance`, 3° by default).
- A hidden range input on the bezel holds the focus and the form value, so the bearing works as a native slider.

## Anatomy

```text
Compass
├─ CompassBaseplate (0..n)
├─ CompassBezel (0..n)
├─ CompassNeedle (0..n)
└─ CompassHandle (0..n)
```

## API reference

### Compass

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `bearing` | `number` |  | The bearing set on the bezel, in degrees (read at the red index), controlled. |
| `defaultBearing` | `number` | 0 | The first bearing, uncontrolled. Default 0. |
| `onBearingChange` | `function` |  | Each new bearing: a twist, a flick, a key. |
| `onBearingCommitted` | `function` |  | The end of a change: a release, the end of a flick, a key. Not on Escape. |
| `heading` | `number \| null` |  | Where the plate faces, in degrees from north: the needle points to north from it. No value: the compass lies on a north-up map, so the needle points up the screen as the plate turns. `null`: no heading (a sensor with no reading); the needle parks. |
| `tolerance` | `number` | COMPASS_TOLERANCE | The half width of "boxed", in degrees. Default 3. |
| `position` | `CompassPosition` |  | The plate place on its host in px, controlled. |
| `defaultPosition` | `CompassPosition` | ORIGIN |  |
| `onPositionChange` | `function` |  | The end of a move: a release or a key. |
| `rotation` | `number` |  | The plate turn on its host, in degrees, controlled. |
| `defaultRotation` | `number` | 0 |  |
| `onRotationChange` | `function` |  | The end of a turn of the plate: a release or a key. |
| `disabled` | `boolean` | false |  |
| `readOnly` | `boolean` | false | The compass shows and can be focused, but a drag or a key changes nothing. |
| `name` | `string` |  | The form name of the bearing input. |
| `form` | `string` |  |  |

### CompassBaseplate

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### CompassBezel

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### CompassNeedle

No props of its own: `className`, `children`, and every other prop go to the element it renders.

### CompassHandle

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `glass` | `"clear" \| "dark" \| "light"` |  |  |
| `rounded` | `"default" \| "full"` |  |  |
| `size` | `"default" \| "icon" \| "icon-lg" \| "icon-sm" \| "icon-xs" \| "lg" \| "sm" \| "xl" \| "xs"` |  |  |
| `variant` | `"dashed" \| "default" \| "destructive" \| "destructive-outline" \| "ghost" \| "link" \| "media" \| "outline" \| "secondary"` |  |  |
| `className` | `string` |  |  |
| `busy` | `boolean` |  | The button waits for the app (busy words): a spinner, `aria-busy`, and no clicks. Focus stays on the button. The style hook stays `data-loading`. |
| `spinnerPlacement` | `"center" \| "start"` |  | `center` (default): the spinner covers the label. `start`: it takes the leading icon slot. The icon sizes always use `center`, because their one icon is the label. |

Also takes every prop of Base UI `Button`: https://base-ui.com/react/components/button

## Styling

| Part | Slot | States | CSS variables | Tokens |
| --- | --- | --- | --- | --- |
| Compass | `compass` | `data-aligned`, `data-disabled`, `data-dragging`, `data-focus-visible`, `data-moving`, `data-parked`, `data-readonly` | `--compass-turn` | `hit-area`, `motion-timing`, `status-colors` |
| CompassBaseplate | `compass-baseplate` | `data-aligned`, `data-disabled`, `data-dragging`, `data-focus-visible`, `data-moving`, `data-parked`, `data-readonly` | `--compass-turn` | `hit-area`, `motion-timing`, `status-colors` |
| CompassBezel | `compass-bezel` | `data-aligned`, `data-disabled`, `data-dragging`, `data-focus-visible`, `data-moving`, `data-parked`, `data-readonly` | `--compass-turn` | `hit-area`, `motion-timing`, `status-colors` |
| CompassNeedle | `compass-needle` | `data-aligned`, `data-disabled`, `data-dragging`, `data-focus-visible`, `data-moving`, `data-parked`, `data-readonly` | `--compass-turn` | `hit-area`, `motion-timing`, `status-colors` |
| CompassHandle | `compass-handle` | `data-aligned`, `data-disabled`, `data-dragging`, `data-focus-visible`, `data-moving`, `data-parked`, `data-readonly` | `--compass-turn` | `hit-area`, `motion-timing`, `status-colors` |

## Usage

Put the compass on a map host with `position: relative`. Drag the plate, turn it by the handle, and twist the bezel to set a bearing.

```tsx title="route-compass.tsx"
import {
  Compass,
  CompassBaseplate,
  CompassBezel,
  CompassHandle,
  CompassNeedle,
} from "@/components/controls/compass";

export function RouteCompass() {
  return (
    <div className="relative h-[640px] w-[960px] overflow-hidden rounded-3xl bg-muted">
      <Compass
        aria-label="Bearing to the summit"
        defaultBearing={48}
        defaultRotation={48}
        className="absolute"
        style={{ left: 430, top: 100 }}
      >
        <CompassBaseplate />
        <CompassBezel />
        <CompassNeedle />
        <CompassHandle aria-label="Move or turn the compass" />
      </Compass>
    </div>
  );
}
```

## 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/compass
```

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

## Built on

- [Button](https://gelatinui.com/components/button.md)
- [Input](https://gelatinui.com/components/input.md)
- [Tooltip](https://gelatinui.com/components/tooltip.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

- [Compass Dial](https://gelatinui.com/components/compass-dial.md): Pick Compass Dial for a heading-up phone compass that shows which way to turn to a target.
- [Angle Dial](https://gelatinui.com/components/angle-dial.md): Pick Angle Dial to set any angle in degrees with a plain round dial.
- [Slider](https://gelatinui.com/components/slider.md)

## Keyboard

| Keys | Action |
| --- | --- |
| Right Arrow, Up Arrow | On the bezel: turns the bearing 1° up. |
| Left Arrow, Down Arrow | On the bezel: turns the bearing 1° down. |
| Shift + arrow keys | On the bezel: turns the bearing to the next 15°. |
| Page Up, Page Down | On the bezel: turns the bearing 45°. |
| Home | On the bezel: sets the bearing to north. |
| Escape | Stops a twist, a move, or a turn and puts the compass back. |
| Arrow keys on the handle | Moves the compass 8 px (Shift: 40 px). |
| [ and ] on the handle | Turns the compass 1° (Shift: 10°). |

## Motion

| Part | Motion |
| --- | --- |
| Needle | sway · the needle swings past north and settles in shorter swings |
| Bezel | glide · a fast flick spins the bezel on and lands on a whole degree |
| Plate | press · a moving plate lifts on a deeper shadow |
