How to Build a Modern CSS Floating Action Button (FAB) & Radial Speed Dial Menu
A modern floating action button (FAB) speed dial combines fixed CSS viewport positioning (`position: fixed; bottom: 2rem; right: 2rem; z-index: 999;`) with transform-based item bloom (`transform: translateY(-60px) scale(1)`), CSS cubic-bezier transition curves for spring physics, and an ARIA-expanded controller tracking Escape key dismissals.
Step 1: Construct the Accessible Semantic Markup
Structure the floating action trigger and its blooming action list with aria-haspopup, aria-expanded, and an action container.
<div class="fab-container" id="fabMenu">
<ul class="fab-actions" id="fabActions" role="menu" aria-label="Quick actions" aria-hidden="true">
<li role="none"><button role="menuitem" class="fab-action-btn" aria-label="Create Document" data-tooltip="New Doc">📝</button></li>
<li role="none"><button role="menuitem" class="fab-action-btn" aria-label="Upload File" data-tooltip="Upload">📤</button></li>
<li role="none"><button role="menuitem" class="fab-action-btn" aria-label="Share Link" data-tooltip="Share">🔗</button></li>
</ul>
<button class="fab-trigger" id="fabTrigger" aria-haspopup="menu" aria-expanded="false" aria-label="Toggle quick actions menu">
<svg class="fab-icon" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="currentColor" stroke-width="2.5"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>
</button>
</div>
Step 2: Apply Spring Easing & Staggered CSS Transforms
Use CSS custom properties to calculate stagger delays and hardware-accelerated transforms to achieve buttery 60fps item bloom.
.fab-container {
position: fixed;
bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
right: calc(1.5rem + env(safe-area-inset-right, 0px));
z-index: 999;
display: flex;
flex-direction: column-reverse;
align-items: center;
gap: 12px;
}
.fab-trigger {
width: 56px;
height: 56px;
border-radius: 50%;
border: none;
background: linear-gradient(135deg, #6366f1, #a855f7);
color: #fff;
cursor: pointer;
box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
}
.fab-container.is-active .fab-trigger {
transform: rotate(135deg) scale(0.95);
background: #ef4444;
}
.fab-actions {
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-direction: column-reverse;
gap: 10px;
pointer-events: none;
}
.fab-container.is-active .fab-actions {
pointer-events: auto;
}
.fab-action-btn {
width: 44px;
height: 44px;
border-radius: 50%;
border: 1px solid rgba(255, 255, 255, 0.15);
background: rgba(30, 27, 75, 0.85);
backdrop-filter: blur(12px);
color: #fff;
opacity: 0;
transform: translateY(20px) scale(0.6);
transition: opacity 0.25s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.fab-container.is-active .fab-action-btn {
opacity: 1;
transform: translateY(0) scale(1);
}
.fab-container.is-active .fab-actions li:nth-child(1) .fab-action-btn { transition-delay: 0.05s; }
.fab-container.is-active .fab-actions li:nth-child(2) .fab-action-btn { transition-delay: 0.1s; }
.fab-container.is-active .fab-actions li:nth-child(3) .fab-action-btn { transition-delay: 0.15s; }
Step 3: Add Keyboard Esc Listener & Outside Click Trapping
Ensure users can toggle via Space/Enter, close the speed dial with the Escape key, and auto-dismiss when tapping outside the menu.
const container = document.getElementById('fabMenu');
const trigger = document.getElementById('fabTrigger');
const actions = document.getElementById('fabActions');
function toggleFab(force) {
const open = force !== undefined ? force : !container.classList.contains('is-active');
container.classList.toggle('is-active', open);
trigger.setAttribute('aria-expanded', String(open));
actions.setAttribute('aria-hidden', String(!open));
}
trigger.addEventListener('click', () => toggleFab());
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && container.classList.contains('is-active')) {
toggleFab(false);
trigger.focus();
}
});
document.addEventListener('click', (e) => {
if (!container.contains(e.target) && container.classList.contains('is-active')) {
toggleFab(false);
}
});
Next-Level Addons: Elevating Your Implementation
Take this technique further by combining it with complementary design token studios and animation tools:
A trick I use in almost every project: don't fight specificity battles with !important. Leverage modern CSS cascade layers (@layer) and CSS variables as design tokens—it makes dark/light theme switching and responsive tuning effortless.
Frequently Asked Questions
Practical answers to common implementation questions, browser quirks, and performance tips.
What is the optimal target size for mobile floating action buttons?
WCAG 2.2 Success Criterion 2.5.8 recommends minimum 44×44px CSS pixels for touch targets. We recommend 56×56px for primary triggers and 44×44px for secondary action pills.
How do you prevent the speed dial menu from being cut off by mobile browser address bars?
Use CSS safe area insets: `bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));`. This ensures proper padding above Safari iOS tab bars.
Can speed dial actions be arranged in a radial arc instead of a vertical column?
Yes! Using CSS transforms with polar coordinates (`transform: translate(calc(cos(var(--angle)) * 80px), calc(sin(var(--angle)) * -80px))`), actions bloom in an 90-degree radial arc.
Why should the trigger icon rotate 135 degrees instead of 45 degrees?
Rotating 135 degrees gives a dynamic fluid spin sensation while transforming the upright cross (+) into an intuitive dismissal cross (×).
Does this speed dial work without client-side frameworks?
Yes, it is 100% vanilla CSS custom properties and lightweight zero-dependency JavaScript with less than 1KB gzipped footprint.