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.

rulesscreen-reader-sr-only.md

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

Screen Reader Only Text (sr-only)

Use the sr-only class to provide text for screen readers that is visually hidden.

Why

  • Icon-only buttons need text labels for screen readers
  • Visual context (like icons, colors) needs text alternatives
  • Some content is clear visually but needs explanation for screen readers

The sr-only Class

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

Common Use Cases

Icon-Only Buttons

// Bad - no accessible name
<Button variant="icon" onPress={onClose}>
  <XMarkIcon />
</Button>

// Good - sr-only provides the name
<Button variant="icon" onPress={onClose}>
  <XMarkIcon aria-hidden="true" />
  <span className="sr-only">{t("Close")}</span>
</Button>

// Also good - aria-label
<Button variant="icon" onPress={onClose} aria-label={t("Close")}>
  <XMarkIcon aria-hidden="true" />
</Button>

Visual-Only Table Headers

<table>
  <thead className="sr-only">
    <tr>
      <th>{t("Item name")}</th>
      <th>{t("Amount")}</th>
      <th>{t("Date")}</th>
    </tr>
  </thead>
  <tbody>{/* Visual rows with no visible headers */}</tbody>
</table>

Section Headings for Screen Reader Navigation

import { Region, Heading } from "~/components/heading";

<Region>
  <Heading className="sr-only">{t("Search results")}</Heading>
  <SearchResultsList />
</Region>;

Currency/Unit Indicators

<span className="sr-only" id="currency">{t("Currency USD")}</span>
<input type="number" aria-describedby="currency" />

Contextual Information

// Badge that's visually clear but needs context
<Badge variant="success">
  <CheckIcon aria-hidden="true" />
  <span className="sr-only">{t("Status:")}</span>
  {t("Approved")}
</Badge>

When NOT to Use sr-only

Don't Hide Important Content

// Bad - hiding content that should be visible
<Button>
  <span className="sr-only">{t("Submit form")}</span>
</Button>

// Good - visible text
<Button>{t("Submit")}</Button>

Don't Duplicate Visible Text

// Bad - redundant
<Button>
  {t("Submit")}
  <span className="sr-only">{t("Submit")}</span>
</Button>

// Good - just the visible text
<Button>{t("Submit")}</Button>

Rules

  1. Use sr-only for text that provides context missing from visual presentation
  2. Always add aria-hidden="true" to decorative icons
  3. Every interactive element must have an accessible name (visible text, sr-only, or aria-label)
  4. Don't use sr-only to hide content that should be visible to all users
  5. Don't duplicate visible text with sr-only text

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