CSS Success State Button
A submit button that turns green and draws a checkmark when its data-state is set to done.
<button class="btn-success" type="button">Submit</button>
<button class="btn-success" type="button" data-state="done">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>
Submitted
</button>
.btn-success {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 14px 28px;
border: 0;
border-radius: 10px;
background: #2563eb;
color: #fff;
font: 600 16px/1 system-ui, sans-serif;
cursor: pointer;
transition: background-color 0.3s ease;
}
.btn-success svg {
width: 18px;
height: 18px;
fill: none;
stroke: currentColor;
stroke-width: 3;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 24;
}
.btn-success[data-state="done"] {
background: #15803d;
animation: btn-success-pop 0.35s ease;
}
.btn-success[data-state="done"] svg {
animation: btn-success-draw 0.4s 0.15s ease-out backwards;
}
.btn-success:focus-visible {
outline: 3px solid #93c5fd;
outline-offset: 3px;
}
@keyframes btn-success-pop {
50% { transform: scale(1.06); }
}
@keyframes btn-success-draw {
from { stroke-dashoffset: 24; }
}
@media (prefers-reduced-motion: reduce) {
.btn-success[data-state="done"],
.btn-success[data-state="done"] svg { animation: none; }
}
About this CSS Success State Button
This CSS Success State Button is 51 lines of pure CSS (1.0 KB) with no JavaScript and no dependencies. It uses keyframe animations, transitions, transforms and Flexbox. 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:
#2563eb#fff#15803d#93c5fd
How to use this success state 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-successclass 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.