Overview
Anchors are text links that allow users to navigate to different pages or locations. They can be used inline with text or as standalone navigation elements. The Anchor component automatically handles security for external links and provides visual indicators when configured to do so.Installation
Usage
External Links
The Anchor component automatically detects external links (those starting withhttp: or https:) and applies appropriate security attributes (rel="noreferrer noopener" and target="_blank").
Show External Icon
You can display an external link icon to indicate that the link opens in a new window.Custom External Link Label
Customize the accessible label for the external link icon.Inverse Variant
Use the inverse variant for dark backgrounds.With Spacing
The Anchor component supports layout and spacing props from the Box component.Internal Links
Anchor Links (Page Sections)
Props
The text or content to display in the link.
The URL to navigate to when the anchor is clicked.
The visual style variant. Use ‘inverse’ for dark backgrounds.
Whether to display the external link icon. Useful for indicating links that open in a new window.
Accessible title for the external link icon. Used as the icon title attribute.
Relationship attribute. For external links, defaults to ‘noreferrer noopener’ but can be overridden.
Where to open the linked document. For external links, defaults to ‘_blank’ but can be overridden.
The tab order of the anchor element.
Overrides the default element name to apply unique styles with the Customization Provider.
Layout Props
The Anchor component also accepts layout and spacing props:display- CSS display propertyheight,minHeight,maxHeight- Height propertieswidth,minWidth,maxWidth- Width propertiesmargin,marginTop,marginRight,marginBottom,marginLeft,marginX,marginY- Margin propertiespadding,paddingTop,paddingRight,paddingBottom,paddingLeft,paddingX,paddingY- Padding propertiesverticalAlign- Vertical alignment
Utility Functions
The package also exports utility functions for working with external links:isExternalUrl
Determines if a URL is external.secureExternalLink
Returns security attributes for external links.Accessibility
- Anchors are semantic
<a>elements with proper href attributes. - External links automatically receive
rel="noreferrer noopener"andtarget="_blank"for security. - When
showExternalis true, the icon includes a descriptive title attribute for screen readers. - Focus states are clearly visible with appropriate styling.
- Color contrast meets WCAG AA standards in both default and inverse variants.
Best Practices
Do
- Use anchors for navigation between pages or to external resources
- Use descriptive link text that makes sense out of context
- Use
showExternalfor external links to set user expectations - Use the inverse variant on dark backgrounds for proper contrast
- Keep link text concise but meaningful
Don’t
- Don’t use “click here” or “read more” without context
- Don’t use anchors for actions (use Button instead)
- Don’t open links in new windows without indication (use
showExternal) - Don’t remove the underline styling (it’s important for accessibility)
- Don’t make non-interactive text look like a link