Skip to content

Compass

Free

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.

  • Base UI
  • Motion
  • React 19
  • Tailwind CSS 4

Added Nov 22, 2026 · MIT + Commons Clause

Playground

Loading the preview

Props

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.

route-compass.tsx

Compass

<div>
PropTypeDefaultDescription
bearingnumber—The bearing set on the bezel, in degrees (read at the red index), controlled.
defaultBearingnumber0The first bearing, uncontrolled. Default 0.
onBearingChange—Each new bearing: a twist, a flick, a key.
onBearingCommitted—The end of a change: a release, the end of a flick, a key. Not on Escape.
headingnumber | 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.
tolerancenumberCOMPASS_TOLERANCEThe half width of "boxed", in degrees. Default 3.
position—The plate place on its host in px, controlled.
defaultPositionORIGIN
onPositionChange—The end of a move: a release or a key.
rotationnumber—The plate turn on its host, in degrees, controlled.
defaultRotationnumber0
onRotationChange—The end of a turn of the plate: a release or a key.
disabledbooleanfalse
readOnlybooleanfalseThe compass shows and can be focused, but a drag or a key changes nothing.
namestring—The form name of the bearing input.
formstring—
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

CompassBaseplate

<div>
PropTypeDefaultDescription
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

CompassBezel

<div>
PropTypeDefaultDescription
...props<div> attributes—Every other attribute goes to the <div>, with a ref.

CompassNeedle

<svg>
PropTypeDefaultDescription
...props<svg> attributes—Every other attribute goes to the <svg>, with a ref.

CompassHandle

<button>
PropTypeDefaultDescription
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"—
classNamestring—
busyboolean—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.
From Base UIButtonBase UI docs
focusableWhenDisabledbooleanfalseWhether the button should be focusable when disabled.
render—Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
style—Style applied to the element, or a function that returns a style object based on the component's state.
...props<button> attributes—Every other attribute goes to the <button>, with a ref.
  • 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.
  • For a heading-up phone compass with a target and a turn hint, use a Compass Dial.
  • For a plain angle in degrees, such as a gradient direction, use an Angle Dial.
Right ArroworUp ArrowOn the bezel: turns the bearing 1° up.
Left ArroworDown ArrowOn the bezel: turns the bearing 1° down.
Shiftarrow keysOn the bezel: turns the bearing to the next 15°.
Page UporPage DownOn the bezel: turns the bearing 45°.
HomeOn the bezel: sets the bearing to north.
EscapeStops a twist, a move, or a turn and puts the compass back.
Arrow keys on the handleMoves the compass 8 px (Shift: 40 px).
[ and ] on the handleTurns the compass 1° (Shift: 10°).
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

Built with

Installs with Compass

Components
Button,Input,Tooltip
  1. AddedCompass, with Button, Input, Tooltip.
Open the release