A guide to implementing horizontal scroll animations using CSS keyframes.
CSS scroll animations are commonly used to create marquee-like effects where content scrolls continuously. These animations are smooth, lightweight, and do not require JavaScript for simple behaviors.
Start by setting up a container for the scrollable content:
<div class="scroll-container">
<div class="scroll-text">
This is a scrolling text animation using CSS.
</div>
</div>
Note: Only the inner content scrolls, while the outer container masks overflow.
Define your container and scroll effect using @keyframes and animation properties.
.scroll-container {
width: 100%;
overflow: hidden;
background: #f9f9f9;
}
.scroll-text {
display: inline-block;
white-space: nowrap;
padding-left: 100%;
animation: scroll-left 10s linear infinite;
}
@keyframes scroll-left {
0% {
transform: translateX(0%);
}
100% {
transform: translateX(-100%);
}
}
This example scrolls the text from right to left infinitely.
Below is a horizontally scrollable, grid-style image layout.
Animation | Duration | Timing Function |
---|---|---|
scroll-left | 10s | linear |
scroll-right | 8s | ease-in-out |
:hover
to control animation state.
.scroll-text:hover {
animation-play-state: paused;
}
This halts the scroll when the user hovers over the text.