UI Components Easy
FAB Navigation
Floating action button with expandable speed-dial actions. Tap the FAB to reveal stacked action buttons with staggered animation.
Open in Lab
MCP
css vanilla-js
Targets: JS HTML
Code
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
:root {
--bg: #050910;
--nav-bg: #0d1117;
--screen-bg: #374151;
--accent: #3b82f6;
--accent-hover: #2563eb;
--text: #e2e8f0;
--text-muted: #94a3b8;
--muted: #475569;
}
body {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
background: var(--bg);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
color: var(--text);
padding: 2rem;
}
/* โโ Demo wrapper โโ */
.demo {
width: 100%;
max-width: 400px;
display: flex;
flex-direction: column;
align-items: center;
gap: 2rem;
}
.demo-title {
font-size: 1.5rem;
font-weight: 800;
text-align: center;
}
.demo-sub {
color: var(--muted);
font-size: 0.875rem;
text-align: center;
}
/* โโ Phone frame โโ */
.phone-frame {
width: 320px;
border-radius: 32px;
border: 1.5px solid rgba(255, 255, 255, 0.08);
background: var(--screen-bg);
overflow: hidden;
box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.04);
}
.phone-screen {
position: relative;
width: 100%;
height: 520px;
overflow: hidden;
background: var(--screen-bg);
}
/* โโ Status bar โโ */
.status-bar {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 20px 6px;
font-size: 12px;
font-weight: 600;
color: var(--text-muted);
}
.status-icons {
font-size: 9px;
letter-spacing: 3px;
}
/* โโ Top bar โโ */
.top-bar {
display: flex;
align-items: center;
padding: 8px 20px 12px;
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.top-bar-title {
font-size: 18px;
font-weight: 600;
}
/* โโ Page content โโ */
.page-content {
padding: 28px 20px;
}
.page-content h2 {
font-size: 1.25rem;
margin-bottom: 10px;
}
.page-content p {
font-size: 0.85rem;
color: var(--text-muted);
line-height: 1.6;
margin-bottom: 20px;
}
.card-placeholder {
height: 64px;
background: rgba(255, 255, 255, 0.06);
border-radius: 10px;
margin-bottom: 10px;
border: 1px solid rgba(255, 255, 255, 0.06);
}
/* โโ Backdrop overlay โโ */
.backdrop {
position: absolute;
inset: 0;
background: rgba(0, 0, 0, 0.4);
opacity: 0;
visibility: hidden;
transition: opacity 0.3s, visibility 0.3s;
z-index: 10;
}
.fab-open .backdrop {
opacity: 1;
visibility: visible;
}
/* โโ FAB wrapper โโ */
.fab-wrapper {
position: absolute;
bottom: 24px;
right: 20px;
display: flex;
flex-direction: column-reverse;
align-items: center;
gap: 12px;
z-index: 20;
}
/* โโ Main FAB button โโ */
.fab-main {
width: 56px;
height: 56px;
border-radius: 50%;
border: none;
background: var(--accent);
color: #fff;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 4px 16px rgba(59, 130, 246, 0.4);
transition: background 0.3s, box-shadow 0.3s;
z-index: 2;
-webkit-tap-highlight-color: transparent;
}
.fab-main:hover {
background: var(--accent-hover);
box-shadow: 0 6px 20px rgba(59, 130, 246, 0.5);
}
/* โโ FAB icon rotation โโ */
.fab-icon {
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.fab-open .fab-icon {
transform: rotate(45deg);
}
/* โโ Mini FAB buttons โโ */
.fab-mini {
width: 40px;
height: 40px;
border-radius: 50%;
border: none;
background: var(--accent);
color: #fff;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 2px 10px rgba(59, 130, 246, 0.3);
opacity: 0;
transform: scale(0.4) translateY(20px);
transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
background 0.15s ease;
pointer-events: none;
}
.fab-mini:hover {
background: var(--accent-hover);
}
/* โโ Staggered reveal โโ */
.fab-open .fab-mini {
opacity: 1;
transform: scale(1) translateY(0);
pointer-events: auto;
}
.fab-open .fab-mini[data-index="0"] {
transition-delay: 0.05s;
}
.fab-open .fab-mini[data-index="1"] {
transition-delay: 0.1s;
}
.fab-open .fab-mini[data-index="2"] {
transition-delay: 0.15s;
}
.fab-mini[data-index="0"] {
transition-delay: 0.1s;
}
.fab-mini[data-index="1"] {
transition-delay: 0.05s;
}
.fab-mini[data-index="2"] {
transition-delay: 0s;
}const container = document.getElementById("fabContainer");
const fabMain = document.getElementById("fabMain");
const backdrop = document.getElementById("backdrop");
function toggleFab() {
container.classList.toggle("fab-open");
}
function closeFab() {
container.classList.remove("fab-open");
}
fabMain.addEventListener("click", toggleFab);
backdrop.addEventListener("click", closeFab);
document.addEventListener("keydown", (e) => {
if (e.key === "Escape") closeFab();
});<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>FAB Navigation</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="demo">
<h1 class="demo-title">FAB Navigation</h1>
<p class="demo-sub">Floating action button with speed-dial actions.</p>
<div class="phone-frame">
<div class="phone-screen" id="fabContainer">
<!-- Status bar -->
<div class="status-bar">
<span>9:41</span>
<span class="status-icons">โโโ</span>
</div>
<!-- Top bar -->
<div class="top-bar">
<span class="top-bar-title">My App</span>
</div>
<!-- Page content -->
<div class="page-content">
<h2>Welcome</h2>
<p>Tap the floating action button to reveal quick actions.</p>
<div class="card-placeholder"></div>
<div class="card-placeholder"></div>
</div>
<!-- Backdrop -->
<div class="backdrop" id="backdrop"></div>
<!-- FAB speed dial -->
<div class="fab-wrapper" id="fabWrapper">
<button class="fab-mini" aria-label="Copy" data-index="0">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
</svg>
</button>
<button class="fab-mini" aria-label="Edit" data-index="1">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
</svg>
</button>
<button class="fab-mini" aria-label="Add" data-index="2">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<line x1="12" y1="5" x2="12" y2="19"/>
<line x1="5" y1="12" x2="19" y2="12"/>
</svg>
</button>
<button class="fab-main" id="fabMain" aria-label="Toggle actions">
<svg class="fab-icon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
<line x1="12" y1="5" x2="12" y2="19"/>
<line x1="5" y1="12" x2="19" y2="12"/>
</svg>
</button>
</div>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>FAB Navigation
A floating action button (FAB) at the bottom-right corner that expands into a speed-dial of smaller action buttons with staggered reveal animation.
Features
- Primary FAB with + icon that rotates to ร on open
- 3 mini action buttons that fan out vertically
- Staggered animation with CSS transitions
- Backdrop overlay when open
- Keyboard accessible
How it works
- FAB button toggles
.fab-openclass on the container - Mini buttons translate from hidden position with staggered
transition-delay - FAB icon rotates 45ยฐ to form ร shape
- Click outside or Escape closes the speed dial