How to Build a Mobile-Friendly Testimonial Card carousel using HTML, CSS & JavaScript



Hello developers, In this post, we'll examine how to build a testimonial card carousel using HTML, CSS, and JavaScript. A testimonial card carousel is a great way to showcase customer feedback and testimonials on your website. Let's take a look at the HTML code above. Each testimonial card consists of a user picture, testimonial content, and the name and position of the user. Each card also has an image, testimonial content, and the name and position of the user. The CSS code controls the layout of the testimonial card carousel. The carousel is 90% wide and 500px high with a max width of 800px and a max height of 500px. The position: absolute keyword is used to position the testimonial cards. The function setNextCard is used to determine which card should be made visible next. The current card variable is set to 0, which refers to the first card. The function showNextCard is used to determine which card should be made visible next. It works by multiplying the current card by the current card.

Testimonial Card carousel using HTML, CSS & JavaScript [Source Code]

To make this website, you would like to make three files: an HTML file, a CSS file & a JavaScript file. First, create an HTML file with the name of index.html and remember, you have to create a file with a .html extension.

<!DOCTYPE html> <html> <head> <title>Testimonial card carousel</title> <link rel="stylesheet" type="text/css" href="style.css"> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <div class="carousel-container"> <div class="testimonial-card active"> <div class="user-image"> <img src="https://cdn.pixabay.com/photo/2015/01/08/18/29/entrepreneur-593358__480.jpg" alt="User 1"> </div> <div class="testimonial-content"> <p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi consequat vitae tellus ac faucibus. Donec lacinia sapien quis ex tristique eleifend. Proin ut sem nec justo porta gravida."</p> <h4>John Doe</h4> <span>CEO, Company XYZ</span> <div class="credit">Made with <span style="color:tomato;font-size:20px;">❤ </span>by<a href="https://www.learningrobo.com/"> Learning Robo</a></div> </div> </div> <div class="testimonial-card"> <div class="user-image"> <img src="https://cdn.pixabay.com/photo/2016/11/21/12/42/beard-1845166__480.jpg" alt="User 2"> </div> <div class="testimonial-content"> <p>"Vestibulum in tellus eu lectus efficitur ullamcorper nec et metus. In blandit nibh eget nunc vestibulum suscipit. Etiam in dui ac purus finibus fringilla non non est."</p> <h4>Jane Smith</h4> <span>Marketing Manager, Company ABC</span> <div class="credit">Made with <span style="color:tomato;font-size:20px;">❤ </span>by<a href="https://www.learningrobo.com/"> Learning Robo</a></div> </div> </div> <div class="testimonial-card"> <div class="user-image"> <img src="https://cdn.pixabay.com/photo/2015/07/20/12/57/ambassador-852766__480.jpg" alt="User 3"> </div> <div class="testimonial-content"> <p>"Sed euismod magna eget arcu bibendum, vel maximus turpis congue. Fusce id nulla a ante bibendum consectetur. Suspendisse sollicitudin nulla nec pharetra suscipit."</p> <h4>David Lee</h4> <span>CTO, Company QRS</span> <div class="credit">Made with <span style="color:tomato;font-size:20px;">❤ </span>by<a href="https://www.learningrobo.com/"> Learning Robo</a></div> </div> </div> <div class="testimonial-card"> <div class="user-image"> <img src="https://cdn.pixabay.com/photo/2017/11/02/14/27/model-2911332__480.jpg" alt="User 3"> </div> <div class="testimonial-content"> <p>"Sed euismod magna eget arcu bibendum, vel maximus turpis congue. Fusce id nulla a ante bibendum consectetur. Suspendisse sollicitudin nulla nec pharetra suscipit."</p> <h4>David Lee</h4> <span>CTO, Company QRS</span> <div class="credit">Made with <span style="color:tomato;font-size:20px;">❤ </span>by<a href="https://www.learningrobo.com/"> Learning Robo</a></div> </div> </div> </div> <script src="script.js"></script> </body> </html>
CSS provides style to an HTML page. To make the page attractive create a CSS file with the name style.css and remember that you have to make a file with a .css extension.


body {
  font-family: Arial, sans-serif;
  padding: 20px;
  background: #180835;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
html, body {
  height: 100%;
}

.carousel-container {
  width: 90%;
  max-width: 800px;
  height: 500px;
  position: relative;
  
}

.testimonial-card {
  width: 90%;
  position: absolute;
  display: flex; /* Change to flex */
  justify-content: center; /* Center horizontally */
  opacity:0;
  background: #8E2DE2;  /* fallback for old browsers */
background: -webkit-linear-gradient(to right, #4A00E0, #8E2DE2);  /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #4A00E0, #8E2DE2); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */

  padding: 20px;
  border-radius: 200px 20px 20px 200px;
  transition: transform 0.6s ease, opacity 0.6s ease;
}

@media only screen and (max-width: 860px) {
  .testimonial-card
   {
   flex-direction: column;
   margin: 10px;
   border-radius: 20px 120px 20px 130px;
  }
}
@media only screen and (max-width: 600px) {
  .testimonial-card
   {
   flex-direction: column;
   margin: 10px;
   border-radius: 200px 200px 20px 20px;
  }
}
.user-image {
  display: flex;
  justify-content: center;
  align-items: center;
}

.user-image img {
  width: 200px;
  height: 200px;
  object-fit: cover;
  border-radius: 50%;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
  border: 10px solid #fff;
}

.testimonial-content {
  margin: 20px;
  text-align: center;
  background-color: #fff;
  border-radius: 20px;
padding:10px;
height:auto;
min-height: 250px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

.testimonial-content p {
  font-size: 18px;
  line-height: 1.5;
  margin-bottom: 20px;
}

.testimonial-content h4 {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 5px;
}

.testimonial-content span {
  font-size: 16px;
  color: #666;
}
.credit a {
  text-decoration: none;
  color: #000;
  font-weight: 800;
}

.credit {
  text-align: center;
  margin-top: 10px;
  font-family: Verdana,Geneva,Tahoma,sans-serif;
}
.testimonial-card.active {
  opacity: 1;
}

.testimonial-card.prev {
  opacity: 1;
}



.testimonial-card::before {
  content: "";
  z-index: -1;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: linear-gradient(-45deg, #4A00E0 0%, #8E2DE2 100% );
  transform: translate3d(0px, 0px, 0) scale(0.99);
  filter: blur(22px);
  opacity: var(0.7);
  transition: opacity 0.3s;
  border-radius: inherit;
}
.testimonial-card::after {
  content: "";
  z-index: -1;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: inherit;
  border-radius: inherit;
}
      
      

JavaScript makes the page work functionally. At last, create a JavaScript file with the name script.js and remember that you have got need to make a file with a .js extension.


const carouselContainer = document.querySelector('.carousel-container');
const testimonialCards = carouselContainer.querySelectorAll('.testimonial-card');
const totalCards = testimonialCards.length;
let currentCard = 0;

function showNextCard() {
  const nextCard = (currentCard + 1) % totalCards;
  testimonialCards[currentCard].classList.remove('active');
   testimonialCards[nextCard].classList.add('active');
  currentCard = nextCard;
}

setInterval(showNextCard, 5000);
We hope you would like this Testimonial Card carousel using HTML, CSS & JavaScript.

Thank you for reading our blog. If you face any problem in creating this Testimonial Card Slider using HTML, CSS & JavaScript, then contact us or comment to us. We’ll try to provide a solution to your problem as soon as possible.

Press The Key ' p ' and say ' read article ' our voice assistant read our article.
In Our older post it doesnot work we working on that.

Thank you
Learning robo team

Post a Comment

Thank you
Learning robo team

Post a Comment (0)

Previous Post Next Post
Learning Robo says...
code copied
Welcome