Let’s create a Cool Responsive Card Slider using HTML, CSS, and JavaScript. This project will feature a slider that showcases multiple cards, offering a seamless and interactive experience across all screen sizes.
We’ll use HTML to structure the slider, CSS to style it and ensure responsiveness, and JavaScript to handle the sliding functionality and interactions.
Let’s get started on building the Cool Responsive Card Slider. Whether you’re a beginner or an experienced developer, this project is a great way to enhance your web development skills and create an engaging element for your websites. Let’s slide into action!
HTML :
This HTML sets up a Swiper slider displaying cards with images, badges, titles, and buttons. It includes pagination, navigation buttons, and links external styles and scripts for functionality and design.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Card Slider HTML & CSS | @coding.stella</title> <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@24,400,0,0" /> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css"> <link rel="stylesheet" href="style.css"> </head> <body> <div class="container swiper"> <div class="card-wrapper"> <!-- Card slides container --> <ul class="card-list swiper-wrapper"> <li class="card-item swiper-slide"> <a href="#" class="card-link"> <img src="images/designer.jpg" alt="Card Image" class="card-image"> <p class="badge badge-designer">Designer</p> <h2 class="card-title">Lorem ipsum dolor sit explicabo adipisicing elit</h2> <button class="card-button material-symbols-rounded">arrow_forward</button> </a> </li> <li class="card-item swiper-slide"> <a href="#" class="card-link"> <img src="images/developer.png" alt="Card Image" class="card-image"> <p class="badge badge-developer">Developer</p> <h2 class="card-title">Lorem ipsum dolor sit explicabo adipisicing elit</h2> <button class="card-button material-symbols-rounded">arrow_forward</button> </a> </li> <li class="card-item swiper-slide"> <a href="#" class="card-link"> <img src="images/marketer.jpg" alt="Card Image" class="card-image"> <p class="badge badge-marketer">Marketer</p> <h2 class="card-title">Lorem ipsum dolor sit explicabo adipisicing elit</h2> <button class="card-button material-symbols-rounded">arrow_forward</button> </a> </li> <li class="card-item swiper-slide"> <a href="#" class="card-link"> <img src="images/gamer.jpg" alt="Card Image" class="card-image"> <p class="badge badge-gamer">Gamer</p> <h2 class="card-title">Lorem ipsum dolor sit explicabo adipisicing elit</h2> <button class="card-button material-symbols-rounded">arrow_forward</button> </a> </li> <li class="card-item swiper-slide"> <a href="#" class="card-link"> <img src="images/editor.jpg" alt="Card Image" class="card-image"> <p class="badge badge-editor">Editor</p> <h2 class="card-title">Lorem ipsum dolor sit explicabo adipisicing elit</h2> <button class="card-button material-symbols-rounded">arrow_forward</button> </a> </li> </ul> <!-- Pagination --> <div class="swiper-pagination"></div> <!-- Navigation Buttons --> <div class="swiper-slide-button swiper-button-prev"></div> <div class="swiper-slide-button swiper-button-next"></div> </div> </div> <!-- Linking SwiperJS script --> <script src="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js"></script> <!-- Linking custom script --> <script src="script.js"></script> </body> </html>
CSS :
This CSS styles a responsive card slider with a gradient background, rounded white cards, hover effects, badges, and a clean modern design. It ensures smooth interactions, pagination styling, and hides navigation buttons on smaller screens.
@import url('https://fonts.googleapis.com/css2?family=Inter:opsz,wght@14..32,100..900&display=swap'); * { margin: 0; padding: 0; box-sizing: border-box; font-family: "Inter", sans-serif; } body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(#ECEFFE, #C5CFFC); } .card-wrapper { max-width: 1100px; margin: 0 60px 35px; padding: 20px 10px; overflow: hidden; } .card-list .card-item { list-style: none; } .card-list .card-item .card-link { display: block; background: #fff; padding: 18px; user-select: none; border-radius: 12px; text-decoration: none; border: 2px solid transparent; box-shadow: 0 10px 10px rgba(0, 0, 0, 0.05); transition: 0.2s ease; } .card-list .card-item .card-link:active { cursor: grabbing; } .card-list .card-item .card-link:hover { border-color: #5372F0; } .card-list .card-link .card-image { width: 100%; border-radius: 10px; aspect-ratio: 16 / 9; object-fit: cover; } .card-list .card-link .badge { color: #5372F0; width: fit-content; padding: 8px 16px; font-size: 0.95rem; border-radius: 50px; font-weight: 500; background: #DDE4FF; margin: 16px 0 18px; } .card-list .card-link .badge-designer { color: #B22485; background: #F7DFF5; } .card-list .card-link .badge-marketer { color: #B25A2B; background: #FFE3D2; } .card-list .card-link .badge-gamer { color: #205C20; background: #D6F8D6; } .card-list .card-link .badge-editor { color: #856404; background: #fff3cd; } .card-list .card-link .card-title { color: #000; font-size: 1.19rem; font-weight: 600; } .card-list .card-link .card-button { height: 35px; width: 35px; color: #5372F0; margin: 30px 0 5px; background: none; cursor: pointer; border-radius: 50%; border: 2px solid #5372F0; transform: rotate(-45deg); transition: 0.4s ease; } .card-list .card-link:hover .card-button { color: #fff; background: #5372F0; } .card-wrapper .swiper-pagination-bullet { height: 13px; width: 13px; opacity: 0.5; background: #5372F0; } .card-wrapper .swiper-pagination-bullet-active { opacity: 1; } .card-wrapper .swiper-slide-button { color: #5372F0; margin-top: -35px; } /* Responsive media query code for small screens */ @media (max-width: 768px) { .card-wrapper { margin: 0 10px 25px; } .card-wrapper .swiper-slide-button { display: none; } }
JavaScript:
This code initializes a Swiper slider on elements with the class .card-wrapper
. It enables looping, sets space between slides to 30px, adds clickable pagination bullets, navigation arrows, and adjusts the number of visible slides based on screen width (1 for small, 2 for medium, and 3 for large screens).
new Swiper('.card-wrapper', { loop: true, spaceBetween: 30, // Pagination bullets pagination: { el: '.swiper-pagination', clickable: true, dynamicBullets: true }, // Navigation arrows navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', }, // Responsive breakpoints breakpoints: { 0: { slidesPerView: 1 }, 768: { slidesPerView: 2 }, 1024: { slidesPerView: 3 } } });
In conclusion, building a Cool Responsive Card Slider using HTML, CSS, and JavaScript has been an exciting and educational journey. By combining HTML for structure, CSS for styling and responsiveness, and JavaScript for interactivity, we’ve crafted a dynamic and user-friendly slider.
If your project has problems, don’t worry. Just click to download the source code and face your coding challenges with excitement. Have fun coding!