Website animation that does not slow phones: light and accessible
· 6 min read
What to do so your site's animation does not slow down a phone or bother people who asked for less motion. With examples taken from the code of the Vibran effects and from tests I ran on them.
Two different complaints
Animation causes two kinds of problems, and each has its own fix.
The first is performance: the page gets slow, the phone gets warm, the battery drains. The people who feel it are the ones with simple devices, who are also the ones who browse mostly on a phone.
The second is accessibility: for some people, movement on screen causes dizziness, nausea or headaches. Operating systems have a setting for that, and your site has to respect it.
The setting your site has to read
On iPhone it is called Reduce Motion, on Android it is Remove animations, and Windows and macOS have it too, under similar names. The browser passes the choice on to the site through a CSS and JavaScript query called prefers-reduced-motion.
In CSS, you switch the animation off inside a rule:
.background::before { animation: drift 14s ease-in-out infinite alternate; }
@media (prefers-reduced-motion: reduce) {
.background::before { animation: none; }
}
In JavaScript, you ask before you start:
const calm = matchMedia("(prefers-reduced-motion: reduce)").matches;
if (calm) return; // do not start the effect
Reduced motion does not ask for a dead screen. It asks that whatever moves on its own stops or appears without animating. All the content stays there.
What the Vibran effects do
I checked the code of the 110 files in the effects folder. 109 of them handle prefers-reduced-motion: 59 with an @media rule in the CSS the effect injects and 57 with matchMedia in JavaScript, and some use both. The exception is the glow card (cartao-brilho), which does not do the check. Its light only moves when the mouse moves, but it is a point to fix.
In practice, each type of effect behaves differently:
| Effect | With reduced motion |
|---|---|
| Aurora background | The CSS animation is switched off and the patches stand still. |
| Text scramble | The text shows up directly, without going through the symbols. |
| Light strands (fios-luz) | Draws one frame and stops. No animation loop. |
| Marquee (faixa infinita) | The strip stops, becomes a list you can scroll by touch, and the hidden copy goes away. |
| Magnetic button | Does not start. It also does not start for people without a mouse. |
I did not stop at reading the code. I ran three of them in Chrome, once with the normal preference and once with it turned on through the developer tools emulation:
- Aurora: the animation name went from
ef-auroratonone. - Light strands: two screenshots 1.5 seconds apart came out identical with the preference on, and different without it.
- Text scramble: in 25 readings of the text over 2 seconds, two texts showed up without the preference (the final one and a scrambled one) and only the final text with it.
In the effects that check through JavaScript, the question is asked when the file loads. If someone turns the setting on while the page is open, those effects only obey after a reload. The ones that use a CSS rule obey right away.
Performance on a phone
Small files
The effects are plain JavaScript, with no library. The 110 minified files add up to 370 KB together, and you only load the ones you use. Aurora is 1.2 KB, Fios de luz is 5.7 KB, and the biggest of all, the zoom modal, is 6.6 KB.
Animate only what is on screen
59 effects use IntersectionObserver. Of the 49 that use requestAnimationFrame, 40 also watch whether the element is visible. In Fios de luz, the code keeps track of whether the element is on screen, stops asking for frames when it leaves and starts again when it comes back. A background you already scrolled away from does not spend battery.
A ceiling on resolution
Phones often have a pixel density of 3. Drawing on a canvas at that density means 9 pixels for each page pixel. The 29 effects that read devicePixelRatio cap the value with Math.min, at 1.25, 1.5 or 2. With a cap of 1.5, that is 2.25 pixels per page pixel, four times fewer than 9. In 15 of them the default cap is 1.5. Another 15 effects have a data-qualidade option (quality) that lowers the drawing resolution (in the liquid sphere, from 0.3 to 1).
Animate only the cheap properties
The Aurora animation only touches transform, and the blur is fixed. The marquee slides with translateX. These are properties the browser handles on the graphics card, without redoing the layout on every frame.
Less stuff on a phone
Some effects have options to lighten the load. Fios de luz accepts data-fios (strands, 70 per bundle by default, 140 at most) and data-nuvens="nao" (turns the clouds off). One way to use fewer strands on a small screen:
<section data-efeito="fios-luz">...</section>
<script>
document.querySelector('[data-efeito="fios-luz"]').dataset.fios =
matchMedia("(max-width: 700px)").matches ? "24" : "70";
</script>
<script src="efeitos/fios-luz.js"></script>
The small script comes before the effect file so the number is already set when the effect starts. Mouse effects, such as the custom cursor and the magnetic button, only start for people with a mouse pointer. On a phone they do nothing.
How to test on your site
- Reduced motion: in Chrome, developer tools, the “More tools” menu, “Rendering”, and choose
prefers-reduced-motion: reduce. Reload the page and see whether everything that moved has stopped. - A pretend slow phone: turn on device mode (the two-devices icon) and, in the Performance tab, throttle the CPU to 4 times slower. If the page stutters like that, on a simple device it will stutter too.
- Frames per second: the Rendering tab has a frame meter. Scroll the page and watch whether it drops when the effect appears.
- A real phone, preferably the oldest one you have around.
- Lighthouse, in the same tools, for Performance and Accessibility.
- Contrast with a moving background: wait for the whole cycle and see whether the text stays readable.
What is still up to you
- The marquee stops when the mouse passes over it or the keyboard enters it. On a phone there is no hovering, so it only stops for people who turned on reduced motion. If the strip matters to your page, consider a pause button. WCAG 2.2.2 asks for a way to pause, stop or hide any movement that starts on its own and lasts longer than 5 seconds.
- The glow card does not check the preference yet.
- If you ask the AI for an animation of your own, put the rule in the request. The Vibran prompts already end with the sentence “mantenha o respeito a prefers-reduced-motion e não adicione dependências” (keep respecting prefers-reduced-motion and add no dependencies). In a request of your own, something like:
Every animation must respect prefers-reduced-motion: with the setting
on, stay still or appear without animating. Animate only transform and
opacity, pause whatever leaves the screen and cap the canvas resolution.
In short
Ask for, or write, the reduced-motion rule from the start. Prefer small effects that pause off screen and cap their resolution. Test with the emulation and with a real device. To see how an effect gets into a site, read how to add an animated effect with a prompt. To see a whole page that takes these precautions, open the barbershop template with WhatsApp booking.
See the background effects running and adjust the time and the amount before copying.
See the animated backgrounds