How to Add Testimonials using HTML? Last Updated : 25 Jul, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Testimonials are Written recommendations from users and are often seen in a separate section of a web page. In this article, we will learn how to add responsive testimonials to our web page. Generally, a testimonial contains the user’s name, picture, his/her identity(optional), and most importantly his/her quoted text. ApproachWe will begin by creating a basic HTML structure for our carousel. This structure will include a main container that houses the carousel itself and navigation buttons. The carousel will be designed to display testimonials dynamically.For styling, we'll use CSS to create an appealing and responsive design. The carousel will be centered on the page, and we'll employ flexbox to enable smooth horizontal scrolling of testimonials. Each testimonial will be styled as a card-like element, containing an avatar image, the name of the person providing the testimonial, and their message.To ensure responsiveness, we'll implement media queries in our CSS. For screens narrower than 768px, the carousel will display a single testimonial at a time.On wider screens, it will showcase three testimonials side by side, with the center one enlarged and fully opaque, while the side testimonials are slightly scaled down and semi-transparent.The JavaScript portion of our code will handle the dynamic functionality of the carousel. We'll start by defining an array of testimonial objects, each containing a name and text.We'll then create functions to generate HTML elements for each testimonial, update the carousel display based on the current index, and manage navigation through the testimonials.Our code will include event listeners for the navigation buttons and for window resizing. This will allow users to manually cycle through testimonials and ensure that the carousel adapts appropriately when the screen size changes.Lastly, we'll include an option for auto-scrolling through the testimonials, which can be easily enabled or disabled by uncommenting a single line of code.Example: In this Example, we will use the above discussed approach. html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Circular Testimonial Carousel</title> <link rel="stylesheet" href="styles.css"> </head> <body> <div class="carousel-container"> <div class="carousel"> <!-- Testimonials will be dynamically added here --> </div> <button class="nav-button prev">‹</button> <button class="nav-button next">›</button> </div> <script src="script.js"></script> </body> </html> CSS * { box-sizing: border-box; margin: 0; padding: 0; } body { font-family: 'Arial', sans-serif; display: flex; justify-content: center; align-items: center; min-height: 100vh; background-color: #f0f0f0; } .carousel-container { width: 90%; max-width: 1200px; overflow: hidden; position: relative; } .carousel { display: flex; transition: transform 0.5s ease; } .testimonial { flex: 0 0 100%; padding: 40px; background-color: white; border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,0.1); margin: 0 10px; transition: all 0.3s ease; } .testimonial img { width: 80px; height: 80px; border-radius: 50%; margin-bottom: 20px; object-fit: cover; } .testimonial h3 { margin-bottom: 10px; color: #333; font-size: 1.4em; } .testimonial p { font-size: 1em; color: #666; line-height: 1.6; } .nav-button { position: absolute; top: 50%; transform: translateY(-50%); background-color: rgba(255,255,255,0.8); border: none; font-size: 24px; padding: 15px; cursor: pointer; border-radius: 50%; box-shadow: 0 2px 10px rgba(0,0,0,0.1); transition: all 0.3s ease; z-index: 10; } .nav-button:hover { background-color: white; box-shadow: 0 4px 15px rgba(0,0,0,0.2); } .prev { left: 20px; } .next { right: 20px; } @media (min-width: 768px) { .carousel { display: flex; justify-content: center; align-items: center; } .testimonial { flex: 0 0 calc(33.333% - 20px); transform: scale(0.8); opacity: 0.7; transition: all 0.5s ease; } .testimonial.active { transform: scale(1.1); opacity: 1; z-index: 1; } } JavaScript const carousel = document.querySelector('.carousel'); const prevBtn = document.querySelector('.prev'); const nextBtn = document.querySelector('.next'); const testimonials = [ { name: "John Doe", text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." }, { name: "Jane Smith", text: "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." }, { name: "Bob Johnson", text: "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur." }, { name: "Alice Brown", text: "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." }, { name: "Charlie Davis", text: "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium." } ]; let currentIndex = 0; function createTestimonialElement(testimonial, index) { const div = document.createElement('div'); div.className = 'testimonial'; div.innerHTML = ` <img src="https://picsum.photos/80?random=${index}" alt="${testimonial.name}"> <h3>${testimonial.name}</h3> <p>${testimonial.text}</p> `; return div; } function updateCarousel() { carousel.innerHTML = ''; const isMobile = window.innerWidth < 768; if (isMobile) { carousel.appendChild(createTestimonialElement(testimonials[currentIndex], currentIndex)); } else { const prevIndex = (currentIndex - 1 + testimonials.length) % testimonials.length; const nextIndex = (currentIndex + 1) % testimonials.length; carousel.appendChild(createTestimonialElement(testimonials[prevIndex], prevIndex)); const activeTestimonial = createTestimonialElement(testimonials[currentIndex], currentIndex); activeTestimonial.classList.add('active'); carousel.appendChild(activeTestimonial); carousel.appendChild(createTestimonialElement(testimonials[nextIndex], nextIndex)); } } function showNext() { currentIndex = (currentIndex + 1) % testimonials.length; updateCarousel(); } function showPrev() { currentIndex = (currentIndex - 1 + testimonials.length) % testimonials.length; updateCarousel(); } nextBtn.addEventListener('click', showNext); prevBtn.addEventListener('click', showPrev); // Responsive behavior function handleResize() { updateCarousel(); } window.addEventListener('resize', handleResize); // Initial setup updateCarousel(); // Auto-scroll (optional) // setInterval(showNext, 5000); Output: Comment More infoAdvertise with us Next Article How to Add a Short Quotation using HTML? A argha_c14 Follow Improve Article Tags : Technical Scripter Web Technologies HTML HTML-Misc HTML-Questions +1 More Similar Reads How to Add a Short Quotation using HTML? For defining a short quotation by using an <q> tag. It is used to insert quotation texts on a web page, i.e. a portion of texts different from the normal texts. Syntax:<q> Quotation Text... </q>Example 1: The example below shows how to Add a Short Quotation using HTML5. html <!D 1 min read How to add Testimonials in Next.js ? In this article, we are going to learn how we can add the Testimonials in NextJs. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components con 2 min read Create a Testimonial Card Using HTML and CSS In this tutorial, we're going to create a testimonial card that can be used on websites to display feedback from clients or customers. Testimonials are an excellent way to add social proof to your site, enhancing credibility and trust among visitors. Weâll create a testimonial card with:A speech bub 4 min read How to use Mailto in HTML? The mailto link in HTML allows users to easily send emails by opening their default email application when clicked. It can include important details like the recipientâs email address, subject line, body, and optional fields such as CC and BCC, making it convenient for direct communication or feedba 5 min read How to write e-mails in HTML and send it using Gmail ? In this article, we are going to learn that how users can write e-mails in HTML format and send them using Gmail. However, Gmail doesn't offer an HTML editor still we can send HTML templates in an e-mail using some tools and methods. Many people need to send an e-mail with HTML templates to others. 3 min read Design a Testimonial Page using Tailwind CSS Testimonials are written recommendations from users and are often displayed in a separate section of a web page. Generally, a testimonial contains the user's name, picture, identity (optional), and most importantly, their quoted text. Preview CDN Link<link href="https://cdn.jsdelivr.net/npm/tailw 3 min read Like