<main>
  <h2>CSS Animations: the <code>animation-play-state</code> Property</h2>

  <p>This animation below is set to run infitely but is paused to start and can be paused or resumed using the <code>animation-play-state</code> property.</p>

  <div class="box box-animate">
  </div>

  <button disabled>Pause</button> <button>Resume</button>

</main>
body {
  font-family: Arial, sans-serif;
  font-size: 20px;
  padding: 0 20px;
}

main {
  text-align: center;
  margin: 0 auto;
  max-width: 800px;
}

p {
  padding: 0 20px;
}

code {
  color: firebrick;
}

.box {
  width: 100px;
  height: 100px;
  background: orange;
  border: solid 2px;
  margin-bottom: 20px;
}

.box-animate {
  animation-name: moveObject;
  animation-duration: 2s;
  animation-direction: alternate;
  animation-iteration-count: infinite;
  animation-timing-function: linear;
  animation-play-state: paused;
}

@keyframes moveObject {
  from {
    transform: translateX(0);
  }

  to {
    transform: translateX(600px);
  }
}

input[type=number] {
  width: 60px;  
}

button {
  margin-top: 20px;
}
console.clear();

let myObject = document.querySelector('.box'),
    btn1 = document.querySelector('button'),
    btn2 = document.querySelectorAll('button')[1];

btn1.addEventListener('click', function () {
  myObject.style.animationPlayState = 'paused';
  this.disabled = true;
  btn2.disabled = false;
}, false);

btn2.addEventListener('click', function () {
  myObject.style.animationPlayState = 'running';
  this.disabled = true;
  btn1.disabled = false;
}, false);

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.