DEV Community

Cover image for ๐Ÿš€ Create a Cute Heartbeat Animation with Pure CSS (Easily Add to Your Website!) โค๏ธ
Raj Aryan
Raj Aryan

Posted on

๐Ÿš€ Create a Cute Heartbeat Animation with Pure CSS (Easily Add to Your Website!) โค๏ธ

Hey devs! ๐Ÿ‘‹ Want to add a little life to your website? Letโ€™s create a cute heartbeat animation using just CSS! Itโ€™s simple, lightweight, and perfect for adding a playful touch to your design. Letโ€™s dive in! ๐ŸŽ‰


Step 1: The HTML Structure

All you need is a single div to create the heart. Keep it clean and simple!

<div class="heartbeat"></div>
Enter fullscreen mode Exit fullscreen mode

Step 2: The CSS Magic

Hereโ€™s where the fun begins! Weโ€™ll use @keyframes to create the heartbeat effect.

.heartbeat {
  width: 100px;
  height: 100px;
  background-color: red;
  position: relative;
  transform: rotate(-45deg); /* Rotate to make it look like a heart */
  animation: beat 1.5s infinite; /* Add the heartbeat animation */
  margin: 100px auto; /* Center it on the page */
}

.heartbeat::before,
.heartbeat::after {
  content: '';
  width: 100px;
  height: 100px;
  background-color: red;
  border-radius: 50%; /* Make it round */
  position: absolute;
}

.heartbeat::before {
  top: -50px;
  left: 0;
}

.heartbeat::after {
  top: 0;
  left: 50px;
}

/* Heartbeat Animation */
@keyframes beat {
  0% {
    transform: scale(1) rotate(-45deg);
  }
  50% {
    transform: scale(1.1) rotate(-45deg);
  }
  100% {
    transform: scale(1) rotate(-45deg);
  }
}
Enter fullscreen mode Exit fullscreen mode

Step 3: Add It to Your Website

Just copy the HTML and CSS into your project, and youโ€™re done! You can customize the size, color, and animation speed to fit your design.


Why This Works

  • Pure CSS: No JavaScript needed! ๐ŸŽ‰
  • Lightweight: Perfect for performance-focused websites.
  • Customizable: Change the color, size, or animation duration to match your brand.

Pro Tip ๐Ÿ’ก

Use this animation for:

  • Loading screens ๐Ÿ•’
  • Call-to-action buttons ๐Ÿ””
  • Valentineโ€™s Day themes ๐Ÿ’˜
  • Health or fitness websites ๐Ÿ‹๏ธโ€โ™‚๏ธ

Try it out and watch your website come to life! โค๏ธ

Let me know in the comments how youโ€™re using this animation. And donโ€™t forget to share this post with your fellow devs! ๐Ÿš€


CSS #WebDesign #Animation #Frontend #DevTips #WebDev #UIUX

Top comments (0)