Pulsing Heart CSS animation

Fernando Souza picture Fernando Souza · Jan 13, 2016 · Viewed 59.6k times · Source

I`m working on an animated heart only with CSS.

I want it to pulse 2 times, take a small break, and then repeat it again.

What I have now:

small ==> big ==> small ==> repeat animation

What I'm going for:

small ==> big ==> small ==> big ==> small ==> pause ==> repeat animation

How can I do it?

My code :

See also this Fiddle.

Answer

Rein picture Rein · Jan 13, 2016

You can incorporate the pause into the animation. Like so:

@keyframes heartbeat
{
  0%
  {
    transform: scale( .75 );
  }
  20%
  {
    transform: scale( 1 );
  }
  40%
  {
    transform: scale( .75 );
  }
  60%
  {
    transform: scale( 1 );
  }
  80%
  {
    transform: scale( .75 );
  }
  100%
  {
    transform: scale( .75 );
  }
}

Working example: https://jsfiddle.net/t7f97kf4/

@keyframes heartbeat
{
  0%
  {
    transform: scale( .75 );
  }
  20%
  {
    transform: scale( 1 );
  }
  40%
  {
    transform: scale( .75 );
  }
  60%
  {
    transform: scale( 1 );
  }
  80%
  {
    transform: scale( .75 );
  }
  100%
  {
    transform: scale( .75 );
  }
}

div
{
  background-color: red;
  width: 50px;
  height: 50px;
  animation: heartbeat 1s infinite;
}
<div>
Heart
</div>

Edit:

Working example with pure CSS heart shape: https://jsfiddle.net/qLfg2mrd/

@keyframes heartbeat
{
  0%
  {
    transform: scale( .75);
  }
  
  20%
  {
    transform: scale( 1);
  }
  
  40%
  {
    transform: scale( .75);
  }
  
  60%
  {
    transform: scale( 1);
  }
  80% {
    transform: scale( .75);
  }
  
  100%
  {
    transform: scale( .75);
  }
}

#heart
{
  position: relative;
  width: 100px;
  height: 90px;
  animation: heartbeat 1s infinite;
}

#heart:before,
#heart:after
{
  position: absolute;
  content: "";
  left: 50px;
  top: 0;
  width: 50px;
  height: 80px;
  background: red;
  -moz-border-radius: 50px 50px 0 0;
  border-radius: 50px 50px 0 0;
  -webkit-transform: rotate(-45deg);
  -moz-transform: rotate(-45deg);
  -ms-transform: rotate(-45deg);
  -o-transform: rotate(-45deg);
  transform: rotate(-45deg);
  -webkit-transform-origin: 0 100%;
  -moz-transform-origin: 0 100%;
  -ms-transform-origin: 0 100%;
  -o-transform-origin: 0 100%;
  transform-origin: 0 100%;
}

#heart:after
{
  left: 0;
  -webkit-transform: rotate(45deg);
  -moz-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  -o-transform: rotate(45deg);
  transform: rotate(45deg);
  -webkit-transform-origin: 100% 100%;
  -moz-transform-origin: 100% 100%;
  -ms-transform-origin: 100% 100%;
  -o-transform-origin: 100% 100%;
  transform-origin: 100% 100%;
}
<div id="heart"></div>