The Link component allows you to show links on the page, open them in a new window, and change the color.

Props

Name
Type
Default
Required
string
-
string
-

Supply a short, descriptive label for screen-readers to replace link texts that don't provide sufficient context about the link component behavior. Texts like Click Here, or Read More can be confusing when a screen reader reads them out of context. In those cases, we must pass an alternative text to replace the link text.

Accessibility: It populates aria-label. Screen readers read the accessibilityLabel prop, if present, instead of the link text.

boolean
-
children
React.Node
-
"none" | "underline"
"underline"
id
string
-

id attribute of the anchor tag

boolean
false
onBlur
() => void
-
AbstractEventHandler<SyntheticMouseEvent<HTMLAnchorElement> | SyntheticKeyboardEvent<HTMLAnchorElement>, {| disableOnNavigation: () => void |}>
-

Callback fired when Link is clicked (pressed and released) with a mouse or keyboard. See custom navigation variant for examples.

onFocus
() => void
-
ref
React.Ref<"a">
-

Forward the ref to the underlying anchor element

rel
"none" | "nofollow"
"none"
"tab"
-
"pill" | "circle" | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8
"0"
"none" | "compress"
"none"
"null" | "self" | "blank"
"null"

Usage guidelines

When to Use
  • For navigation within or directly accompanying a sentence.
  • Directing users to another page or a different portion of the same page.
When Not to Use
  • Performing actions, such as "Save", "Cancel" or "Delete". Use Button instead.
  • Submitting a form or opening a modal. Use Button instead.

Example

You should wrap Link components inside of a Text component to get the correct font & underline color.

Accessible Content

When providing the content for the link, avoid phrases like "click here" or "go to".

Bad ❌

For more information, click here.

Good ✅

Visit Pinterest.com for more information.

Accessible Tab Link

Use accessibilitySelected and role when using it as a Tab.

Permutations: tapStyle and hoverStyle

Variants

Custom navigation

This example illustrates two custom navigation implementations to externally control the link navigation behavior of Link: setting a default logic with OnLinkNavigationProvider and a custom component logic with the onClick prop.

If onNavigation prop is passed to OnLinkNavigationProvider, it's passed down to all children links and sets a custom default link navigation behavior. onLinkNavigation is a higher-order function: it takes named arguments (href and target) and returns an event handler function. In the component's onClick event handler, the onClick prop gets called first, followed by the function passed down by the OnLinkNavigationProvider.

Link's onClick prop is an event handler function. This callback takes 2 named parameters: 'event', the 'onClick' event, and disableOnNavigation, a callback function that disables any default custom navigation logic set by OnLinkNavigationProvider. disableOnNavigation is only accessible in OnLinkNavigationProvider's children components with link behavior.

In this example, Link has a parent OnLinkNavigationProvider setting a default custom navigation logic. We can compare three navigation behaviors: (a) the default Link behavior (by disabling the OnLinkNavigationProvider's inherited logic), (b) the default custom behavior set by OnLinkNavigationProvider and (c) a custom behavior set on Link.

onClick is used to disable the default custom logic set in OnLinkNavigationProvider and implement custom behavior at the component level. disableOnNavigation and customOnNavigation are both called first during the 'onClick' event.

If onNavigation is a custom hook function, it can contain complex logic, including React hooks, to perform side effects.

In this example, both onNavigation and customOnNavigation functions execute the following actions:

  • Disable the default link behavior
  • Show an alert message
  • Open a different URL in a new window

Both onNavigationClick, inside onNavigation, and onClick have event access to preventDefault(). It could also be used to stopPropagation().

Navigation controller:

OnLinkNavigationProvider
OnLinkNavigationProvider allows external link navigation control across all children components with link behavior.
See custom navigation variant for examples.