Heart Like Button

A heart icon button that fills red with a pop animation when liked.

Tailwind CSS
<style>
  @keyframes heart-pop {
    0% { transform: scale(0.6); }
    40% { transform: scale(1.25); }
    70% { transform: scale(0.95); }
    100% { transform: scale(1); }
  }
  .like-btn input:checked + span { background-color: #fef2f2; border-color: #fecaca; color: #ef4444; }
  .like-btn input:checked + span svg { animation: heart-pop 0.4s ease; }
</style>
<label class="like-btn inline-flex cursor-pointer items-center gap-2 select-none">
  <input type="checkbox" checked class="sr-only" />
  <span class="grid h-11 w-11 place-items-center rounded-full border border-slate-200 bg-white text-slate-400 transition-colors duration-200 hover:border-red-200 hover:text-red-400">
    <svg viewBox="0 0 24 24" fill="currentColor" class="h-5 w-5"><path d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"/></svg>
  </span>
  <span class="text-sm font-medium text-slate-600 dark:text-slate-300">1.2k</span>
</label>

Free to use in personal and commercial projects. No attribution required.

Variants

Same component, different looks. Preview each one live and copy the code you like.

Bookmark

The bookmark variant fits save-for-later actions in blogs and reading apps.

Tailwind CSS

Star rating

The star variant with a rating count suits reviews and favorites.

Tailwind CSS

Compact

The compact icon-only heart fits dense feeds where a count would clutter the layout.

Tailwind CSS

About this heart like button

The heart like button is the smallest unit of social feedback on the web. This version shows the liked state: a red filled heart in a soft red circle with a count next to it. Uncheck it and it falls back to a quiet gray outline, which is exactly how a toggle should behave.

A hidden checkbox drives the whole thing. When checked, sibling selectors recolor the button and trigger the heart-pop keyframes: a quick overshoot to 1.25 scale, a settle at 0.95, then rest. That springy pop is what makes the tap feel satisfying instead of flat. The count sits outside the button as plain text so you can update it with your own logic.

Use it for post likes, favorite buttons, wishlist toggles, or comment reactions. The preview shows the liked state; in your app, bind the checkbox to your like state and update the count text when it changes.

The like is the smallest unit of social feedback, and its whole job is to make a tap feel good. A heart that just flips color feels flat; a heart that pops with a springy overshoot feels like the app celebrated with you. That micro-joy is what keeps people tapping, and it is entirely in the animation curve.

A hidden checkbox drives everything through sibling selectors. When checked, the button recolors and the heart-pop keyframes run: a quick overshoot to 1.25 scale, a settle at 0.95, then rest at 1. The count beside it is real text so it stays selectable and screen-reader friendly. Unchecking reverses the color instantly, which matches how toggles should behave.

Format the count compactly and put it after the heart: 1.2k, not 1,243, and hide the count entirely at zero rather than showing a lonely 0. On unlike, play the animation in reverse at double speed; a slow un-like feels like the interface is mourning. Debounce rapid taps into a single state change so the count never flickers. For the count bump, scale the number to 1.3 briefly; it is a tiny detail that makes the number feel physical.

The broken version updates the count only after the server responds, so the heart pops but the number sits still for a second and the whole interaction feels fake. Update the count optimistically the instant the tap lands, then reconcile quietly if the request fails. Users forgive a corrected number; they do not forgive a button that feels dead.

Where to use it

  • ✓ Social post like buttons
  • ✓ Wishlist and favorite toggles
  • ✓ Blog article reactions
  • ✓ Comment like buttons

Customization tips

Change red-500 to pink-500 for a softer feel, or amber for a star-style favorite. Slow the 0.4s pop for a bouncier feel. Remove the count span if you only need the icon.

Design notes

When to use

A heart like button fits content feeds where appreciation is quick and public, like posts, photos, or comments. The pop animation plus the red fill gives an instant emotional payoff that a plain toggle cannot match. Pairing it with a count, as this one does with 1.2k, turns a private tap into visible social proof.

What to avoid

Do not use a heart for bookmarking, users expect the heart to mean like and will be confused when it saves instead. Avoid the pop animation on every render, it should fire on the tap, not when the page loads. And do not hide the unlike path, trapping users in a like they cannot remove breeds resentment.

Accessibility

Use aria-pressed on the button so screen readers announce liked versus not liked. The pop animation is decorative, and the count should be real text associated with the button.

Frequently asked questions

How do I make a heart like button animation in CSS?

Use a scale keyframe with an overshoot: scale up past 1, settle slightly under, then rest at 1. Trigger it with input:checked + span svg so it replays every time the state turns on.

Why use a checkbox instead of a button with JavaScript?

A checkbox gives you the toggle state in pure HTML with zero JavaScript, and it stays keyboard accessible. For a static demo or prototype this is enough. In a real app, sync it with your backend state.

The animation only plays once. How do I replay it?

It plays every time the checkbox transitions from unchecked to checked. Uncheck and re-check to see it again. If you need it to replay while already liked, remove and re-add the animation via JavaScript.

How do I make an Instagram style heart pop on double click?

On double click, spawn a heart element at the pointer position inside a relative container and play a keyframe that scales it from 0 to 1.2 and fades it out over about 800ms. Remove the element on animationend so repeated double clicks stay clean. Keep the like state separate from the burst effect.

How do I show a like count next to the heart button?

Put the count in a span beside the heart and bump it with a quick scale pop when the state toggles. Format large numbers as 1.2k so the layout does not widen on viral posts. Update the count in the same click handler that flips the liked state so the two never drift apart.

How do I make the heart fill with color when liked?

Transition the SVG fill from transparent or gray to red over 200ms when the liked class is added. Add a matching scale bounce on the heart itself, overshooting to 1.3 before settling at 1, which is the pop people expect. If you use an icon font instead of SVG, swap the outline and solid glyph classes at the same moment.

Customize it with our tools