<div class="shopping-container">
  <div class="counter-container">
    <span id="counter">1</span>
    <i data-feather="shopping-bag"></i>
  </div>
  <button id="add-animation">Add to Cart</button
    </div>
    
    <script src="https://unpkg.com/feather-icons"></script>
    <script>
      feather.replace()
    </script>
* {
  padding: 0;
  margin: 0;
  border: none;
}

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

body, button {
  font-family: 'Open Sans', sans-serif;
  font-size: .6rem;
}

.shopping-container {
  display: flex;
}

.shopping-container button {
  border-radius: .1rem;
  background: #ff4754;
  padding: 0 2rem;
  transition: .2s opacity;
}

.shopping-container button:hover {
  cursor: pointer;
  opacity: .8;
}

.shopping-container .counter-container {
  margin-right: 1rem;
  border: 1px solid #ffffff20;
  border-radius: .1rem;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.shopping-container .counter-container svg {
  width: 1rem;
  color: #FFF;
}

.shopping-container .counter-container span:not(.animation-counter) {
  display: none;
}

.shopping-container .counter-container span.animation-counter {
  animation: count .4s ease-in-out;
}

.shopping-container .counter-container span {
  user-select: none;
  position: absolute;
  background: #ff4754;
  width: .6rem;
  height: .6rem;
  font-size: .3rem;
  border-radius: 50%;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  top: .2rem;
  right: .3rem;
}

@keyframes count {
  from {
    top: .2rem;
    right: -1.8rem;
    transform: rotate(80deg);
  }
  
  25% {
    top: -.2rem;
    right: -1.2rem;
    transform: rotate(80deg);
  }
  
  50% {
    top: -.4rem;
    right: -.6rem;
    transform: rotate(60deg);
  }
  
  75% {
    top: -.4rem;
    right: 0;
    transform: rotate(30deg);
  }
  
  to {
    top: .2rem;
    right: .3rem;
    transform: rotate(0);
  }
}
let count = 0;

const counter = document.getElementById('counter');

document.getElementById('add-animation').addEventListener('click', event => {
  const cl = counter.classList;
  const c = 'animation-counter';
  
  count++;
  counter.innerText = count;
  
  cl.remove(c, cl.contains(c));
  
  setTimeout(() => counter.classList.add('animation-counter'), 1);
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.