CSS Parallax Scrolling
An image that moves slower than the page inside its frame as it scrolls past, using a view() scroll timeline.
<div class="parallax-frame">
<img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 40'%3E%3Crect width='60' height='40' fill='%23bae6fd'/%3E%3Ccircle cx='14' cy='11' r='6' fill='%23fde047'/%3E%3Cpath d='M0 40V30l15-6 15 5 15-7 15 6v12z' fill='%2334d399'/%3E%3Cpath d='M36 31l5-15 5 15zM45 32l4-11 4 11zM8 36l4-12 4 12z' fill='%23047857'/%3E%3C/svg%3E" alt="Green hills and pine trees on a sunny day" width="280" height="220">
</div>
.parallax-frame {
width: 100%;
max-width: 280px;
height: 160px;
margin: 0 auto;
overflow: hidden;
border-radius: 16px;
}
.parallax-frame img {
display: block;
width: 100%;
height: 140%;
object-fit: cover;
}
@supports (animation-timeline: view()) {
.parallax-frame img {
animation: parallax-frame-shift linear both;
animation-timeline: view();
}
}
@keyframes parallax-frame-shift {
from {
transform: translateY(-28%);
}
to {
transform: translateY(0);
}
}
@media (prefers-reduced-motion: reduce) {
.parallax-frame img {
height: 100%;
animation: none;
}
}
About this CSS Parallax Scrolling
This CSS Parallax Scrolling is 39 lines of pure CSS (0.6 KB) with no JavaScript and no dependencies. It uses scroll-driven animations, keyframe animations, transforms and reduced-motion support. It relies on scroll-driven animations, which not every browser supports yet, so check the browser notes below. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.
CSS features used
- scroll-driven animationsChrome and Edge 115+ and Safari 26+. Firefox support is very recent; browsers without it skip the animation and show the content as is.
- keyframe animations
- transforms
- reduced-motion support
How to use this parallax scrolling
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.parallax-frameclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).
Building with an AI tool?
“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.