Radial menu in CSS: a floating action button that fans out on an arc
Build a radial menu in CSS: a floating action button that fans items along an arc with staggered overshoot, reverse stagger on close, Escape, focus, React.
A radial menu hides a few related actions behind one floating action button. Tap the button and the actions fan out around it on an arc; tap again and they fold back in. It saves space on a busy screen and gives each action a large target, which is why it shows up in mobile apps, editors and chat composers.
The motion is what sells it. Items that leave one after another, overshoot slightly and settle feel like they spring out of the button. This guide builds that with CSS transitions: arc positioning with rotate() or CSS trig functions, a staggered open with overshoot, a reverse stagger on close, and the keyboard and screen reader behaviour a menu needs. It ends with a React version.
Pick an action
How the animation is put together
Each item has one transition for opening and a different one for closing. CSS uses the transition declared on the state an element is moving to, so the open rule carries the springy timing and the base rule carries the quick fold-back.
| Part | Property | Duration | Delay | Easing |
|---|---|---|---|---|
| Button icon | transform: rotate(0 → 45deg), plus becomes × | 300 ms | 0 | cubic-bezier(.34, 1.56, .64, 1) |
| Items, open | transform: centre → arc, scale(.4 → 1) | 460 ms | i × 45 ms (0–180 ms) | cubic-bezier(.34, 1.56, .64, 1) |
| Items, open | opacity 0 → 1 | 200 ms | i × 45 ms | ease-out |
| Items, close | transform: arc → centre, scale(1 → .4) | 200 ms | (n − 1 − i) × 30 ms | cubic-bezier(.4, 0, 1, 1) |
| Items, close | opacity 1 → 0 | 160 ms | (n − 1 − i) × 30 ms | ease-in |
| Items, close | visibility → hidden | 0 | close delay + 200 ms | step |
Opening is slower and bouncy because it is the moment people watch. Closing is about twice as fast and uses an ease-in with no overshoot: the user has already made a choice and the menu should get out of the way.
Placing items on an arc
All the items start stacked at the centre of the button. Each one has an angle, --a, and the menu has a radius, --r. Angles follow the screen's coordinate system: 0deg points right and angles increase clockwise, so 270deg points straight up. The demo spreads five items from 200deg to 340deg, which is an upward fan of 140 degrees with 35 degrees between items.
There are two ways to turn an angle and a radius into a position.
Rotate, translate, rotate back
transform: rotate(var(--a)) translateX(var(--r)) rotate(calc(var(--a) * -1));
This turns the item's axis to the angle, pushes it out along that axis, then turns it back so the icon stays level. It works in every browser that supports transforms, and it is the same trick the orbit animation uses to place icons on a ring.
CSS trig functions
transform: translate(calc(cos(var(--a)) * var(--r)), calc(sin(var(--a)) * var(--r)));
cos() and sin() return plain numbers, so multiplying them by a length gives the x and y offsets directly. This reads like the maths and leaves no rotation in the transform. Trig functions are supported in all current major browsers, so the demo uses them inside @supports and keeps the rotate version as the fallback.
Whichever you choose, write the closed and open states with the same list of transform functions, for example translate(0, 0) scale(.4) and translate(x, y) scale(1). The browser then interpolates each function separately and the items travel in a straight line from the centre. If the lists differ, it falls back to interpolating a matrix, which can give odd curved paths.
The HTML
<div class="rm">
<ul class="rm-items" id="rm-items" style="--n:5">
<li style="--i:0; --a:200deg"><button type="button" class="rm-item" aria-label="Note">…</button></li>
<li style="--i:1; --a:235deg"><button type="button" class="rm-item" aria-label="Photo">…</button></li>
<li style="--i:2; --a:270deg"><button type="button" class="rm-item" aria-label="Voice">…</button></li>
<li style="--i:3; --a:305deg"><button type="button" class="rm-item" aria-label="File">…</button></li>
<li style="--i:4; --a:340deg"><button type="button" class="rm-item" aria-label="Link">…</button></li>
</ul>
<button type="button" class="rm-fab" aria-expanded="false" aria-controls="rm-items" aria-label="Add">
<svg class="rm-plus" viewBox="0 0 24 24">…</svg>
</button>
</div>
The items are plain buttons in a list, controlled by the floating button through aria-expanded and aria-controls. That is the disclosure pattern, and it fits better than role="menu", which promises arrow-key navigation and other application-menu behaviour that you would then have to build. Each icon-only button needs an aria-label.
The CSS
.rm-items { position: absolute; left: 50%; bottom: 28px; width: 0; height: 0;
margin: 0; padding: 0; list-style: none; }
.rm-items li {
--r: 100px;
--open-delay: calc(var(--i) * 45ms);
--close-delay: calc((var(--n) - 1 - var(--i)) * 30ms);
position: absolute; left: -22px; top: -22px; width: 44px; height: 44px;
opacity: 0; visibility: hidden;
transform: rotate(var(--a)) translateX(0) rotate(calc(var(--a) * -1)) scale(.4);
/* closing: fast, no overshoot, reverse order, hide when done */
transition: transform 200ms cubic-bezier(.4, 0, 1, 1) var(--close-delay),
opacity 160ms ease-in var(--close-delay),
visibility 0s linear calc(var(--close-delay) + 200ms);
}
.rm.is-open .rm-items li {
opacity: 1; visibility: visible;
transform: rotate(var(--a)) translateX(var(--r)) rotate(calc(var(--a) * -1)) scale(1);
/* opening: springy, in order, visible at once */
transition: transform 460ms cubic-bezier(.34, 1.56, .64, 1) var(--open-delay),
opacity 200ms ease-out var(--open-delay),
visibility 0s linear 0s;
}
@supports (top: calc(1px * sin(1deg))) {
.rm-items li { transform: translate(0, 0) scale(.4); }
.rm.is-open .rm-items li {
transform: translate(calc(cos(var(--a)) * var(--r)), calc(sin(var(--a)) * var(--r))) scale(1);
}
}
.rm-plus { transition: transform 300ms cubic-bezier(.34, 1.56, .64, 1); }
.rm.is-open .rm-plus { transform: rotate(45deg); }
@media (prefers-reduced-motion: reduce) {
.rm-items li, .rm.is-open .rm-items li, .rm-plus { transition: none; }
}
The stagger is just arithmetic on --i. On open, item 0 leaves first and item 4 last. On close, (n − 1 − i) flips the order, so the last item out is the first one back. Because the delays are custom properties, you can change the item count by updating --n and the angles; nothing else changes.
The visibility transition is the part that is easy to miss. It switches to visible immediately on open, so the items can take focus at once, and to hidden only after each item has finished closing. Hidden items cannot be tabbed to and are not read out, so the closed menu leaves no invisible buttons behind.
The overshoot comes from the first control point of cubic-bezier(.34, 1.56, .64, 1): its y value of 1.56 is above 1, which means the curve passes its end value and comes back. Here that makes each item fly a little past its spot on the arc and the scale go slightly above 1. The easing functions guide explains how the control points shape the curve.
The JavaScript
const root = document.querySelector('.rm');
const fab = root.querySelector('.rm-fab');
const items = [...root.querySelectorAll('.rm-item')];
function setOpen(open, returnFocus) {
root.classList.toggle('is-open', open);
fab.setAttribute('aria-expanded', String(open));
fab.setAttribute('aria-label', open ? 'Close' : 'Add');
if (open) items[0].focus();
else if (returnFocus) fab.focus();
}
fab.addEventListener('click', () => setOpen(!root.classList.contains('is-open'), false));
items.forEach(item => item.addEventListener('click', () => {
// run the action here
setOpen(false, true);
}));
root.addEventListener('keydown', e => {
if (e.key === 'Escape' && root.classList.contains('is-open')) {
e.preventDefault();
setOpen(false, true);
}
});
document.addEventListener('click', e => {
if (root.classList.contains('is-open') && !root.contains(e.target)) setOpen(false, false);
});
Focus moves to the first item when the menu opens, so keyboard users can tab straight through the actions. Escape and choosing an action both close the menu and return focus to the floating button; without that, focus would sit on a button that is about to become hidden. A click outside closes the menu without moving focus, because the user has already put their attention somewhere else.
The React version
import { useEffect, useRef, useState } from 'react';
export function RadialMenu({ actions, startAngle = 200, endAngle = 340, radius = 100 }) {
const [open, setOpen] = useState(false);
const rootRef = useRef(null);
const fabRef = useRef(null);
const firstRef = useRef(null);
const n = actions.length;
const stepAngle = n > 1 ? (endAngle - startAngle) / (n - 1) : 0;
const close = (returnFocus) => {
setOpen(false);
if (returnFocus) fabRef.current?.focus();
};
useEffect(() => {
if (!open) return;
firstRef.current?.focus();
const onKey = e => { if (e.key === 'Escape') close(true); };
const onClick = e => { if (!rootRef.current.contains(e.target)) close(false); };
document.addEventListener('keydown', onKey);
document.addEventListener('click', onClick);
return () => {
document.removeEventListener('keydown', onKey);
document.removeEventListener('click', onClick);
};
}, [open]);
return (
<div ref={rootRef} className={'rm' + (open ? ' is-open' : '')}>
<ul className="rm-items" id="rm-items" style={{ '--n': n }}>
{actions.map((action, i) => (
<li key={action.label}
style={{ '--i': i, '--a': startAngle + i * stepAngle + 'deg', '--r': radius + 'px' }}>
<button type="button" className="rm-item" aria-label={action.label}
ref={i === 0 ? firstRef : undefined}
onClick={() => { action.onSelect(); close(true); }}>
{action.icon}
</button>
</li>
))}
</ul>
<button ref={fabRef} type="button" className="rm-fab"
aria-expanded={open} aria-controls="rm-items" aria-label={open ? 'Close' : 'Add'}
onClick={() => setOpen(o => !o)}>
<PlusIcon className="rm-plus" />
</button>
</div>
);
}
The CSS is unchanged. The component spreads the angles evenly between startAngle and endAngle, so a corner button can use 180 to 270 degrees for a quarter fan instead. If you use more than one menu on a page, generate the list id with useId(). For the same stagger driven by Framer Motion variants, see Framer Motion stagger animation; staggerDirection: -1 gives the reverse order on close.
Timing that feels right
- Stagger 30 to 60 ms per item. Below about 25 ms the items look like they leave together; above 70 ms the last one feels late. Keep the whole open sequence under roughly 650 ms.
- Gentle overshoot. A y value of 1.4 to 1.6 in the bezier gives a visible spring without a wobble. Larger values make the items bounce past their neighbours on a tight arc.
- Close in half the time. 180 to 240 ms with an ease-in. No overshoot when collapsing into a button.
- Leave room for the bounce. At a 100 px radius and 44 px items, adjacent items on a 35 degree spread are about 60 px apart, which leaves space for the overshoot and gives comfortable touch targets.
Reduced motion
Under prefers-reduced-motion: reduce the transitions are removed. The items appear in place and disappear at once, and the plus icon swaps to a cross without turning. Because the visibility transition is removed as well, the items are hidden immediately on close and focus handling is unaffected. The reduced motion guide covers when a fade is a better substitute than no motion at all.
Copy one you already like
The feel of a radial menu comes down to a few numbers: the stagger, the overshoot and how the close differs from the open. If you have seen one you want to match, start the Capture Motion extension and open the menu while it records. It reads the keyframes, duration, delay and easing of every item, so the stagger shows up as a list of delays, and exports CSS, React, GSAP or JSON for the Figma plugin.
Questions
How do I position items on an arc in CSS?
Give each item an angle and a radius, then use transform: rotate(angle) translateX(radius) rotate(-angle). In browsers with CSS trig functions you can write translate(calc(cos(angle) * r), calc(sin(angle) * r)) instead, which reads more directly.
Why should the close stagger run in reverse?
The last item out is the first item back, so the fan folds up from the far end towards the button. Running the same order on close makes the first item disappear while the others are still visible, which reads as items being dropped rather than collected.
How do I keep closed menu items out of the tab order?
Set visibility: hidden on the closed items and delay that change until the close animation ends. Hidden elements cannot receive focus and are removed from the accessibility tree, and the delay lets them animate out first.
Can I copy a radial menu animation from another website?
Yes. The Capture Motion Chrome extension records the transform and opacity keyframes, durations, stagger delays and easing of each item while the menu opens, and exports CSS, React, GSAP or JSON.
