Image Carousel
Preview
Edit
Download
Run
Download Options
HTML File
Download as .html file
CSS File
Download as .css file
JavaScript File
Download as .js file
Combined HTML
All code in one HTML file
Project ZIP
All files in a ZIP archive
Cancel
HTML
<div class="carousel-container"> <div class="carousel" id="carousel"> <div class="slide active"> <img src="https://images.unsplash.com/photo-1522071820081-009f0129c71c?ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80" alt="Slide 1"> <div class="caption">Future City</div> </div> <div class="slide"> <img src="https://images.unsplash.com/photo-1552664730-d307ca884978?ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80" alt="Slide 2"> <div class="caption">Cyber Dreams</div> </div> <div class="slide"> <img src="https://images.unsplash.com/photo-1493612276216-ee3925520721?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=80" alt="Slide 3"> <div class="caption">AI Revolution</div> </div> </div> <button class="nav prev" onclick="prevSlide()">❮</button> <button class="nav next" onclick="nextSlide()">❯</button> </div>
CSS
* { box-sizing: border-box; margin: 0; padding: 0; } body { background: linear-gradient(135deg, #0f2027, #203a43, #2c5364); font-family: 'Segoe UI', sans-serif; height: 100vh; display: flex; justify-content: center; align-items: center; overflow-x: hidden; } .carousel-container { position: relative; width: 90%; max-width: 1200px; aspect-ratio: 16 / 9; overflow: hidden; border-radius: 20px; backdrop-filter: blur(10px); box-shadow: 0 0 40px rgba(0, 255, 255, 0.2); } .carousel { display: flex; transition: transform 0.6s ease-in-out; } .slide { min-width: 100%; position: relative; transition: opacity 0.6s ease; } .slide img { width: 100%; height: 100%; object-fit: cover; } .caption { position: absolute; bottom: 20px; left: 30px; color: #fff; font-size: 2rem; background: rgba(0, 0, 0, 0.3); padding: 10px 20px; border-radius: 12px; backdrop-filter: blur(5px); text-shadow: 0 0 10px cyan; } .nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(0,0,0,0.4); border: none; color: cyan; font-size: 2.5rem; padding: 10px 20px; cursor: pointer; z-index: 1; transition: background 0.3s ease; } .nav:hover { background: rgba(0,0,0,0.7); } .prev { left: 10px; } .next { right: 10px; } /* Responsive Styles */ @media (max-width: 768px) { .caption { font-size: 1.4rem; left: 20px; right: 20px; } .nav { font-size: 2rem; } } @media (max-width: 480px) { .caption { font-size: 1rem; } .nav { padding: 5px 10px; } }
JavaScript
let index = 0; const slides = document.querySelectorAll(".slide"); function showSlide(i) { slides.forEach((slide, idx) => { slide.classList.remove("active"); slide.style.transform = `translateX(-${i * 100}%)`; }); slides[i].classList.add("active"); } function nextSlide() { index = (index + 1) % slides.length; showSlide(index); } function prevSlide() { index = (index - 1 + slides.length) % slides.length; showSlide(index); } // Auto-slide every 5 seconds setInterval(nextSlide, 5000);
Output Preview
Desktop
Mobile
Fullscreen