Skip to the main content
{}
Back to all articles

Technical article

Use web animation without harming performance or accessibility

Use motion to clarify hierarchy, status and transitions, with transform and opacity, reduced motion and progressive enhancement.

By Codegenie2 minute read
  • UX & accessibility
  • Use
  • animation
  • harming
  • performance
  • accessibility
Website and devices beside a dashboard with performance charts.
In this article

Use motion when it clarifies status or a transition. Primary content and actions must remain visible without an animation script. Respect reduced-motion preferences and inspect actual rendering; transform and opacity do not automatically guarantee smooth behaviour.

Start with a useful static state

An illustrative status card can briefly change colour after an action. The text “Saved” remains the actual confirmation. A large movement around an enquiry button can instead obstruct the next action. Never make motion the sole carrier of information.

Visible without JavaScript

Keep content visible and add optional motionresources/css/app.csscss
.reveal {
    opacity: 1;
    transform: none;
}

@media (prefers-reduced-motion: no-preference) {
    .reveal.is-visible {
        animation: reveal-accent 180ms ease-out;
    }
}

@keyframes reveal-accent {
    from { transform: translateY(6px); }
    to { transform: none; }
}
Use IntersectionObserver instead of a scroll handlerresources/js/features/reveal-motion.jsjavascript
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)');

if (!reduceMotion.matches && 'IntersectionObserver' in window) {
    const observer = new IntersectionObserver((entries) => {
        for (const entry of entries) {
            if (!entry.isIntersecting) continue;
            entry.target.classList.add('is-visible');
            observer.unobserve(entry.target);
        }
    });

    document.querySelectorAll('.reveal').forEach((element) => {
        observer.observe(element);
    });
}

The CSS keeps content visible by default. Only when IntersectionObserver reaches an element does its optional animation begin. The script exits for reduced motion or missing support, leaving the same content available. Use it for non-essential accents, not for hiding focusable elements.

Check the cost of motion

Prefer animating transform and opacity over properties that repeatedly require layout. Large layers, filters and many simultaneous effects can still be expensive. Inspect rendering and interaction on the same device before and after changes. Choosing a property does not establish measured speed gains.

Reduced motion must not hide information

WCAG 2.3.3 covers disabling non-essential interaction animation at level AAA. Automatically moving content has separate requirements, such as pausing where applicable. Review repeating banners and carousels too; a media query alone does not satisfy every criterion.

Illustrative comparison across states

  • JavaScript disabled: text and actions are immediately visible.
  • Normal motion: the accent does not move surrounding layout or block operation.
  • Reduced motion: the same information appears without movement.
  • Keyboard use: focus stays visible during transitions.

Omit an animation when the static version already explains the task better. Also check changes to the system preference during use.

This CSS/JavaScript example is illustrative. Check the three described states and focus with your actual content and browsers.

Last updated:

Need technical context for your own project?

Codegenie helps with Laravel applications, existing codebases, shared-hosting deployments and technical improvements.