Collapsing a nav to a rail shouldn’t move its icons, so build both states to put every icon at the same x.

The problem

A lot of collapsible navs center their icons in the rail and left-align them when open. So every toggle slides the icons sideways, then snaps them into place. That’s a lot of motion for something that didn’t change, and it’s the part of the nav your eye was resting on.

What I concluded

Make the icon’s position identical in both states by construction. Fixed left padding, fixed icon size, and a rail exactly as wide as padding plus icon plus padding. Collapsing only animates the container’s width and fades the labels. The icons never move, because no rule ever tells them to.

.nav { width: var(--nav-w); overflow: hidden;
       transition: width 220ms; }
.nav[data-open] { --nav-w: 240px; }
.nav:not([data-open]) { --nav-w: 44px; } /* 12 + 20 + 12 */

.nav-item { display: flex; gap: 10px; padding-left: 12px;
            white-space: nowrap; }
.nav-item svg { flex: none; width: 20px; }
.nav:not([data-open]) .nav-item span { opacity: 0; }

This does animate width, which is layout work on every frame. I think that’s fine here: the nav’s contents are fixed size and don’t wrap, so each frame is cheap, and the page beside it can snap to its final width once. If it ever janks, keep the nav full width and animate clip-path: inset() instead.

Rules

  • Same x in both states. Padding and icon size are fixed, and the rail width is derived from them.
  • Animate one property. The container’s width. Labels fade, nothing re-centers.
  • Collapsed labels stay in the DOM. Transparent, not removed, so each item keeps its accessible name.
  • Give the rail tooltips. Sighted users lose the labels when it’s closed, so each item needs one on hover and focus.
  • The toggle says its state. A button with aria-expanded, pointing at the nav.
  • Reduced motion turns the transition off.

What you get

A collapse that reads as the nav getting narrower, not as everything in it rearranging. Your eye stays on the icon it was on.

The demo shows the geometry only: turn on slow motion and watch the guide line, then unpin the icons to see them drift. Its toggle is a plain button and the rail has no tooltips, which the last rules cover for a real nav. Related: Layout geometry.