# Heart Like Button

> A heart that fills and pops with a burst ring when liked, built on a plain checkbox.

- Category: [CSS Effects](https://copy-css.com/category/effects)
- Tags: like, heart, favorite, toggle, checkbox, pop
- Live preview: https://copy-css.com/snippets/heart-like-toggle
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<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>
```

## CSS

```css
.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; }
}
```

## Notes

- 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.
- the :has() selector: Chrome 105+, Safari 15.4+, Firefox 121+.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
