Interview Prep
Interview questions, roadmaps and practice sets
Tutorials
Free tutorials on 30+ topics
Blog
Career guides, skills and interview tips
Free PDFs
Notes, cheat sheets and question banks
Certificates
Free skill tests and course certificates
Tools & Whiteboard
Free tools you can use right in the browser
Practice Tests
Mock tests, MCQs and quick Q&A
Free LMS
Learn on the Uncodemy LMS
Choose the best training program according to your career.
Improve the performance of your business with our innovative Industrial Training Program.
Read More →
Our instructor-led training classes are designed to make you an expert.
Read More →
Real-life case studies are a great way to demonstrate your practical knowledge.
Read More →
Explore blogs, latest technologies and industry updates with practical examples.
Read More →Browse all available training programs and choose the right one for your career.
Read More →Know more about who we are and what we stand for.
Discover our mission to equip individuals with essential IT skills and industry expertise.
Read More →
Free tutorials, interview questions, tools and calculators to help you learn.
Explore →Learn, practice and plan your career — bilkul free.
Book a free video counselling session and pick the right course for you.
Read More →A parallax background moves more slowly than the content in front of it as the user scrolls, which adds a sense of depth. You can build it with one line of CSS, with a pure-CSS 3D trick, with a few lines of JavaScript, or with the newer CSS scroll-driven animations.
This tutorial shows all four with working code, explains where each one fails (iPhones, performance, accessibility) and how to pick one.

All examples use a simple page with a parallax "hero" section followed by normal content:
<section class="parallax">
<div class="parallax-bg"></div>
<h2>Learn to build for the web</h2>
</section>
<section class="content">...normal text...</section>
The quickest version. The background image stays fixed to the viewport while the section scrolls over it.
.parallax {
min-height: 70vh;
display: grid;
place-items: center;
background-image: url("/img/mountains.webp");
background-size: cover;
background-position: center;
background-attachment: fixed;
}
Limits: this is a "fixed" effect rather than true slow-motion parallax, and iOS Safari does not support background-attachment: fixed in the usual way, so on iPhones the image simply scrolls normally. It can also cause repaint jank on long pages. Use it when a simple fallback on mobile is acceptable. (With this method you do not need the .parallax-bg div.)
This method makes a scrolling container with perspective and pushes the background layer "back" in 3D space, so it moves more slowly.
.page {
height: 100vh;
overflow-x: hidden;
overflow-y: auto;
perspective: 1px;
}
.parallax {
position: relative;
min-height: 70vh;
display: grid;
place-items: center;
transform-style: preserve-3d;
}
.parallax-bg {
position: absolute;
inset: 0;
background: url("/img/mountains.webp") center / cover;
transform: translateZ(-1px) scale(2);
z-index: -1;
}
Wrap your sections in <div class="page">. With perspective: 1px, a layer at translateZ(-1px) appears half its size and moves at half speed. The scale(2) brings it back to full size, using the formula scale = 1 + (−translateZ ÷ perspective). Move it to translateZ(-2px) scale(3) for a slower layer.
Limits: the page now scrolls inside .page instead of the window, which can affect sticky headers, scroll-position scripts and some browser features. Test it with your layout.
JavaScript gives full control and works on iPhones. The key to smooth performance is to change only transform and to update at most once per frame.
.parallax { position: relative; overflow: hidden; min-height: 70vh;
display: grid; place-items: center; }
.parallax-bg { position: absolute; left: 0; right: 0; top: -30%; bottom: -30%;
background: url("/img/mountains.webp") center / cover;
will-change: transform; z-index: -1; }
const layers = document.querySelectorAll(".parallax-bg");
const speed = 0.2; // 0 = no effect, higher = stronger
let ticking = false;
function update() {
layers.forEach(layer => {
const top = layer.parentElement.getBoundingClientRect().top;
layer.style.transform = `translate3d(0, ${-top * speed}px, 0)`;
});
ticking = false;
}
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
if (!reduceMotion) {
window.addEventListener("scroll", () => {
if (!ticking) {
requestAnimationFrame(update);
ticking = true;
}
}, { passive: true });
update();
}
How it works: as the section scrolls up, its top value goes from positive to negative. The background is moved by a fraction of that distance in the opposite direction, so it appears to move more slowly than the section. The layer extends 30% above and below the section so its edges never show; if you raise speed, increase that overhang. The requestAnimationFrame flag ensures the work happens at most once per screen refresh, and { passive: true } tells the browser the listener will not block scrolling.
Newer CSS can link an animation directly to scroll position without JavaScript:
@keyframes drift {
from { transform: translateY(-15%); }
to { transform: translateY(15%); }
}
@supports (animation-timeline: view()) {
.parallax-bg {
animation: drift linear both;
animation-timeline: view();
}
}
The view() timeline runs the animation as the section passes through the viewport. It runs off the main thread in supporting browsers, so it is very smooth. Support arrived first in Chromium-based browsers and is still spreading, so the @supports rule keeps other browsers on a static background. Check current support on MDN or caniuse.com before relying on it.
@media (prefers-reduced-motion: reduce) {
.parallax-bg { transform: none !important; animation: none !important; }
.parallax { background-attachment: scroll; }
}| Method | Effort | Works on iOS | Best for |
|---|---|---|---|
| background-attachment: fixed | One line | No (falls back to normal scroll) | Quick desktop effect |
| CSS 3D perspective | Medium | Yes | CSS-only sites that can scroll in a container |
| JavaScript | Medium | Yes | Full control, multiple layers |
| Scroll-driven animations | Low | Where supported | Modern browsers, with a static fallback |
To build the rest of the page, see responsive web design with HTML and CSS and CSS media queries. Pair the effect with CSS blur and filter effects, use transitions as in a CSS-only toggle switch, and put it all together in a portfolio website.