22 Apr 2023

Building a responsive testimonial slider with HTML and CSS

Testimonials are a great way to showcase the success stories of your business or services. They can help build trust and credibility among potential customers. And what's better than displaying these testimonials in a slider format on your website? In this tutorial, we will go through the steps to create a responsive testimonial slider with HTML and CSS.

Step 1: Setting up the HTML structure

First, let's create the basic HTML structure for our testimonial slider. We will use a div container to hold all the testimonial items, and each testimonial item will consist of a quote and the author's name.

<div class="testimonial-slider">
  <div class="testimonial">
    <blockquote>"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere erat a ante."</blockquote>
    <cite>- John Doe</cite>
  </div>
  <div class="testimonial">
    <blockquote>"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas."</blockquote>
    <cite>- Jane Doe</cite>
  </div>
  <!-- Add more testimonial items here -->
</div>

Step 2: Styling the testimonial slider

Now let's add some CSS styles to make our testimonial slider look good. We will use a simple card layout for each testimonial item and use Flexbox to align them in a row.

.testimonial-slider {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.testimonial {
  background-color: #f7f7f7;
  border-radius: 5px;
  box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.2);
  margin-right: 20px;
  padding: 20px;
  width: 400px;
  flex: 0 0 auto;
}

.testimonial blockquote {
  font-size: 1.2rem;
  margin: 0;
  padding: 0;
}

.testimonial cite {
  display: block;
  font-size: 1.1rem;
  font-style: normal;
  margin-top: 10px;
  text-align: right;
}

Let's go over the CSS styles we just added:

Step 3: Making the slider responsive

Our testimonial slider looks good, but it is not yet fully responsive. Let's add some media queries to make it look good on smaller screens.

@media (max-width: 768px) {
  .testimonial-slider {
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .testimonial {
    margin-bottom: 20px;
    width: 80%;
  }
}

In the above media query, we made the following changes:

Step 4: Adding animation to the slider

Finally, let's add some animation to our testimonial slider. We will use CSS transitions to create a smooth sliding effect when the user scrolls the slider.

.testimonial-slider {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  transition: transform 0.3s ease-in-out;
}

.testimonial-slider::-webkit-scrollbar {
  height: 5px;
}

.testimonial-slider::-webkit-scrollbar-thumb {
  background-color: #ccc;
  border-radius: 5px;
}

.testimonial-slider:hover {
  transform: scale(1.02);
}

Let's break down the changes we made:

And there you have it, a fully responsive testimonial slider with HTML and CSS! You can further customize the slider by adding more styles, changing the animation, or using JavaScript to add additional functionality.

Before we wrap up, let's review what we've learned:

With these skills, you can create and customize your own testimonial slider to fit the needs of your website. Remember to keep the user experience in mind and test your slider on various devices to ensure it looks and functions properly.

Happy coding!

You may also like

Building a responsive testimonial grid with HTML and CSS

Building a responsive testimonial grid is a great way to showcase yo...

Continue reading

Building a responsive pricing slider with HTML, CSS, and JavaScript

Build a responsive pricing slider with HTML, CSS, and JavaScript: fo...

Continue reading

Creating a responsive testimonial rotator with HTML, CSS, and JavaScript

In this tutorial, we will show you how to create a responsive testim...

Continue reading