Vertical Cards Carousel

In this tutorial, you will how to create a vertical cards carousel using pure CSS. Watch the video below for a detailed tutorial.


HTML

<div class="carousel">
	<div class="card">1</div>
	<div class="card">2</div>
	<div class="card">3</div>
	<div class="card">4</div>
	<div class="card">5</div>
</div>

CSS

body {
  background-color: #2E3537;
}

.carousel {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

.card {
  background-color: white;
  border-radius: 5px;
  position: absolute;
  width: 250px;
  height: 190px;
  padding: 20px;
  text-align: center;
  font-family: sans-serif;
  font-size: 10em;
  opacity: 0;
  will-change: transform, opacity;
  animation: carousel 15s linear infinite; /* duration should be 3 multiplied by the total number of cards */
}

/* Increment animation delay by 3 for each card */
.card:nth-child(1) {
  animation-delay: -3s;
}

.card:nth-child(2) {
  animation-delay: 0;
}

.card:nth-child(3) {
  animation-delay: 3s;
}

.card:nth-child(4) {
  animation-delay: 6s;
}

.card:last-child {
  animation-delay: 9s;
}

@keyframes  carousel {
  0% {
    transform: translateY(100%) scale(0.5);
    opacity: 0;
    visibility: hidden;
  }
  3%, 20% { /* 3, 100/total number of cards */
    transform: translateY(100%) scale(0.7);
    opacity: 0.4;
    visibility: visible;
  }
  23%, 40% { /* [(100/total number of cards) + 3], [(100/number of cards) * 2] */
    transform: translateY(0) scale(1);
    opacity: 1;
    visibility: visible;
  }
  43%, 60% { /* [(100/total number of cards)*2 + 3], [(100/number of cards) * 3] */
    transform: translateY(-100%) scale(0.7);
    opacity: 0.4;
    visibility: visible;
  }
  63% { /* [(100/total number of cards) * 3] + 3 */
    transform: translateY(-100%) scale(0.5);
    opacity: 0;
    visibility: visible;
  }
  100% {
    transform: translateY(-100%) scale(0.5);
    opacity: 0;
    visibility: hidden;
  }
}