CSS Floating Action Button
A Material-style floating action button pinned to the corner, with a plus icon that turns on hover.
<button class="btn-fab" aria-label="Create new">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M5 12h14"/></svg>
</button>
.btn-fab {
position: fixed;
right: 24px;
bottom: 24px;
z-index: 10;
display: grid;
place-items: center;
width: 56px;
height: 56px;
padding: 0;
border: 0;
border-radius: 16px;
background: #7c3aed;
color: #fff;
box-shadow:
0 4px 8px -2px #4c1d9566,
0 10px 24px -6px #7c3aed99;
cursor: pointer;
transition: box-shadow 0.2s ease, background-color 0.2s ease;
}
.btn-fab svg {
width: 26px;
height: 26px;
fill: none;
stroke: currentColor;
stroke-width: 2.4;
stroke-linecap: round;
transition: transform 0.3s ease;
}
.btn-fab:hover {
background: #6d28d9;
box-shadow:
0 6px 12px -2px #4c1d9566,
0 16px 32px -8px #7c3aed99;
}
.btn-fab:hover svg {
transform: rotate(90deg);
}
.btn-fab:focus-visible {
outline: 3px solid #c4b5fd;
outline-offset: 3px;
}
About this CSS Floating Action Button
This CSS Floating Action Button is 46 lines of pure CSS (0.8 KB) with no JavaScript and no dependencies. It uses transitions, transforms, box shadows and CSS Grid. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.
CSS features used
Customize it
The colors in this snippet. Search and replace them to match your brand:
#7c3aed#fff#4c1d9566#7c3aed99#6d28d9#c4b5fd
How to use this floating action button
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.btn-fabclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).
Building with an AI tool?
“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.