top of page
Writer's pictureWeb Coding

How to create a beating heart

Today I will be teaching you how to create a beating heart for your website using CSS animation


HTML

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>Document</title>
 <link rel="stylesheet" href="style.css">
</head>
<body>
 <img src="img/heart.png" alt="heartImage">
</body>
</html>

CSS

*{
 padding0;
 margin0;
}

body{
 min-height100vh;
 displayflex;
 align-itemscenter;
 justify-contentcenter;
 background#121212;
}

img{
 max-widthauto;
 height50vh;
 animation-name: heartbeat;
 animation-duration1s;
 animation-timing-functionlinear;
 animation-iteration-countinfinite;
}

@keyframes heartbeat{
    0% {transformscale(1);}
    20% {transformscale(1.3);}
    30% {transformscale(1);}
    40% {transformscale(1.3);}
    60% {transformscale(1);}
    100% {transformscale(1);}
}

If you found this blog post helpful don’t forget to check out my other projects and if you want more content follow me on


YouTube: https://www.youtube.com/channel/UC2nxqB2usQIS2c8zwVZKWEQ

Instagram: https://www.instagram.com/coding_for_the_web/

Twitter: https://twitter.com/LearnWebCoding

18 views

Comments


bottom of page