How to Build an Infinite Carousel with HTML & CSS
Learn how to build an infinite carousel with this comprehensive guide containing source code.
Table of Contents
Welcome to this tutorial on How to Build an Infinite Carousel with HTML & CSS.
HTML Structure
<div class="marquee-wrapper">
<h2>Our Partners</h2>
<div class="marquee-container">
<div class="marquee-track">
<div class="marquee-item">CSS3</div>
<div class="marquee-item">HTML5</div>
<div class="marquee-item">JavaScript</div>
<div class="marquee-item">React</div>
<div class="marquee-item">Node.js</div>
<div class="marquee-item">Python</div>
<div class="marquee-item">Django</div>
<div class="marquee-item">Figma</div>
<div class="marquee-item">CSS3</div>
<div class="marquee-item">HTML5</div>
<div class="marquee-item">JavaScript</div>
<div class="marquee-item">React</div>
<div class="marquee-item">Node.js</div>
<div class="marquee-item">Python</div>
<div class="marquee-item">Django</div>
<div class="marquee-item">Figma</div>
</div>
</div>
</div>
CSS Styling
.marquee-wrapper {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
min-height: 100vh;
background-color: #0f172a;
color: white;
font-family: 'Inter', sans-serif;
overflow: hidden;
}
.marquee-wrapper h2 {
font-size: 2.5rem;
margin-bottom: 50px;
color: #38bdf8;
}
.marquee-container {
width: 100%;
max-width: 1000px;
overflow: hidden;
padding: 20px 0;
position: relative;
mask-image: linear-gradient(to right, transparent, black 10%, black 90%, transparent);
-webkit-mask-image: linear-gradient(to right, transparent, black 10%, black 90%, transparent);
}
.marquee-track {
display: flex;
width: calc(200px * 16 + 20px * 16);
animation: scroll 20s linear infinite;
}
.marquee-track:hover {
animation-play-state: paused;
}
.marquee-item {
width: 200px;
height: 100px;
flex-shrink: 0;
display: flex;
justify-content: center;
align-items: center;
font-size: 1.5rem;
font-weight: 700;
color: #94a3b8;
background: rgba(255,255,255,0.05);
border: 1px solid rgba(255,255,255,0.1);
border-radius: 10px;
margin: 0 10px;
transition: all 0.3s ease;
cursor: pointer;
}
.marquee-item:hover {
background: #38bdf8;
color: #0f172a;
transform: scale(1.05);
box-shadow: 0 10px 25px rgba(56, 189, 248, 0.4);
}
@keyframes scroll {
0% { transform: translateX(0); }
100% { transform: translateX(calc(-200px * 8 - 20px * 8)); }
}
JavaScript Logic
document.addEventListener('DOMContentLoaded', () => {
// Pure CSS implementation, no JS required for infinite scrolling marquee.
});