Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Dock for Radix UI

A macOS-style dock for React and Radix UI: icons that grow as the pointer nears, with hover labels, open-app dots and arrow-key focus.

On this page9 sections

Dock is a row of icons on a shelf that grow as the pointer passes over them and spread apart to make room, the way the macOS dock does. Reach for it when a handful of apps, tools or pages are known by their icons, and a name over the one under the pointer is enough.

When the labels should stay in view and the bar marks the section you're in, use Menu Dock instead.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Dock anatomy: root, item, icon, label, separator

Usage

import { HouseIcon, SettingsIcon } from "lucide-react";
import {
  Dock, DockIcon, DockItem, DockLabel,
} from "@/components/ui/dock";
<Dock>
  <DockItem>
    <DockLabel>Home</DockLabel>
    <DockIcon>
      <HouseIcon />
    </DockIcon>
  </DockItem>
  <DockItem>
    <DockLabel>Settings</DockLabel>
    <DockIcon>
      <SettingsIcon />
    </DockIcon>
  </DockItem>
</Dock>

The icons grow upward out of the dock and the label floats above the one under the pointer, so leave about 56 pixels clear over it at the default sizes.

Accessibility

Dock is a toolbar named Dock, which an aria-label replaces, with a single tab stop: Tab lands on the item focused last, and the arrow keys, Home and End move between items, skipping disabled ones. DockIcon is hidden from screen readers, so the DockLabel inside each DockItem is that item's name even while it's invisible, and an item without one needs an aria-label. The dot from active is only drawn, so pair it with aria-pressed or aria-current.

Tab
Moves focus into the dock, onto the item that had focus last or the first one, and from there out of the dock.
Shift+Tab
Moves focus out of the dock to the previous focusable element.
Arrow Right
Moves focus to the next item, and from the last one back to the first. In a right-to-left layout, moves to the previous item.
Arrow Left
Moves focus to the previous item, and from the first one to the last. In a right-to-left layout, moves to the next item.
Home
Moves focus to the first item.
End
Moves focus to the last item.
Enter
Activates the focused item, whether it is a button or a link.
Space
Activates the focused item when it is a button. A link ignores it.

Demos

Mac desktop

Eight apps over a wallpaper, with Finder and Safari starting open. A click toggles an app: active draws the dot under it, aria-pressed tells a screen reader the same, and bounce makes the icon hop. A DockSeparator sets the Trash apart as on a Mac, and each tile's color comes from a class on its DockIcon.

Preview width

Magnification

Two docks of the same six icons at a 40 pixel resting size. The subtle one grows an icon to 52 pixels and reaches 100 pixels from the pointer, while the strong one grows to 96 and reaches 220, lifting several icons at once. Tune magnification for the icon under the pointer and distance for how many neighbors rise with it.

Preview width

A personal site's pages as a dock, with Writing as the current page and an RSS feed after a separator. Each DockItem renders an <a> through asChild, and the current one gets active for the dot and aria-current for screen readers. Use links for items that open a page, and leave items as buttons when they run an action.

Preview width

Avatars

Six teammates as round profile photos, with a dot under the three who are online and the word online in their labels. The photo fills a DockIcon given rounded-full, and since that wrapper is hidden from screen readers, the label is the only name each person has. Use it for a presence bar or a quick switch between people.

Preview width

FAQ

How do I change how much the Dock magnifies?

Set three numbers on Dock, all in pixels: size is an icon at rest (48 by default), magnification its size right under the pointer (80), and distance how far from the pointer an icon still grows (140).

The growth falls off on a cosine curve, so the icon under the pointer is the largest and its neighbors spread aside to make room while the shelf widens under them. The Magnification demo puts a subtle and a strong setting side by side.

How do I show which apps are open in the Dock?

Set active on a DockItem to draw the dot under its icon, the way macOS marks a running app. The dot is only drawn, so give the item aria-pressed with the same value and screen readers hear it too.

The Mac desktop demo keeps the open apps in a list in state and toggles one on each click. Add bounce and the icon hops for a quarter of a second on every click, on closing as well as opening.

Can I use the Dock with the keyboard?

Yes. The dock is a toolbar with one tab stop, so Tab enters it on the item focused last and the arrow keys move along it, wrapping at the ends and mirrored in a right-to-left layout. Home and End jump to the first and last item.

An icon focused from the keyboard grows and shows its label the way a hovered one does, with a focus ring around it. The Accessibility section lists every key.

Does the Dock respect reduced motion and touch screens?

It does. When the system asks for reduced motion, nothing grows, spreads or bounces, the shelf keeps its width, and the labels still appear on hover and focus without sliding.

The dock ignores pointer moves from touch, so on a phone or tablet it never magnifies and stays a plain row of icons. A tap still presses the item, so the dock works the same with or without the effect.

Why does the Dock overlap the content above it?

The icons grow with CSS transforms, which take no room in the layout, so the page never shifts while the pointer moves but the grown icons and the label spill out over whatever sits above. Leave clear space of about magnification minus size plus 24 pixels for the label, which is 56 pixels at the defaults.

The shelf also widens to both sides as the icons spread, so keep the dock away from the edges of its container. Fixed to the bottom of the screen over the page, as on macOS, the spill is part of the effect.

How do I change the Dock's background, tiles and dot?

The shelf is a layer behind the icons, drawn by the root's before: classes so it can widen as they spread. Add your own before: classes to Dock, such as before:bg-muted, to recolor it, and round it with a radius class on Dock, which the layer inherits.

Each tile is a class on its DockIcon: a background and a border, or rounded-full for a photo. The dot under an open item is the after: layer of DockItem, so after:bg-primary on the item changes its color.

Can I make a vertical Dock on the side of the screen?

Not as it ships. The magnification measures where each icon sits along the horizontal axis, the icons grow upward from their bottom edge, and only the Left and Right arrow keys move focus. In a column, every icon would grow at once and Up and Down would do nothing.

A side dock needs those three changes in components/ui/dock, which is your code once installed. For a vertical bar that marks the current section, Menu Dock has an orientation of its own.

API Reference

Dock

<div> data-slot="dock"

PropType
distance?number

How far from the pointer icons still grow, in pixels.

Default
140
magnification?number

An icon's size right under the pointer, in pixels.

Default
80
size?number

Each icon's size at rest, in pixels.

Default
48
className?string

Merged with the part's classes.

CSS variableType
--dock-scalestring

On each item: how much its icon is grown now.

--dock-shiftstring

On each item: how far it's moved aside now.

--dock-sizestring

Each icon's size at rest (from size).

DockItem

<button> data-slot="dock-item"

PropType
active?boolean

Shows the dot under the icon, as macOS marks an app that's open.

Default
false
bounce?boolean

Whether the icon bounces when clicked, as an app does when it opens.

Default
false
asChild?boolean

Merge props onto the child element instead of rendering a host.

className?string

Merged with the part's classes.

AttributeType
data-active?string

Present when active is true.

CSS variableType
--dock-scalestring

On each item: how much its icon is grown now.

--dock-shiftstring

On each item: how far it's moved aside now.

--dock-sizestring

Each icon's size at rest (from size).

DockIcon

<span> data-slot="dock-icon"

PropType
className?string

Merged with the part's classes.

CSS variableType
--dock-scalestring

On each item: how much its icon is grown now.

--dock-shiftstring

On each item: how far it's moved aside now.

--dock-sizestring

Each icon's size at rest (from size).

DockLabel

<span> data-slot="dock-label"

PropType
className?string

Merged with the part's classes.

CSS variableType
--dock-scalestring

On each item: how much its icon is grown now.

--dock-shiftstring

On each item: how far it's moved aside now.

--dock-sizestring

Each icon's size at rest (from size).

DockSeparator

<hr> data-slot="dock-separator"

PropType
className?string

Merged with the part's classes.

CSS variableType
--dock-scalestring

On each item: how much its icon is grown now.

--dock-shiftstring

On each item: how far it's moved aside now.

--dock-sizestring

Each icon's size at rest (from size).