Skip to the content
human-kit design
38 — Navigation

Link

A link in a line of text, underlined, and marked when it leaves the site.

Read the consent guide before the visit.

Installation

pnpm dlx @human-kit/design add link
npx @human-kit/design add link
yarn dlx @human-kit/design add link
bunx @human-kit/design add link

The command copies the files to src/lib/components/ui/link. It also installs the packages that the files import.

Usage

<script lang="ts">
	import * as Link from '$lib/components/ui/link';
</script>

<p>Read the <Link.Root href="/consent">consent guide</Link.Root> before the visit.</p>

Examples

Among quiet words

variant="muted" takes the grey of a caption or a footer, and its line shows only under the pointer. Use it where a full link in each line would be louder than the text around it.

Last edited by Dr. Ospina on 12 March. See the history · Print

Guidelines

  • Use a link to go somewhere, a page or a place on it. For an action that changes something, use a Button.Root, with variant="link" if it has to sit in a sentence.
  • Use default inside a paragraph. Use muted in captions, footers and metadata, where the words around it are muted too.
  • Make the linked words say where they go: "the consent guide", not "here" or "click this".
  • Set external for a link to another site: it opens in a new tab and says so.

Accessibility

  • It renders a native <a href>, so it is reached with Tab, opened with Enter, and keeps the browser's own menu.
  • It is underlined, not only coloured, so it is found by people who do not tell the colours apart.
  • With external, the arrow is hidden from assistive technology and the words in externalLabel are read in its place. Translate them with the rest of the page.
  • An external link gets rel="noopener noreferrer", so the new tab cannot reach back to the page.
  • Mark the link to the page being shown with aria-current="page", which it passes through.

API reference

PropTypeDefault
hrefstring

Where it goes. Required.

—
variant'default' | 'muted'

The ink of the text around it, or the muted grey.

'default'
externalboolean

Off to another site: a new tab, an arrow, and words that say so.

false
externalLabelstring

The words a screen reader hears in place of the arrow.

'(opens in a new tab)'

Plus every attribute of a native <a>.