ScrollPremium

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().

CSSRotateScroll

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

The eight-pointed star is born from turning squares — page of a zellige workshop — Nested Rotation on Scroll example 1

① The eight-pointed star is born from turning squares — page of a zellige workshop

When“The craft” page of a Moroccan mosaic workshop: four short paragraphs about the layout on the left; on the right, a figure that stays in view while you read — a glazed tile and two outlined squares.
WhyThe eight-pointed star of zellige is two equal squares, one of them turned by 45°. The figure shows it without a line of script: the tile and its ochre frame, the same size, turn at two speeds, and the star forms and dissolves four times during the read. The wide frame, faster, stands for the path of the interlacing.
SettingsA 116 px square with sharp corners, turquoise glaze; ::before brought to the square's size (inset: 0), solid 3 px ochre stroke; ::after at inset: -17px, solid blue stroke. The figure is pinned by the scene (position: sticky; top: 100px). A 540 × 316 px area, 544 px of travel: the star is complete at 68, 204, 340 and 476 px. Capture: 78 px/s by a timer in the scene.
Log of a nightly backup — the emblem turns for as long as lines come in — Nested Rotation on Scroll example 2

② Log of a nightly backup — the emblem turns for as long as lines come in

WhenConsole of a small family photo server: the log of the night copy scrolls by itself, line after line, under a strip carrying the task's name and a small emblem.
WhyA looping activity indicator proves nothing: it spins just as well when everything is frozen. This one is tied to the scrolling of the log — it advances when lines arrive and stops when they stop. Its three frames at three speeds keep it readable even at 34 px: you see it move without staring at it.
SettingsFigure shrunk to a 14 px square; frames at inset: -5px and -10px, dashed at 75 and 60% opacity, 34 px in all. It sits in a 46 px strip on position: sticky added by the scene, above nineteen log lines. A 380 × 212 px area, 271 px of travel. The arrival of lines is simulated by a timer in the scene (64 px/s, pause at the end of the log).
The three rings of a second-hand lens — mobile listing of a camera dealer — Nested Rotation on Scroll example 3

③ The three rings of a second-hand lens — mobile listing of a camera dealer

WhenListing of a second-hand 50 mm lens viewed on a phone: the front view of the lens stays at the top of the screen, the bench report scrolls beneath, point by point.
WhyOn a lens, what you check first is the rings: do they turn, and smoothly? The listing turns them under the thumb while you read “smooth focus”, “crisp clicks”. The outer ring goes four times faster than the inner one, like an aperture ring next to a long focus throw.
SettingsAll three shapes become circles (border-radius: 50%): the rotation only shows through the strokes. The square turned into a 64 px lens in a radial gradient; ::before in 7 px grey dashes (knurled ring), ::after in 5 px dots. The figure sits in a pinned 158 px strip added by the scene. A 190 × 318 px area, 329 px of travel. Capture: 80 px/s, timer in the scene.

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: reduce the 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-label caption 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.

Chrome 115+✓ Full (measured in Chromium 149)
Edge 115+✓ Not verified (same engine as Chrome)
Safari 26+✓ Full in the WebKit 26.5 test build; real Safari not verified
Firefox 159+✓ Not verified (support announced by MDN)
Firefox up to 158✓ Square and frames aligned, motionless (measured in Firefox 151)
iOS 26+ / Android Chrome 115+✓ Not verified on a device

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):

index.html — structure
<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 / propertyDefaultEffect
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

Rotate on Scroll turns a block and its icon at a single speed: it is the version to take for an object of your own. Rotation on Scroll pins a graduated dial where only the needle turns, to read a position. Here the point is the composition: three rotations carried by one div and its two pseudo-elements, falling out of line and back into it. It is a motif — mechanism, rosette, rings — more than an object or an instrument.
Because it is drawn inside the square and turns with it. Its −360° are taken off the parent's 720°: one turn is left in the square's direction, twice as slow. Seen from the square the frame does move backwards; seen from the page it just moves forward more slowly. For it to really run backwards on screen you have to go beyond −720° — or take the frame out of the square, making it a sibling element with its own animation.
Not with pseudo-elements: a div only has two, and both are taken. Add a real child inside .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°.