All skills
sergiodxa avatar

/frontend-accessibility-best-practices

@4d1d816

Accessibility (a11y) best practices for React components. Use when creating UI components, forms, interactive elements, or reviewing code for accessibility compliance.

Use this Skill: https://skilld.dev/gh/sergiodxa/agent-skills/frontend-accessibility-best-practices

This session only. Nothing lands on disk.

rulesreduced-motion.md

≈789 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Respect Reduced Motion Preference

Honor the user's prefers-reduced-motion setting to avoid triggering vestibular disorders.

Why

  • Some users experience motion sickness, dizziness, or seizures from animations
  • Users explicitly request reduced motion in system preferences
  • Respecting this preference is a WCAG 2.1 requirement (2.3.3)

CSS Approach

Use the motion-reduce Tailwind variant:

// Animation only plays if user hasn't requested reduced motion
<div className="animate-bounce motion-reduce:animate-none">
  Bouncing content
</div>

// Reduce transition duration
<div className="transition-all duration-300 motion-reduce:duration-0">
  Transitioning content
</div>

Or use CSS media query directly:

@media (prefers-reduced-motion: reduce) {
  .animated-element {
    animation: none;
    transition: none;
  }
}

JavaScript Approach

Use the usePrefersReducedMotion hook:

import { usePrefersReducedMotion } from "~/hooks/use-prefers-reduced-motion";

function AnimatedCounter({ value }) {
  let prefersReducedMotion = usePrefersReducedMotion();

  if (prefersReducedMotion) {
    // Show static value immediately
    return <span>{value}</span>;
  }

  // Show animated count-up
  return <CountUp target={value} duration={1000} />;
}

Hook Usage

import { usePrefersReducedMotion } from "~/hooks/use-prefers-reduced-motion";

function CarouselControls() {
  let prefersReducedMotion = usePrefersReducedMotion();

  // Disable auto-play for reduced motion users
  let [isAutoPlaying, setIsAutoPlaying] = useState(!prefersReducedMotion);

  return (
    <Carousel autoPlay={isAutoPlaying && !prefersReducedMotion}>
      {/* slides */}
    </Carousel>
  );
}

What to Reduce

Should Respect Reduced Motion

  • Decorative animations (floating elements, parallax)
  • Auto-playing carousels and slideshows
  • Animated backgrounds
  • Page transition animations
  • Count-up number animations
  • Infinite scrolling marquees

Can Keep (Essential Motion)

  • Loading spinners (but keep them simple)
  • Progress indicators
  • Button hover states (if subtle)
  • Form validation feedback
  • Focus ring transitions (keep very short)

Bad

// Bad - no reduced motion consideration
function Banner() {
  return (
    <div className="animate-pulse">
      <FloatingParticles />
      <ParallaxBackground />
    </div>
  );
}

Good

function Banner() {
  let prefersReducedMotion = usePrefersReducedMotion();

  return (
    <div className="motion-reduce:animate-none animate-pulse">
      {!prefersReducedMotion && <FloatingParticles />}
      <StaticBackground />
    </div>
  );
}

Rules

  1. Use motion-reduce: Tailwind variant for CSS animations
  2. Use usePrefersReducedMotion hook for JS-controlled animations
  3. Disable auto-playing content for reduced motion users
  4. Keep essential motion (loading indicators) but simplify them
  5. Never use animations that flash or strobe rapidly
  6. Provide static alternatives for decorative animations

Source: SKILL.md on GitHub

1 warning16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    This skill provides a comprehensive set of accessibility (a11y) guidelines and code examples for building inclusive React applications. It covers semantic HTML, screen reader support, keyboard navigation, and user preferences without including any executable scripts or network-connected components. No security risks or malicious patterns were detected.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer7mo

    5/8 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 4d1d816. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Dormantupdated 8 months ago

README badge

README badge for sergiodxa/agent-skills/frontend-accessibility-best-practices