CSS Heart Like Button
A heart that fills and pops with a burst ring when liked, built on a plain checkbox.
<label class="like">
<input type="checkbox" aria-label="Like">
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 20.5 4.1 12.8A5 5 0 0 1 12 6.6a5 5 0 0 1 7.9 6.2Z"/></svg>
</label>
.like {
position: relative;
display: inline-grid;
place-items: center;
width: 56px;
height: 56px;
border-radius: 50%;
cursor: pointer;
transition: background 0.2s ease;
}
.like:hover {
background: #ffe4e6;
}
.like input {
position: absolute;
inset: 0;
margin: 0;
opacity: 0;
cursor: pointer;
}
.like svg {
width: 30px;
height: 30px;
fill: transparent;
stroke: #71717a;
stroke-width: 2;
stroke-linejoin: round;
pointer-events: none;
transition: fill 0.2s ease, stroke 0.2s ease;
}
.like:hover svg {
stroke: #f43f5e;
}
.like input:checked + svg {
fill: #f43f5e;
stroke: #f43f5e;
animation: like-pop 0.45s cubic-bezier(0.3, 1.6, 0.5, 1);
}
/* Burst ring */
.like::after {
content: "";
position: absolute;
inset: 6px;
border: 2px solid #f43f5e;
border-radius: 50%;
opacity: 0;
pointer-events: none;
}
.like:has(input:checked)::after {
animation: like-burst 0.5s ease-out;
}
.like:has(input:focus-visible) {
outline: 2px solid #f43f5e;
outline-offset: 2px;
}
@keyframes like-pop {
from { transform: scale(0.6); }
}
@keyframes like-burst {
from { opacity: 1; transform: scale(0.5); }
to { opacity: 0; transform: scale(1.3); }
}
@media (prefers-reduced-motion: reduce) {
.like input:checked + svg,
.like:has(input:checked)::after { animation: none; }
}
About this CSS Heart Like Button
This CSS Heart Like Button is 77 lines of pure CSS (1.3 KB) with no JavaScript and no dependencies. It uses keyframe animations, transitions, transforms 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
- keyframe animations
- transitions
- transforms
- CSS Grid
- the :has() selectorChrome 105+, Safari 15.4+, Firefox 121+.
- the :checked state (no JavaScript)
- keyboard focus styles
- reduced-motion support
Customize it
The colors in this snippet. Search and replace them to match your brand:
#ffe4e6#71717a#f43f5e
How to use this heart like 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
.likeclass 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.