CSS Scroll Animation

A guide to implementing horizontal scroll animations using CSS keyframes.

Introduction

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.

HTML Structure

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.

CSS Implementation

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.

Scrollable Image Container

Below is a horizontally scrollable, grid-style image layout.

Image 1 Image 2 Image 3

Responsive Table Example

Animation Duration Timing Function
scroll-left 10s linear
scroll-right 8s ease-in-out

Customization Tips

  1. Speed: Modify the animation duration for faster or slower scrolling.
  2. Direction: Use translateX(100%) for right-to-left or reverse values for left-to-right.
  3. Pause on Hover: Add :hover to control animation state.

Pause on Hover (Bonus)


.scroll-text:hover {
  animation-play-state: paused;
}
      

This halts the scroll when the user hovers over the text.