> ## Documentation Index
> Fetch the complete documentation index at: https://anvil.servicetitan.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Sr Only - Web

> A utility component for providing content that is visually hidden but accessible to screen readers.

> [!NOTE]
>
> For development, import `SrOnly` from
> `@servicetitan/anvil2`. For design, find it in the
> [Anvil2 file](https://www.figma.com/design/xaNQsvRKczoxu7pj0M6QT8/Anvil2-v3).

> [tab] Implementation
>
> ## Usage Guidelines
>
> Use `SrOnly` when assistive technology needs text that should not appear on screen. `SrOnly` visually hides content while keeping it in the accessibility tree.
>
> | Standard | Requirement |
> | - | - |
> | DoEquivalent text for visual meaning | Provide equivalent text when meaning is only visual, such as icons, symbols, star ratings, and abbreviations. |
> | DoLabel icon-only controls | Label icon-only controls by pairing visible decorative content (`aria-hidden`) with `SrOnly` text. |
> | DoGive `SrOnly` an `id` for descriptions | Give `SrOnly` an `id` when another control references it via `aria-describedby`. |
> | DoKeep the string in the DOM | Prefer `SrOnly` when the hidden string should stay in the DOM as real text, not only an attribute. |
> | Don'tDuplicate visible text | Leave text that is already visible and descriptive out of `SrOnly`. |
> | Don'tHide content everyone needs | Make content that every user needs visible. |
> | Don'tExtra DOM text for a single name | Use `aria-label` or `aria-labelledby` when a single accessible name on the control is enough. |
> | Don'tSubstitute for semantics | Use headings, labels, and landmarks for structure. `SrOnly` does not replace them. |
>
> ### Alternatives
>
> * `aria-label` or `aria-labelledby` for naming a control without extra DOM text.
> * `aria-describedby` pointing at visible helper text when the description can be shown to everyone.
> * Visible [Text](https://anvil.servicetitan.com/docs/components/text/web.md) or [FieldLabel](https://anvil.servicetitan.com/docs/components/field-label/web.md) when sighted users also need the content.
> * The `sr-only` class in [`a2-utils.css`](https://anvil.servicetitan.com/docs/utilities/web/css-utilities) for the same visual-hide behavior without the React component.
>
> ### How to Use
>
> Import `SrOnly` and place the screen-reader text next to the decorative content.
>
> ```tsx theme={null}
> import { SrOnly } from "@servicetitan/anvil2";
>
> <button type="button">
>   <span aria-hidden="true">×</span>
>   <SrOnly>Close dialog</SrOnly>
> </button>
> ```
>
> Content stays in the accessibility tree. `SrOnly` is a `span` and accepts standard `span` props, including `id` for `aria-describedby`.
>
> ## 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.
>
> ```tsx theme={null}
> import { SrOnly } from "@servicetitan/anvil2";
>
> function ExampleComponent() {
>   return (
>     <Text>
>       <span aria-hidden="true">★★★★☆</span>
>       <SrOnly>4 out of 5 stars</SrOnly>
>     </Text>
>   );
> }
> ```
>
> ## 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](https://anvil.servicetitan.com/docs/accessibility/semantic-markup.md).

> [tab] SrOnly Props
>
> ```tsx theme={null}
> <SrOnly>
>   Screen reader only content
> </SrOnly>
> ```
>
> ## `SrOnly` Props
>
> The `SrOnly` component accepts all standard HTML `span` element props. The content is visually hidden using CSS but remains accessible to screen readers.
>
> **children** `ReactNode`
>
> The content to be read by screen readers. This can be text, elements, or any valid React children.
>
> **className** `string`
>
> Additional CSS classes to apply to the element.
>
> **id** `string`
>
> Unique identifier, useful when referenced by `aria-describedby` or `aria-labelledby`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.