Overview
A link is an <a> element. Every <a> gets the link look, with or without the nds-link class, except buttons, cards and avatars. A script marks each link to another website as external.
Pick another component when:
- the element starts an action instead of opening a page: Button, for example
nds-btn nds-subtle - the links show where the page sits in the site: Breadcrumb
- the links are the site’s navigation: Side Menu or Tabs
Markup
Variants
Every row goes on the link. Inside a content section, a link is also underlined. The builder preview sits outside one.
| Group | Option | Markup | On element | Use |
|---|---|---|---|---|
| Color | Primary (default) | — | — | The brand color, for links in running text |
| Color | Neutral | .nds-neutral |
.nds-link |
A quiet link that does not draw the eye, such as a secondary link in a list |
| Color | On color (hint: For a deep primary or dark background) | .nds-oncolor |
.nds-link |
For a link on a deep primary or dark background. Inside an on-color area (data-theme="dark oncolor"), the link already takes this look: skip the class |
| Icon | None (default) | — | — | Text only. A link to another website gets the external icon from the script |
| Icon | Link icon (hint: A chain-link icon after the text) | .nds-icon |
.nds-link |
A link icon after the text, for an internal link that needs a visual cue |
| Icon | External icon | .nds-external |
.nds-link |
The external icon after the text. The script adds it to links to other websites, so add it yourself only to force it |
| Underline | Underline | .nds-underline |
.nds-link |
Always underlined, for dense text where color alone does not mark the link |
Built-in Features
-
Auto-initialization
The script runs on every page when it loads. It needs no selector and no call.
-
Color Variants
Primary, neutral and on color, each with its own hover, pressed, focus and visited colors from design tokens.
-
External Link Detection
The script compares each link's hostname with the page's hostname. A link to another hostname, a subdomain included, gets the external icon.
-
Safe Navigation
An external link opens in a new tab. Browsers already add
noopenertotarget="_blank", so the script adds norel. -
Block Content
A link that wraps a block, such as
<a><p>…</p></a>from an editor, gets the external icon inside its last block, so the icon stays on the text line. -
Opt-out Control
data-no-externalon a link or on a container stops the external icon and the new tab for every link inside it. -
Underline Modifier
A link is underlined on hover and when pressed.
nds-underlinekeeps the underline on, and links inside a content section always have it.
Best Practices
- Keep the primary default for links in running text, so readers find them.
- Add
nds-neutralto a link that should stay quiet, such as a secondary link in a list or in metadata. - Add
nds-underlinein dense text outside a content section, where color alone does not mark the link. - On a deep primary or dark surface, primary and neutral links lack contrast. On a deep primary surface, give it
data-theme="dark oncolor primary": a primary link takes the white look. See Color Areas. On a dark surface, give itdata-theme="dark". For one link, addnds-oncolor. - Write link text that names the destination, such as “official guidelines”. Avoid “click here”.
- Do not add
target="_blank"to a link to another website: the script adds it. Addrel="noreferrer"yourself when the link must not send the page address. - Add
data-no-externalto a link or a container for a trusted partner site or an embedded widget that must open in the same tab. - A link that holds only an icon or an image gets no external icon from the script. Add
nds-externalto it to force the icon.
API
Other Classes
| Class | Element | Effect |
|---|---|---|
nds-primary |
.nds-link |
Primary inside a host that makes its links neutral, such as a breadcrumb or an alert |
nds-color |
.nds-link |
The same as nds-primary |
nds-external-block |
.nds-link |
The script adds it to an external link that wraps a block. The icon moves to that block |
nds-external-badge |
the link’s last block | The script adds it to the block that shows the external icon |
Data Attributes
| Attribute | Element | Effect |
|---|---|---|
data-no-external |
<a> or any container |
The script skips every link inside it: no external icon and no new tab |
CSS Custom Properties
Set these on the link, or on a container to reach every link inside it. The color classes set the five color properties.
| Property | Default | Controls |
|---|---|---|
--link-color |
var(--link-primary) |
Text color |
--link-hover |
var(--link-primary-hovered) |
Text color on hover |
--link-pressed |
var(--link-primary-pressed) |
Text color when pressed |
--link-focused |
var(--link-primary-focused) |
Text color when focused |
--link-visited |
var(--link-primary-visited) |
Text color after a visit |
--link-decoration |
none |
Text decoration. Hover, press, nds-underline and a content section set underline |
Tokens
Set a token at :root, or on a wrapper to reach every link inside it. Give a token with a Dark mode value a dark override too: see Tokens.
Source: the link group in _sass/tokens/_components.scss.
| Token | Preview | Value |
|---|---|---|
--link-primary | var(--text-primary)Dark mode var(--colors-primary-400) | |
--link-primary-hovered | var(--colors-primary-700)Dark mode var(--colors-primary-300) | |
--link-primary-pressed | var(--colors-primary-800)Dark mode var(--colors-primary-200) | |
--link-primary-focused | var(--text-primary)Dark mode var(--colors-primary-400) | |
--link-primary-visited | var(--colors-primary-800)Dark mode var(--colors-primary-300) | |
--link-neutral | var(--colors-neutral-700)Dark mode var(--colors-neutral-200) | |
--link-neutral-hovered | var(--colors-neutral-500)Dark mode var(--colors-neutral-400) | |
--link-neutral-pressed | var(--colors-neutral-400)Dark mode var(--colors-neutral-500) | |
--link-neutral-focused | var(--colors-neutral-700)Dark mode var(--colors-neutral-200) | |
--link-neutral-visited | var(--colors-neutral-600)Dark mode var(--colors-neutral-300) | |
--link-oncolor | var(--colors-base-white) | |
--link-oncolor-hovered | var(--colors-alpha-white-80) | |
--link-oncolor-pressed | var(--colors-alpha-white-60) | |
--link-oncolor-focused | var(--colors-base-white) | |
--link-oncolor-visited | var(--colors-alpha-white-90) |
JavaScript
| Method | Effect |
|---|---|
NDS.Link.init() |
Marks every link to another hostname: adds nds-external and target="_blank". It runs on page load. Call it again after you add links to the page |
The full API is in the banner of _js/nds-link.js.