Skip to contentSkip to navigationSkip to topbar
Paste assistant Assistant
Figma
Star

Anchor

Version 12.1.1GithubStorybook

An Anchor is text that navigates the user from one webpage to another.

Component preview theme
<Anchor href="/components">
Go to Paste components
</Anchor>

Guidelines

Guidelines page anchor

About anchors

About anchors page anchor

An Anchor is text that navigates the user from one webpage to another.

Example use cases may include:

  • Linking to another page within an app or website
  • Linking to an external domain outside of the current app or website

Anchor vs. Button

Anchor vs. Button page anchor

Anchors should be used in place of a button if you only need to create a hyperlink to some other page or content. Anchors should not be used for submitting a form, closing a modal, moving to the next step in a flow, or any other click action that a button should handle. Buttons perform an action, like submitting a form; Anchors take you somewhere, like to the documentation page.

If you need a click handler, you can use our Button component.

The Anchor is built with standard accessible practices in mind. Those include an href attribute, link context, and opening and closing tags.

The title attribute was not included because it’s not exposed to all browsers in an accessible way, meaning most screen readers and touch-only devices will likely never see that information.

All anchor text should be written succinctly and make sense on its own (e.g., don't write "Click here"). This is especially important for users of assistive technology who often navigate through a list of all actions on a page, meaning they might not know about any contextual information surrounding a given action.

The default anchor is a basic text hyperlink. There are no other anchor variants at this time.

Component preview theme
<Anchor href="/components">
Go to Paste components
</Anchor>

If an external URL is used for the href, the target and rel will automatically be updated to:

target=”_blank” rel=”noreferrer noopener”

This is done for security purposes. Even though the target and rel are set by default for external anchors, they can be overridden using the target and rel props.

You can show the link external icon by setting the showExternal prop.

Component preview theme
<Anchor href="https://www.nlg-npap.org/donate/" showExternal>
Donate to the National Police Accountability Project
</Anchor>

To internationalize an Anchor, simply pass an i18nExternalLinkLabel prop to the Anchor, with the value wrapped in parentheses. The value should be a translation of the phrase "link takes you to an external page", to indicate that the showExternal link will open the link in a new URL.

Component preview theme
<Anchor href="https://www.nlg-npap.org/donate/" showExternal i18nExternalLinkLabel="(este enlace redirige a una página externa)">
Soy enlace externo
</Anchor>

Anchor text should indicate what kind of information the user can expect to find when they click the link. Avoid "Learn more" or "Click here," since they don't offer any indication of where the link will take the user.

When placing an Anchor within a sentence, don't link the whole sentence. Instead, only link the text that describes where the user will go when they follow the link.

When the link is at the end of a paragraph or block of text, avoid punctuation except for a question mark.

Do

Anchors should only be used to link to another page, app, or another website.

Don't

Don’t use an anchor where a button makes more sense, i.e., closing a modal.

Using Anchor with a router

Using Anchor with a router page anchor

There are many different React based routers. For example there is:

They unfortunately all work slightly differently, have different APIs, and many versions that an application might have installed. We want Paste to be used in as many different applications as possible and as such, we have chosen to not support any one router.

Anchor is just a styled HTML anchor element. You should be able to use it with any React based router. It just means that you need to do a little work to wire it up inside your application.

There are many different ways you can achieve this based on the router you are using, but as an example we include a Codesandbox below using React Router(link takes you to an external page), to give you a rough guide on how you might approach it.