I Moved My Portfolio's Scroll Effects from JavaScript to CSS

Framer Motion sat in my root layout, so every page paid for it, including pages with nothing to animate. Moving four scroll effects to CSS let it leave the layout, and I measured what that did.

A scroll thumb on a thin vertical track, a hairline leading to a stack of three cards that go from solid indigo to translucent to a dashed outline, and a small dashed outline of a cube on the far right

Update, November 6, 2026: three things changed after I published this. I removed Lenis, so the site now scrolls natively. The chat widget no longer loads on every page; it mounts only on the SageDesk case study, as a live demo. And Firefox 159 turned scroll-driven animations on by default on October 27, before I published, so the browser note near the end was wrong when I wrote it. It is corrected below. I also re-ran the script-weight measurement on the current build: home is about 191 KB gzipped, About about 170 KB and Privacy about 169 KB. The Lighthouse figures are from the earlier build and I have not re-run them.

I set out to make my portfolio's JavaScript smaller, and my first assumption was wrong. I expected the weight to be in the pages, in the heavy sections with their animations. It was in the layout.

To find out, I measured the gzipped size of every script each page loads. The home page came to 249 KB. The privacy page, which has almost no content and nothing interactive, came to 234 KB. A page with nothing on it was carrying nearly the whole bill.

Where the Weight Was

Framer Motion sat in the root layout, which means it shipped on every page of the site. Nothing a visitor did could avoid it. Everything the privacy page loaded came from the shared layout and the framework:

  • the React and Next runtime, about 143 KB gzipped on its own
  • Framer Motion, pulled in by the root layout, by the page-transition wrapper and by the navigation bar, about 43 KB on top of that
  • Lenis for smooth scrolling, and Vercel Analytics
  • the chat widget (SageDesk), mounted as soon as the page loaded, which I wrote about separately in the post on its 44 MB download

I could not shrink the first item. The others were choices, and the biggest was Framer Motion in three places that run on every route. The navigation bar used it for a reading-progress bar and for the mobile menu. The wrapper that fades between pages used it. A provider in the layout configured it for reduced motion. None of the pages that never animated anything could avoid paying for it.

What I Did for Performance

Here is the whole change in the order I made it, so you can judge each step on its own:

  1. Measured an empty page first. That is what pointed at the layout instead of the sections.
  2. Took Framer Motion out of the root layout, the page-transition wrapper and the navigation bar. This is the change that mattered most, because those three load on every route.
  3. Replaced the four scroll effects with CSS. This is what made step 2 possible, because the reading-progress bar was the nav's reason to need a JavaScript animation library.
  4. Kept Framer Motion only where motion is state. It loads through LazyMotion with the lightweight m component, and the feature set arrives as a separate chunk after the page is interactive.
  5. Moved the mobile menu behind a lazy import, so only a phone that opens it downloads its animation code.
  6. Mounted the chat widget on idle, so it no longer competes with the content the visitor came for. It has since moved off the other pages and now loads only on the SageDesk case study.
  7. Let the sections that only held a reveal go back to being server components, which removes their code from the client bundle.

What the Animations Actually Did

I listed the motion on the site and asked what each piece needed from JavaScript:

  • Sections fading up as they scroll into view. Nothing but the scroll position.
  • A progress bar under the navigation. Nothing but the scroll position.
  • The wall of project covers behind the hero on the home page drifting as you scroll. Nothing but the scroll position.
  • A fade between pages. Nothing but a class name that is set on client navigations.

Four effects, and not one of them needed state. They were scroll position mapped to a visual change, which is what CSS scroll-driven animations do without a listener.

Scroll Timelines in Practice

A scroll-driven animation is an ordinary CSS animation whose clock is a scroll position instead of time. Here is the reveal used for every section on the site:

app/globals.csscss
@keyframes reveal-in {
  from {
    opacity: 0;
    translate: 0 14px;
  }
  to {
    opacity: 1;
    translate: 0 0;
  }
}

@utility reveal {
  @media screen and (prefers-reduced-motion: no-preference) {
    @supports (animation-timeline: view()) {
      animation: reveal-in linear both;
      animation-timeline: view();
      animation-range: entry calc(var(--reveal-i, 0) * 40px) entry
        calc(240px + var(--reveal-i, 0) * 40px);
    }
  }
}

view() ties progress to how far the element has travelled into the viewport. The range says the animation plays over the first 240 pixels of that entrance, and a per-sibling offset staggers neighbours without a single timer. The reading-progress bar uses scroll(root) instead, which maps the whole page's scroll from top to bottom onto a scaleX from 0 to 1.

Three guards wrap all of it, and I would keep them on anything you copy:

  • @supports means a browser without the feature skips the animation block entirely and shows the content.
  • prefers-reduced-motion: no-preference means anyone who asked for less motion gets none.
  • screen means printing never catches an element half-hidden mid-animation.

The page fade is the simplest of the four. It is a plain CSS animation on a wrapper, switched on by a class after the first client navigation, so the first load never starts from opacity zero.

A Behaviour Change You Should Know About

My old reveals were one-shot: Framer Motion's whileInView with once: true played each entrance a single time. A scroll timeline does not know about "once". It is scrubbed, so the animation follows the scroll position in both directions, and an element that you scroll back past replays its entrance in reverse. In practice that happens at the bottom edge of the screen, where the element is only just arriving, so it reads as natural rather than as a glitch. It is still a different behaviour, and if you want strictly one-shot reveals, a scroll timeline is the wrong tool.

Details That Bit or Nearly Did

Animate translate, not transform. An animation with both as its fill mode keeps applying its last frame forever, and that frame wins over normal declarations. If the reveal set transform: none, it would silently cancel any transform hover lift on the same element. The individual translate property leaves transform alone, so a card can reveal on scroll and still lift on hover.

The timeline follows the nearest scrolling ancestor. For a row of cards inside a sideways scrolling strip, that ancestor is the strip, not the page. So on the strip I put the reveal on the scroller itself rather than on each card.

A full-page screenshot looks broken. I took one of a new page and half of it was empty. Nothing was wrong. A full-page capture never scrolls, so elements below the first screen never enter the viewport and their entrance never plays. Scrolling the page for real showed every section. It is worth knowing before you file a bug against yourself.

Server-rendered animation used to wait for JavaScript. My old reveals started at opacity zero in the server HTML and only began after the page hydrated. A CSS animation starts when the browser paints, so nothing above the fold waits on a bundle any more.

What Framer Motion Is Still For

I did not remove it. Some motion is state, and state is what it is good at: the testimonial deck, the folder cards that open on hover or tap, the contact card's fallback panel, and the filter on the projects page, where cards animate to new positions.

What changed is how it loads:

  • m instead of motion. Components use the lightweight m element inside a LazyMotion wrapper, and the animation features arrive as a separate chunk after the page is interactive. In strict mode, a stray motion import is an error rather than a silent extra download.
  • The layout is clean. Nothing that ships on every route imports Framer Motion now.
  • The mobile menu loads it on first open. Only a phone opens that menu, and it takes the animation code with it.
  • One feature set missing. The lazy set has no pan gesture, so the testimonial swipe became a few lines of pointer events.

Server Components Fall Out for Free

I had not planned this part. The reveal was the only reason most sections were client components. With it gone, the problem, selected work, process and FAQ sections all became server components, and a section only holds state in a small separate piece: one open-and-close item for the FAQ, one pointer hint for the folders, one count-up for the stats. I have since cut the problem and process sections from the site, and the FAQ now lives on the contact page, but the pattern held.

The Numbers

On November 3, I built the last commit and the current code side by side and measured both. Everything below is a production build served locally, and it describes the site as it was that day.

Script weight in the page HTML. This is the gzipped size of every script a page references, at maximum compression, leaving out the legacy polyfill file that modern browsers never download. (My first pass counted that file, about 39 KB, and overstated both sides by the same amount. The savings were right; the totals and the percentages were not.)

  • Home: 249 KB before, 197 KB after, a drop of 52 KB or 21 percent.
  • About: 244 KB before, 176 KB after, a drop of 69 KB or 28 percent.
  • Privacy: 234 KB before, 175 KB after, a drop of 60 KB or 25 percent.

Where the drop on the privacy page came from. Of the 60 KB, about 43 KB is the Framer Motion chunk that no longer loads on the route at all. Most of the remaining 16 KB is Next.js helper code for images and URLs that was bundled alongside client components in the layout and the sections. That attribution comes from the chunk contents, not from switching each change on and off, so treat the second figure as approximate. The honest summary is that taking Framer Motion out of the layout was most of the win, and moving the effects to CSS is what allowed it.

Everything the page loads, including what arrives later. Lighthouse counted transferred script bytes through the full run, which includes the chat widget and the lazy animation chunks:

  • Home: 309 KB before, 294 KB after, only 5 percent less.
  • Privacy: 326 KB before, 279 KB after, 14 percent less.

The home page saves far less here because its animation features and chat widget still download, just later. What the change bought is a smaller first load and less work competing with the content, not a smaller total on pages that animate.

Lighthouse, mobile preset, median of five runs.

  • Total blocking time: already low and not meaningfully different. Home measured 28 ms before and 17 ms after, privacy 12 ms before and 14 ms after.
  • Performance score: home 88 before and 89 after, privacy 91 before and 96 after.
  • Largest Contentful Paint: inconclusive. The old build sat at 3.9 s on home. The new build measured 1.2 s in one batch and 3.7 s in another, with nothing else changed, so I am not claiming a gain. Lab LCP here is sensitive to how the run lands, and I would want field data before saying anything about it.

I have no interaction latency numbers, because Lighthouse cannot measure them in the lab.

I had hoped for a lot more, and I did not get it. React and Next are about 143 KB gzipped, and most of what remained was that, plus Lenis, analytics and icons. Lenis has since gone too, which is where the lower figures in the update at the top come from. I want to be straight about what this change is. It is a tidy gain in first-load weight and a simpler architecture. It is not a trick that gets a framework site to 100 KB, and I cannot show it moved the user-facing timings.

Check what your audience can run before you copy this. Scroll-driven animations ship in Chrome and Edge from version 115, in Safari from version 26, and in Firefox from version 159, released on October 27, 2026. A visitor on an older version sees no animation at all. That is the behaviour I wanted, because the content simply appears, but it is a different experience, and you should decide whether it is acceptable for your site.

What I Would Do First Next Time

Measure the page with nothing on it. If an empty page loads most of your JavaScript, the fix is in the layout, and no amount of work on the heavy sections will find it. Then take each animation and ask what it needs from JavaScript. If the answer is nothing but the scroll position, a few lines of CSS can do the job, and the component can go back to the server. Finally, measure again with more than one metric, and report the ones that did not move.

Ship it without building a team first.

Tell me what you’re building. I reply within 24 hours.