Skip to main content
Brand and assets
BuildMonitor and contribute
/
Brand and assets
  • Foundations
    • The brand
    • Logo
    • Colors
    • Typography
    • Styles
    • Shadows & radii
    • Spacing & grid
    • Gradients
    • Styling & the sx prop
    • Color tokens
    • More
    • Accessibility
      • Accessible names
      • Headings
      • Images
      • Accessible colors
      • Anchors
      • HTML semantics
      • DOM order
      • Accessible alternatives
      • Debug with the accessibility tree
      • Engineer setup
  • Assets
  • AI references
  • Foundations
  • Accessibility
  • Anchors

Anchors

Anchor tags (<a> elements) are essential for web navigation, enabling users to jump between resources easily. To ensure their accessibility, here are some considerations:

  • Descriptive Link Text: Clearly describe the link's destination. By default, the textual content will be used as the accessible name. Focusable Elements: Ensure anchor tags are focusable for keyboard users
  • SPA Focus Management: In single-page applications (SPAs), be sure the focus is set to the top of the page when browsing a new page, and give each page its own title so PageTitleAnnouncer announces the change. ARIA Roles and Attributes: Use ARIA roles and attributes sparingly, only when necessary. By default, anchors used with href will have role="link". For actions like opening modals, use role="button" when the anchor doesn't navigate to another page.

Links with Murray​

We implemented the above requirements in the A component. You can’t provide href and onPress attributes at the same time to infer the aria role properly. Keyboard interactions are managed according to the inferred aria-role

You navigate to a new page:

<A asChild>
<!-- The anchor role is set as a link -->
<Link to="/">Go to an internal Alan page</Link>
</A>
<A href="http://mywebsite.com/my_page.html">
Go to a regular page, browser will fully reload the page.
</A>

You open a modal:

<A
onPress={() => {
// open the modal here
// the anchor role is set as a button
}}
>
Open a modal
</A>

You want to track a link usage:

<A
onPress={() => {
// the anchor role is set as a button
trackEvent({...})
// navigate to the next page
// using window.open()
// or window.location.href = "..."
// or history.push('...')
}}
>
Tracked link
</A>

Rule of thumb: In case of doubt, It is always better to announce a link as a button. If you perform a navigation, assistive technologies will announce the new page anyway, so the user will not be lost. It is especially true in SPA when navigation does not lead to “real” pages.

Documentation: A

Edit this page
Previous
Accessible colors
Next
HTML semantics
  • Links with Murray