macOS Dock Magnification in CSS

A glass dock whose icons scale and lift based on pointer distance, with a quiet idle wave when the pointer is away.


macOS Dock Magnification in CSS


Dock magnification is the macOS behavior people try to copy: icons near the pointer grow, icons far away stay put, and the growth falls off with distance so the row makes a smooth hill instead of one sudden pop. It is a search with a long tail (“css dock hover”, “macos dock magnification”, “icon magnify on mouse move”) because a CSS :hover scale on a single icon never looks like the original. The original is a function of distance.

The dock in this demo is a glass pill: translucent white, a hairline border, and backdrop-filter: blur(16px). Five buttons sit on the baseline. On mousemove, each icon measures the horizontal distance from the pointer to its own center and maps that into a scale and a lift. On mouseleave, the inline transform clears and a CSS wave takes over, so the dock is alive in a thumbnail before anyone hovers.

The glassmorphic navigation menu is the same material as a header. The magnetic button is the same idea of “the pointer has gravity”, applied to one control.

Distance, then scale

dock.addEventListener("mousemove", (event) => {
  dock.classList.add("is-hot");
  buttons.forEach((button) => {
    const rect = button.getBoundingClientRect();
    const dist = Math.abs(event.clientX - (rect.left + rect.width / 2));
    const influence = Math.max(0, 1 - dist / 150);
    const scale = 1 + influence * 0.65;
    const lift = influence * 18;
    button.style.transform = `translateY(${-lift}px) scale(${scale})`;
  });
});
dock.addEventListener("mouseleave", () => {
  buttons.forEach((button) => { button.style.transform = ""; });
  dock.classList.remove("is-hot");
});

150 is the radius of influence in pixels. Larger values make a wider hill, so neighbors grow even when you are clearly on one icon. 0.65 is the extra scale at distance zero: the icon under the pointer becomes 1.65 times itself. Lift and scale share the same influence so the icon rises as it grows, which keeps the baseline of the dock visually stable. Set transform-origin: bottom center or the icons grow upward and downward and crash into the pill.

The transition on transform is short, about 120ms linear. A long ease fights the pointer. The pointer is already an ease.

The idle wave

@keyframes wave {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-10px) scale(1.16); }
}
.dock button { animation: wave 2.8s ease-in-out infinite; }
.dock.is-hot button { animation: none; }

Stagger animation-delay by about 120ms per icon. The moment the dock is “hot”, kill the animation. If you leave both running, the wave and the pointer scale compose into a jitter.

Glass, and the cost of it

backdrop-filter blurs whatever is behind the pill. On a flat color it does nothing visible, which is why the demo sits on a dusk gradient. On a page with photos or text scrolling behind a fixed dock, the blur is recomputed while you scroll. One dock is fine. A page of glass cards plus a glass dock is where fans start.

Keyboard

These are buttons with names: Home, Search, Write, Pictures, Profile. Focus draws an outline outside the icon. Magnification is pointer-only. Do not hide the label in a way that leaves an unlabeled SVG. The demo uses aria-label because the SVG is decorative.

Reduced motion turns the script into a no-op and the CSS wave is disabled. The dock remains a row of buttons.

Questions about dock magnification

How do I make a macOS dock hover effect in CSS?

CSS alone can scale the icon you hover. The magnification hill needs the pointer’s x position. On mousemove, compute each icon’s distance from that x, convert the distance to a 0–1 influence, and set scale and translateY from it. Clear the transform when the pointer leaves.

Why do the icons jitter?

An infinite CSS animation and an inline transform are both writing transform. Remove the animation while the pointer is over the dock. Also keep the JS transition short. A 400ms ease on a value you update every frame lags behind the cursor and looks like jitter.

Can I do this without JavaScript?

You can fake a single-icon pop with :hover. You cannot get a distance falloff across the row in CSS, because CSS does not know how far the pointer is from the other icons. The script above is the whole behavior. It does not need a library.