Skip to main content

Common Examples

The SrOnly component renders content that is visually hidden but remains accessible to screen readers. This is essential for providing context to assistive technology users without affecting the visual design.
import { SrOnly } from "@servicetitan/anvil2";

function ExampleComponent() {
  return (
    <Text>
      <span aria-hidden="true">★★★★☆</span>
      <SrOnly>4 out of 5 stars</SrOnly>
    </Text>
  );
}

When to Use

Use SrOnly when:
  • Visual formatting conveys meaning (colors, symbols)
  • Abbreviations need expansion

When NOT to Use

Don’t use SrOnly when:
  • The visual text is already descriptive
  • aria-label or aria-labelledby would be more appropriate
  • The content should be visible to all users

React Accessibility

  • Content in SrOnly is read by screen readers but not visible
  • Uses CSS techniques that maintain content in the accessibility tree
  • Preserves all standard span element functionality
For more guidance on semantic page structure, see semantic markup best practices.
Last modified on January 23, 2026