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>
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);
}
}
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! ๐
Top comments (0)