38 — Navigation
Link
A link in a line of text, underlined, and marked when it leaves the site.
Installation
pnpm dlx @human-kit/design add linknpx @human-kit/design add linkyarn dlx @human-kit/design add linkbunx @human-kit/design add linkThe 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, withvariant="link"if it has to sit in a sentence. - Use
defaultinside a paragraph. Usemutedin 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
externalfor 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 inexternalLabelare 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
| Prop | Type | Default |
|---|---|---|
href | string Where it goes. Required. | — |
variant | 'default' | 'muted' The ink of the text around it, or the muted grey. | 'default' |
external | boolean Off to another site: a new tab, an arrow, and words that say so. | false |
externalLabel | string The words a screen reader hears in place of the arrow. | '(opens in a new tab)' |
Plus every attribute of a native <a>.