# Floating dock

A compact action dock with lifting icons and a sliding selection indicator.

## Usage

Use for a small set of frequent workspace actions. This example changes selection and calls onSelect; connect that callback to real content. Use links instead if each destination is a separate URL.

Save the JSX and CSS Module in the same folder in a React project with CSS Modules support. Controlled components need parent state and change handlers.

## JSX

```jsx
"use client";
import styles from "./FloatingDock.module.css";
import { useState } from "react";
const defaults = [
  { id: "home", label: "Home", glyph: "⌂" },
  { id: "projects", label: "Projects", glyph: "▦" },
  { id: "activity", label: "Activity", glyph: "◷" },
  { id: "saved", label: "Saved", glyph: "♡" },
];
export default function FloatingDock({ items = defaults, onSelect }) {
  const [active, setActive] = useState(items[0]?.id);
  return (
    <div className={styles.root}>
      <div className={styles.dock} role="group" aria-label="Workspace view">
        {items.map((item) => (
          <button
            key={item.id}
            type="button"
            aria-label={item.label}
            aria-pressed={active === item.id}
            onClick={() => {
              setActive(item.id);
              onSelect?.(item.id);
            }}
          >
            <span className={styles.tip}>{item.label}</span>
            <span className={styles.glyph} aria-hidden="true">
              {item.glyph}
            </span>
            <i aria-hidden="true" />
          </button>
        ))}
      </div>
      <p role="status">{items.find((item) => item.id === active)?.label}</p>
    </div>
  );
}

```

## CSS

```css
.root {
  width: 100%;
  text-align: center;
}
.dock {
  display: inline-flex;
  gap: 8px;
  padding: 10px;
  background: var(--tdp-surface, #fffdfa);
  border: 1px solid var(--tdp-border, #d9d1c9);
  border-radius: calc(var(--tdp-radius, 8px) + 12px);
  box-shadow: 0 15px 35px #36251a12;
}
.dock button {
  width: 50px;
  min-height: 54px;
  border: 0;
  border-radius: var(--tdp-radius, 8px);
  background: transparent;
  position: relative;
  display: grid;
  place-items: center;
  color: var(--tdp-text, #302e2b);
  transition: background 0.2s;
}
.glyph {
  font: 27px system-ui;
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.dock button:is(:hover, :focus-visible) .glyph {
  transform: translateY(-8px) scale(1.2);
}
.dock button[aria-pressed="true"] {
  background: var(--tdp-subtle, #eee8e1);
}
.dock i {
  position: absolute;
  bottom: 5px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--tdp-primary, #1f3934);
  scale: 0;
  transition: scale 0.25s;
}
.dock button[aria-pressed="true"] i {
  scale: 1;
}
.tip {
  position: absolute;
  bottom: calc(100% + 15px);
  padding: 5px 9px;
  border-radius: 6px;
  background: #302e2b;
  color: white;
  font-size: 11px;
  opacity: 0;
  translate: 0 5px;
  transition:
    opacity 0.2s,
    translate 0.2s;
  pointer-events: none;
}
.dock button:is(:hover, :focus-visible) .tip {
  opacity: 1;
  translate: 0 0;
}
.root p {
  font-size: 12px;
  color: var(--tdp-muted, #6b625b);
  margin: 22px 0 0;
}
.root {
  font-family: var(--tdp-font, "DM Sans", system-ui, sans-serif);
  color: var(--tdp-text, #302e2b);
  max-width: 100%;
  box-sizing: border-box;
}
.root * {
  box-sizing: border-box;
}
.root :is(button, input, a):focus-visible,
.root:focus-visible {
  outline: 3px solid var(--tdp-focus, #7851a9);
  outline-offset: 4px;
}
.root button {
  font: inherit;
  cursor: pointer;
}
.root button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}
.root button,
.root a {
  touch-action: manipulation;
}
@media (prefers-reduced-motion: reduce) {
  .root,
  .root *,
  .root::before,
  .root::after {
    animation: none !important;
    transition: none !important;
    transform: none !important;
    translate: none !important;
    rotate: none !important;
    scale: none !important;
    scroll-behavior: auto !important;
  }
}
@media (max-width: 400px) {
  .dock {
    display: flex;
    gap: 4px;
    padding: 8px;
  }
  .dock button {
    width: auto;
    min-width: 0;
    flex: 1;
    min-height: 48px;
  }
}

```

## Props

- items (array): Unique id, label, and decorative glyph per action.
- onSelect (function): Receives the chosen id. Connect to your view logic.

## Accessibility

Buttons expose selected state through aria-pressed and names through aria-label. Every action has a touch-sized target. Tooltips also appear on keyboard focus.

Check accessibility again after customizing the component.

[Browse all components](/resources/components/)

Canonical: https://designproject.io/resources/components/floating-dock/

## Keep learning

- [How to create a UI color palette, step by step](https://designproject.io/resources/guides/create-ui-color-palette/)
- [Product design glossary: 44 terms explained](https://designproject.io/resources/glossary/)
- [How to choose font pairings for a product interface](https://designproject.io/resources/guides/choose-font-pairings/)
