Skip to content
https://abc.microfintool.com/

Mobile & Accessories

Smartphone Reviews, Specs, Comparisons & Electronics Guides

  • Welcome to ABC Tool: Your Ultimate Portal for Smartphones and Accessories
  • PRIVACY POLICY
  • Blog
  • Contact
Utils | CSS-native parallax effect

Utils | CSS-native parallax effect

Posted on June 2, 2026October 10, 2026 By Muhammad Safdar No Comments on Utils | CSS-native parallax effect
Blog

Everything you need to know about utils.

[ad_1]

jun 02, 2026

Parallax effects have a long history, and while there are countless ways and libraries to achieve them, a new CSS-native way was recently made possible with CSS Scroll-driven animation timelines.

The usual recipe was a scroll event listener in JavaScript, recalculating positions on every frame and nudging an element up and down.

Scroll-driven animations handle all of that with CSS. Handling parallax animations with CSS has a few advantages: performance should be better as it runs it off the main thread, but my favorite part is the simplicity with which the whole thing becomes a small block of declarative styles, that can be applied with a single utility class. Here is the full code for the class:

.parallax {
	view-timeline-name: --parallax-tl;
	view-timeline-axis: block;
	overflow: hidden;

	& > * {
		scale: calc(1 + var(--parallax-offset, 20) * 2 / 100);
		animation: parallax auto linear both;
		animation-timeline: --parallax-tl;
		animation-range: cover;
		will-change: translate;
	}
}

@keyframes parallax {
	from {
		translate: 0 calc(var(--parallax-offset, 20) * -1%);
	}
	to {
		translate: 0 calc(var(--parallax-offset, 20) * 1%);
	}
}

The timeline

The trick is view-timeline-name. It creates a view progress timeline, a timeline whose progress is measured by how far the .parallax element has travelled through the scrollport. It reads 0% the moment the element starts to enter the viewport and 100% once it has fully left. view-timeline-axis: block tells it to track movement along the block axis, which is the vertical one in a normal writing mode.

On the child, animation-timeline: --parallax-tl swaps the animation’s clock from time to that timeline. From there the rest of the animation line falls into place:

  • auto for duration, because the duration now comes from the timeline rather than a number of seconds
  • linear so scroll progress maps straight onto movement,
  • both to hold the start and end frames outside the active range

⚠️ Note: The animation-timeline longhand property is not part of the animation shorthand and must be declared separately. Furthermore, animation-timeline must be declared after the animation shorthand as the shorthand will reset non-included longhands to their initial value.

The keyframes do the actual work. With the default offset, the child slides from translate: 0 -20% to translate: 0 20% as you scroll past it. Because it moves at a different rate to the container around it, you get that sense of depth.

Scaling to avoid empty spots

The child translates by up to the offset percentage of its own height in each direction, so if the child were exactly the same size as its container, shifting it up or down would expose a strip of empty space.

The child needs to be scaled up in order to have a margin to move into. It needs the offset’s worth of extra height above and below, so twice the offset overall:

scale: calc(1 + var(--parallax-offset, 20) * 2 / 100);

With the default offset of 20, the child is rendered at 140% of its size, the surplus is clipped by overflow: hidden on the container, and there is always enough content to cover the box no matter where in the ±20% travel it sits.

The neat part is that both the translate and the scale read the same --parallax-offset variable. Turn the offset up for a stronger effect and the scale grows to match it, so the cover stays correct on its own. One value to tune, and the gaps never come back:

<div class="parallax" style="--parallax-offset: 30;">
	<img src="…" />
</div>

will-change: translate is the last piece, a hint that this element’s translate is about to change so the browser can promote it to its own layer ahead of time.

Motion preferences

Parallax is movement tied to scrolling, and some people would rather not have it. It’s good practice to respect that by disabling the animation for anyone with prefers-reduced-motion: reduce. In this case, we can just turn off the animation and scale:

@media (prefers-reduced-motion: reduce) {
	.parallax > * {
		animation: none;
		scale: 1;
	}
}

Resources


[ad_2]
Source link

More on utils

Stay tuned for updates on utils as the story develops. Related: Codex SQLite feedback logs can write ~640 TB/year and rapidly consume SSD endurance · Issue #28224 · openai/codex · GitHub.

Frequently Asked Questions

What is the new CSS-native way to do parallax?

CSS scroll-driven animation timelines, instead of a JavaScript scroll event listener recalculating positions on every frame.

What are the advantages of CSS parallax?

Better performance since it runs off the main thread, and simplicity: a small block of declarative styles applied with a single utility class.

How does view-timeline-name work?

It creates a view progress timeline measuring how far the element has traveled through the scrollport: 0% when it starts entering, 100% once it has fully left.

What is the animation-timeline caveat?

The animation-timeline longhand is not part of the animation shorthand and must be declared separately, after the shorthand.

Views: 49

Post navigation

❮ Previous Post: NVIDIA’s RTX Spark looks like a PC chip, but it’s built like a smartphone
Next Post: How to watch Microsoft’s Build 2026 conference ❯

You may also like

Huawei Pura 90 Pro Max unveiled with 200MP 4x telephoto, Pura 90 Pro tags along
Blog
Huawei Pura 90 Pro Max unveiled with 200MP 4x telephoto, Pura 90 Pro tags along
April 21, 2026
Even the cheapest Samsung Galaxy phone is getting One UI 8.5
Blog
Even the cheapest Samsung Galaxy phone is getting One UI 8.5
May 27, 2026
App Store Award finalists announced – Latest News
Blog
App Store Award finalists announced – Latest News
April 25, 2026
Cloudflare vs CrowdStrike: Comparing security approaches
Blog
Cloudflare vs CrowdStrike: Comparing security approaches
April 10, 2026

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • OnePlus 16 Launch Date, Price, Specs: Everything Confirmed for 2026
  • Best 5G Phones 2026 for USA, UK & Europe (Every Budget)
  • Best Foldable Phones 2026: Z Fold 8 vs Pixel 11 Pro Fold vs Razr
  • Google Pixel 10 Review (2026): Still Worth $799?
  • iPhone 16 vs iPhone 17: Should You Upgrade in 2026? (Honest Answer)

Recent Comments

  1. I Hiked Using Robot Legs in the Grand Canyon. I Didn’t Even Need My Cane - Mobile & Accessories on Can Using the Hypershell Exoskeleton on a Bike Replace an E-Bike? I Tested It to Find Out
  2. The media starts receiving the first Trump Mobile T1 Phone units, launch is imminent - Mobile & Accessories on The Competitive Moat That AI Can’t Replicate
  3. Samsung’s giant The Frame Pro TV is $1,500 off until midnight - Mobile & Accessories on All Your Wearables Have One Glaring Weakness. What Can You Do About It?
  4. iPhone 18: Everything We Know About Apple's Most Ambitious Lineup Yet - Mobile & Accessories on This magnetic Qi 2.2 power bank is perfect for the iPhone 17 and it’s on sale right now
  5. Do Camera Sensor Sizes Matter? - Mobile & Accessories on Xiaomi 18 Pro set for a screen upgrade that Samsung fans will be very familiar with

Archives

  • October 2026
  • June 2026
  • May 2026
  • April 2026

Categories

  • Blog
  • Mobiles

Copyright © 2026 Mobile & Accessories.

Theme: Oceanly News by ScriptsTown