Nested Rotation on Scroll
One element, three nested rotations: the square makes 2 turns over the travel, and its two dashed frames — pseudo-elements turning inside it — make 1 and 4 on screen. Three speeds from a single div, and full realignment at every quarter of the scroll. CSS only, on animation-timeline: scroll().
Updated
This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Scroll has 74 effects, including 12 free. Explore the category →
3 usage examples



How it works
It all sits in .sdc-rotate-shape, an empty 120 px div with 20 px corners and a violet → cyan gradient. Its two pseudo-elements draw dashed frames larger than itself: ::before overhangs by 20 px (160 px a side, 2 px violet stroke), ::after by 40 px (200 px, 1 px cyan stroke). The three share animation-timeline: scroll() and two sets of keyframes: fx0561Rotate, up to rotate(720deg), for the square and for ::after; fx0561RotateSlow, up to rotate(-360deg), for ::before. No extra element in the HTML, no script.
A pseudo-element lives in its parent's coordinate system: its rotation adds to the square's. On screen the near frame therefore makes 720 − 360 = 360°, one turn, and the wide frame 720 + 720 = 1,440°, four turns — all in the same direction as the square, despite the minus sign. Read at 100 px of scrolling, in Chromium 149 and WebKit 26.5 alike: square at 138°, ::before at −69° in its own frame of reference (69° on screen), ::after at 138° (277° on screen). That is 0.69°, 1.38° and 2.77° per pixel over the 520 px of travel. A square looks the same every quarter turn: the three are only upright together every 130 px, at 0, 25, 50, 75 and 100% of the scroll.
The square is in the flow, in the middle of an 800 px tray: it crosses the 280 px frame rather than staying in it (visible from 36 to 484 px of scrolling, whole from 189 to 331 px). When the demo opens you only see the caption, placed in the first screen. That original behaviour is kept; what was repaired lies around it. Selectors hang from .fx-0561-root and the animations are renamed — the code shared its area classes with another effect in the catalogue. overflow-x: hidden contains the wide frame, which sweeps 250 px as it turns. The area is focusable, reduced motion is handled, the caption went from 30 to 60% white.
Accessibility
- Reduced motion: three rotation speeds around one centre is the busiest figure of this family of effects. Under
prefers-reduced-motion: reducethe three animations are removed at once (the square and its two pseudo-elements): the figure stays upright, frames aligned, and climbs with the content. - Nothing to read in the figure: the div is empty and the frames only exist in CSS, so a screen reader announces nothing — it is an ornament. Only the
.sdc-rotate-labelcaption is text. If the figure must mean something (an activity in progress, a setting), write it next to it. - Keyboard: Tab brings focus to the area (
tabindex="0",role="region"), a violet outline shows it, and each arrow press moves 40 px in Chromium: 55° for the square, 111° for the wide frame. Recorded in all three engines; WebKit could not reach the area in the original code. - Contrast and touch: the code's dashed frames are barely visible — 1.4:1 for the violet at 30%, 1.35:1 for the cyan at 20% (computed). That is a mood choice; raise opacity to 60–80% if they must be seen turning, as the examples do. The square itself stands at 4.7:1 on its violet side. With a finger the area scrolls natively (150 px swiped, 152 px recorded in touch emulation).
Browser compatibility
No JavaScript. The only recent requirement is animation-timeline: scroll(): Chrome and Edge 115, Safari 26, Firefox 159 per MDN. Pseudo-elements animated on that timeline respond the same way in Chromium 149 and WebKit 26.5 (angles identical to the degree). Firefox 151 displays the figure without turning it. Firefox 159 and Apple's own Safari builds were not tried; neither was smoothness on a phone.
The three animations are declared together under @supports (animation-timeline: scroll()). Without that support the figure sits at 0°: a square centred in its two frames, which is also its state at every quarter of the travel. The motion is lost, not the shape.
The code
HTML structure to paste into your page (the CSS + JS come with your purchase):
<div class="fx-0561-root">
<div class="sdc-scroll-container" tabindex="0" role="region" aria-label="…">
<div class="sdc-rotate-content">
<div class="sdc-rotate-shape"></div>
<span class="sdc-rotate-label">…</span>
</div>
</div>
<span class="sdc-scroll-hint" aria-hidden="true">…</span>
</div>
One-time payment, no subscription — the code is yours forever
Customize
Options passed to the API or data-* attributes:
| Option / property | Default | Effect |
|---|---|---|
Angles (CSS — @keyframes fx0561Rotate and fx0561RotateSlow) |
720° for the square and ::after, −360° for ::before | The frames' angles add to the square's. For a frame that stands still on screen: −720°. For a true reverse spin: beyond that, for instance −1,080° (one turn backwards). |
Frames (CSS — .sdc-rotate-shape::before, ::after: inset, border, border-radius) |
20 and 40 px from the square, 2 and 1 px dashes, violet at 30% and cyan at 20% | inset: 0 lays a frame over the square (an eight-pointed star when they are 45° apart). A solid, more opaque stroke makes the motion far crisper. |
Square (CSS — .sdc-rotate-shape: width, height, border-radius, background) |
120 px, 20 px corners, gradient #8b5cf6 → #06b6d4 | As a circle (50%), square and frames become rings: only the rotation of the dashes shows. The wide frame sweeps about 2.1 times the side of the square. |
Figure position (CSS — .sdc-rotate-content { align-items: center }) |
middle of the tray, in the flow | To pin it: align-items: flex-start on the tray and position: sticky; top: 80px on the square (sticky is enough to anchor the pseudo-elements). |
Travel (CSS — .sdc-rotate-content { height: 800px }) |
520 px of travel, alignment every 130 px | Four sections of equal height put an alignment at the start of each one. With no height and no overflow-y on the area, the page drives the figure. |
Caption and hint (HTML — .sdc-rotate-label, .sdc-scroll-hint) |
“720° over the full height” in the first screen, “Scroll ↓” over the frame | The caption is positioned against the area and leaves with the content after 239 px. Two demo texts to replace. |
FAQ
.sdc-rotate-shape, on position: absolute with a negative inset, and give it the same animation lines in the @supports block. Like the other two it will inherit the square's rotation: work out its on-screen angle by adding 720°.