Button Library · Interactive
Floating Action
Round, raised, one key action.
To pin it to the corner, add position: fixed; right: 24px; bottom: 24px.
States
Default
Hover
Active
Focus
Code
fab.html
<button class="btn-fab" type="button" aria-label="Add">
<svg class="btn-fab__icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M12 5v14"></path>
<path d="M5 12h14"></path>
</svg>
</button>
fab.css
.btn-fab {
--btn-bg: #7c5cff;
--btn-fg: #ffffff;
--btn-font: inherit;
--btn-size: 15px;
--btn-weight: 600;
--btn-px: 16px;
--btn-py: 16px;
--btn-w: auto;
--btn-h: auto;
--btn-bw: 0px;
--btn-line: #8b6cff;
--btn-radius: 40px;
--btn-shadow: 0 14px 34px rgba(0,0,0,.4);
--btn-speed: 180ms;
}
.btn-fab {
position: relative;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.5em;
box-sizing: border-box;
width: var(--btn-w);
height: var(--btn-h);
padding: var(--btn-py) var(--btn-px);
font-family: var(--btn-font);
font-size: var(--btn-size);
font-weight: var(--btn-weight);
line-height: 1.2;
color: var(--btn-fg);
background: var(--btn-bg);
border: var(--btn-bw) solid var(--btn-line);
border-radius: var(--btn-radius);
box-shadow: var(--btn-shadow);
cursor: pointer;
text-decoration: none;
white-space: nowrap;
transition: all var(--btn-speed) ease;
}
.btn-fab:focus-visible {
outline: 2px solid var(--btn-bg);
outline-offset: 2px;
}
.btn-fab:disabled {
opacity: 0.5;
pointer-events: none;
}
.btn-fab__icon {
width: 1.15em;
height: 1.15em;
flex-shrink: 0;
}
.btn-fab:hover {
transform: translateY(-3px) scale(1.05);
}
.btn-fab:active {
transform: scale(0.95);
}
@media (prefers-reduced-motion: reduce) {
.btn-fab {
animation: none !important;
transition: none !important;
}
}
fab.js
// No JavaScript needed: this one is CSS only.
fab.tsx
import type React from "react";
import "./fab.css"; // the CSS tab
export function BtnFab(props: React.ComponentProps<"button">) {
return (
<button className="btn-fab" type="button" aria-label="Add" {...props}>
<svg className="btn-fab__icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d="M12 5v14" />
<path d="M5 12h14" />
</svg>
</button>
);
}
fab.html
<button class="relative inline-flex items-center justify-center gap-[0.5em] [box-sizing:border-box] [padding:16px_16px] [font-family:inherit] text-[15px] font-[600] [line-height:1.2] text-[#ffffff] bg-[#7c5cff] [border:0px_solid_#8b6cff] rounded-[40px] [box-shadow:0_14px_34px_rgba(0,0,0,.4)] cursor-pointer no-underline whitespace-nowrap [transition:all_180ms_ease] focus-visible:[outline:2px_solid_#7c5cff] focus-visible:[outline-offset:2px] disabled:[opacity:0.5] disabled:[pointer-events:none] hover:[transform:translateY(-3px)_scale(1.05)] active:[transform:scale(0.95)] motion-reduce:[transition:none!important]" type="button" aria-label="Add">
<svg class="w-[1.15em] h-[1.15em] [flex-shrink:0]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M12 5v14"></path>
<path d="M5 12h14"></path>
</svg>
</button>