Button Library · Animation
Spin
The icon turns, the button stays still.
States
Default
Hover
Active
Focus
Code
anim-spin.html
<button class="btn-anim-spin" type="button">
<svg class="btn-anim-spin__icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M20 11a8 8 0 0 0-14-4L4 9"></path>
<path d="M4 4v5h5"></path>
<path d="M4 13a8 8 0 0 0 14 4l2-2"></path>
<path d="M20 20v-5h-5"></path>
</svg>
<span>Syncing</span>
</button>
anim-spin.css
.btn-anim-spin {
--btn-bg: #7c5cff;
--btn-fg: #ffffff;
--btn-font: inherit;
--btn-size: 15px;
--btn-weight: 600;
--btn-px: 22px;
--btn-py: 11px;
--btn-w: auto;
--btn-h: auto;
--btn-bw: 0px;
--btn-line: #8b6cff;
--btn-radius: 10px;
--btn-shadow: none;
--btn-speed: 180ms;
}
.btn-anim-spin {
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-anim-spin:focus-visible {
outline: 2px solid var(--btn-bg);
outline-offset: 2px;
}
.btn-anim-spin:disabled {
opacity: 0.5;
pointer-events: none;
}
.btn-anim-spin__icon {
width: 1.15em;
height: 1.15em;
flex-shrink: 0;
animation: btn-spin 1.4s linear infinite;
}
@keyframes btn-spin {
to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
.btn-anim-spin,
.btn-anim-spin__icon {
animation: none !important;
transition: none !important;
}
}
anim-spin.js
// No JavaScript needed: this one is CSS only.
anim-spin.tsx
import type React from "react";
import "./anim-spin.css"; // the CSS tab
export function BtnAnimSpin({ children = "Syncing", ...props }: React.ComponentProps<"button">) {
return (
<button className="btn-anim-spin" type="button" {...props}>
<svg className="btn-anim-spin__icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<path d="M20 11a8 8 0 0 0-14-4L4 9" />
<path d="M4 4v5h5" />
<path d="M4 13a8 8 0 0 0 14 4l2-2" />
<path d="M20 20v-5h-5" />
</svg>
<span>{children}</span>
</button>
);
}
anim-spin.html
<button class="relative inline-flex items-center justify-center gap-[0.5em] [box-sizing:border-box] [padding:11px_22px] [font-family:inherit] text-[15px] font-[600] [line-height:1.2] text-[#ffffff] bg-[#7c5cff] [border:0px_solid_#8b6cff] rounded-[10px] [box-shadow:none] 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] motion-reduce:[transition:none!important]" type="button">
<svg class="w-[1.15em] h-[1.15em] [flex-shrink:0] [animation:btn-spin_1.4s_linear_infinite] motion-reduce:[animation:none!important]" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M20 11a8 8 0 0 0-14-4L4 9"></path>
<path d="M4 4v5h5"></path>
<path d="M4 13a8 8 0 0 0 14 4l2-2"></path>
<path d="M20 20v-5h-5"></path>
</svg>
<span>Syncing</span>
</button>
<!-- A class cannot hold keyframes: keep this in your CSS. -->
<style>
@keyframes btn-spin {
to { transform: rotate(360deg); }
}
</style>