Modern Image Slider
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
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Modern Image Scroller</title> </head> <body> <div class="carousel-container"> <div class="carousel"> <div class="slide"> <img src="https://images.unsplash.com/photo-1511671782779-c97d3d27a1d4?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1470&q=80" alt="Nature"> <div class="slide-content"> <h2>Beautiful Nature</h2> <p>Explore the wonders of the natural world</p> </div> </div> <div class="slide"> <img src="https://images.unsplash.com/photo-1470225620780-dba8ba36b745?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1470&q=80" alt="City"> <div class="slide-content"> <h2>Urban Landscapes</h2> <p>Discover vibrant city life and architecture</p> </div> </div> <div class="slide"> <img src="https://source.unsplash.com/random/1000x500?technology" alt="Technology"> <div class="slide-content"> <h2>Modern Technology</h2> <p>Innovations shaping our future</p> </div> </div> <div class="slide"> <img src="https://images.unsplash.com/photo-1470225620780-dba8ba36b745?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1470&q=80" alt="Travel"> <div class="slide-content"> <h2>Adventure Awaits</h2> <p>Find your next dream destination</p> </div> </div> </div> <button class="nav-btn" id="prevBtn">❮</button> <button class="nav-btn" id="nextBtn">❯</button> <div class="dots-container"></div> </div> </body> </html>
CSS
* { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Arial', sans-serif; background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%); min-height: 100vh; display: flex; justify-content: center; align-items: center; padding: 20px; } .carousel-container { max-width: 1000px; width: 100%; position: relative; overflow: hidden; border-radius: 15px; box-shadow: 0 20px 30px rgba(0, 0, 0, 0.2); } .carousel { display: flex; transition: transform 0.5s ease-in-out; height: 500px; } @media (max-width: 768px) { .carousel { height: 350px; } } @media (max-width: 480px) { .carousel { height: 250px; } } .slide { min-width: 100%; position: relative; } .slide img { width: 100%; height: 100%; object-fit: cover; } .slide-content { position: absolute; bottom: 0; left: 0; right: 0; padding: 30px; background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent); color: white; } .slide-content h2 { font-size: 2rem; margin-bottom: 10px; text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5); } .slide-content p { font-size: 1rem; opacity: 0.9; } .nav-btn { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255, 255, 255, 0.3); color: white; border: none; font-size: 1.5rem; padding: 15px; cursor: pointer; border-radius: 50%; backdrop-filter: blur(5px); transition: all 0.3s ease; z-index: 10; } .nav-btn:hover { background: rgba(255, 255, 255, 0.5); } #prevBtn { left: 20px; } #nextBtn { right: 20px; } .dots-container { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; gap: 10px; z-index: 10; } .dot { width: 12px; height: 12px; border-radius: 50%; background: rgba(255, 255, 255, 0.5); cursor: pointer; transition: all 0.3s ease; } .dot.active { background: white; transform: scale(1.2); } @media (max-width: 480px) { .slide-content { padding: 15px; } .slide-content h2 { font-size: 1.5rem; } .slide-content p { font-size: 0.8rem; } .nav-btn { padding: 10px; font-size: 1rem; } .dot { width: 8px; height: 8px; } }
JavaScript
document.addEventListener('DOMContentLoaded', function() { const carousel = document.querySelector('.carousel'); const slides = document.querySelectorAll('.slide'); const prevBtn = document.getElementById('prevBtn'); const nextBtn = document.getElementById('nextBtn'); const dotsContainer = document.querySelector('.dots-container'); let currentIndex = 0; let slideInterval; const slideDuration = 5000; // 5 seconds // Create dots slides.forEach((_, index) => { const dot = document.createElement('div'); dot.classList.add('dot'); if (index === 0) dot.classList.add('active'); dot.addEventListener('click', () => goToSlide(index)); dotsContainer.appendChild(dot); }); const dots = document.querySelectorAll('.dot'); // Set up auto-slide function startAutoSlide() { slideInterval = setInterval(() => { nextSlide(); }, slideDuration); } function resetAutoSlide() { clearInterval(slideInterval); startAutoSlide(); } function updateCarousel() { carousel.style.transform = `translateX(-${currentIndex * 100}%)`; // Update dots dots.forEach((dot, index) => { dot.classList.toggle('active', index === currentIndex); }); } function nextSlide() { currentIndex = (currentIndex + 1) % slides.length; updateCarousel(); resetAutoSlide(); } function prevSlide() { currentIndex = (currentIndex - 1 + slides.length) % slides.length; updateCarousel(); resetAutoSlide(); } function goToSlide(index) { currentIndex = index; updateCarousel(); resetAutoSlide(); } // Event listeners nextBtn.addEventListener('click', nextSlide); prevBtn.addEventListener('click', prevSlide); // Touch events for mobile let touchStartX = 0; let touchEndX = 0; carousel.addEventListener('touchstart', (e) => { touchStartX = e.changedTouches[0].screenX; }, {passive: true}); carousel.addEventListener('touchend', (e) => { touchEndX = e.changedTouches[0].screenX; handleSwipe(); }, {passive: true}); function handleSwipe() { const threshold = 50; if (touchEndX < touchStartX - threshold) { nextSlide(); } else if (touchEndX > touchStartX + threshold) { prevSlide(); } } // Start the auto-slide startAutoSlide(); // Pause on hover carousel.addEventListener('mouseenter', () => { clearInterval(slideInterval); }); carousel.addEventListener('mouseleave', startAutoSlide); });
Output Preview
Desktop
Mobile
Fullscreen