<div class="box example-1 animation">example-1 <br> click me</div>

<div class="box example-2 animation">example-2 <br> click me</div>
body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  margin: 0;
  padding: 0;
}

.box {
   display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  width: 100px;
  height: 100px;
  background-color: orange;
  margin: 10px;
  cursor: pointer;
}

.animation {
  animation: fadeIn 1s ease forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}
document
  .querySelector('.example-1')
  .addEventListener('click', function () {
    this.classList.remove('animation');
    this.classList.add('animation');
  })

document
  .querySelector('.example-2')
  .addEventListener('click', function () {
    this.classList.remove('animation');
    setTimeout(() => { 
       this.classList.add('animation');
    }, 0);
  })

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.