top of page

How to create a beating heart

Writer: Web Coding
Web Coding
Nov 26, 2020
1 min read

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

*{
 padding: 0;
 margin: 0;
}

body{
 min-height: 100vh;
 display: flex;
 align-items: center;
 justify-content: center;
 background: #121212;
}

img{
 max-width: auto;
 height: 50vh;
 animation-name: heartbeat;
 animation-duration: 1s;
 animation-timing-function: linear;
 animation-iteration-count: infinite;
}

@keyframes heartbeat{
    0% {transform: scale(1);}
    20% {transform: scale(1.3);}
    30% {transform: scale(1);}
    40% {transform: scale(1.3);}
    60% {transform: scale(1);}
    100% {transform: scale(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

 
 
 

Comments


  • YouTube
  • Instagram

©2020 by Web Coding. Proudly created with Wix.com

bottom of page