# Link

A link in running text or on its own.

A link in running text ("read the deploy log"), or one on its own ("View all deploys"). Inline links are always underlined, in a softer shade that takes the full colour on hover; standalone links are medium weight and underline on hover. Accent or neutral tone. external opens a new tab and says so: an arrow after the text and a visually hidden "(opens in a new tab)". Text links never scale; a press shifts the colour. Use it instead of a bare <a>; for a router's link component, give it the recipe's classes (link()).

Kind: component · Category: Navigation · Status: beta · Targets: React, Vue, Svelte

## Add

```bash
npx fndn add link
```

It writes the folder `link/` into the project's ui folder (`index.ts`, `link.tsx`, `Link.vue`, `Link.svelte`, `link.recipe.ts`). First time: [Installation](/installation.md).

## Usage

```tsx
import { Link } from "@/components/ui/link";
```

```vue
import { Link } from "@/components/ui/link";
```

```svelte
import { Link } from "$lib/components/ui/link";
```

## Parts

In the DOM the root carries `data-slot="link"` and each part `data-slot="link-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `a` | `link` |  | The anchor, with every attribute passed on (href, download, rel…). Wraps anywhere, so a pasted URL never overflows its column; its text keeps its own direction. 3px focus-ring radius on each line of a wrapped link. |
| `external` | `span` | `link-external` | optional | With external: the arrow-up-right icon (aria-hidden, 0.85em, mirrored right-to-left) held to the last word, not underlined, followed by a visually hidden label ("(opens in a new tab)"). |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `href` | `string` |  | Where it goes. |
| `variant` | `"inline" \| "standalone"` | `"inline"` | inline: inside a sentence, always underlined (1px, 3px under the text, 40% of the link's colour; full colour on hover). standalone: a link on its own line or at the end of a card ("View all deploys"): medium weight, no line at rest, the line on hover; its hit area is 40px tall on coarse pointers. |
| `tone` | `"accent" \| "neutral"` | `"accent"` | accent: accent-ink, the link in product text. neutral: ink with an ink-3 underline (the line is all that marks it), for quiet text (a field hint, a footnote, terms). |
| `external` | `boolean` | `false` | Opens in a new tab: target=_blank, rel="noopener noreferrer", the arrow marker and the hidden label. A rel or target you pass wins. |
| `labels` | `object` |  | { external: '(opens in a new tab)' }, the hidden text read after an external link. |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## Slots

| Slot | Content |
| --- | --- |
| `default` | The link text (and an icon with data-slot="icon", which takes 1em). |

## States

`hover`, `press`, `focus-visible`

## Keyboard and accessibility

Role: link (native <a href>).

Keyboard:

- Tab reaches it; Enter follows it

Notes:

- Inline links are underlined at rest: colour alone does not tell a link from text.
- An external link says so to screen readers ("(opens in a new tab)", visually hidden) and to sight (the arrow).
- Name the destination in the text ("read the deploy log"), not "click here".
- No visited colour: product links are navigation, the same link looks the same every time.

## Motion

- hover: colour and underline colour over duration.fast (a real pointer only)
- press: the colour shifts at once (accent → accent; neutral → ink-2) and eases back over duration.fast on release; no scale (text links never scale)
- focus: the global ring, never faded

## Tokens

`color.accent`, `color.accent-ink`, `color.ink`, `color.ink-2`, `color.ink-3`, `duration.fast`

## Examples

### Deploy failed (links in a sentence)

React · `deploy-failed.tsx`

```tsx
import { Link } from "@/components/ui/link";

export default function DeployFailed() {
  return (
    <p className="max-w-80 text-sm text-ink-2">
      The build of <span className="font-mono text-xs">dpl_7f3a9c</span> failed at "Install dependencies".{" "}
      <Link href="/web-app/deploys/dpl_7f3a9c/logs">Read the deploy log</Link> or{" "}
      <Link href="/web-app/deploys/dpl_6e21b4">roll back to the last good deploy</Link>.
    </p>
  );
}
```

Vue · `deploy-failed.vue`

```vue
<script setup lang="ts">
import { Link } from "@/components/ui/link";
</script>

<template>
  <p class="max-w-80 text-sm text-ink-2">
    The build of <span class="font-mono text-xs">dpl_7f3a9c</span> failed at "Install dependencies".
    <Link href="/web-app/deploys/dpl_7f3a9c/logs">Read the deploy log</Link> or
    <Link href="/web-app/deploys/dpl_6e21b4">roll back to the last good deploy</Link>.
  </p>
</template>
```

Svelte · `deploy-failed.svelte`

```svelte
<script lang="ts">
  import { Link } from "$lib/components/ui/link";
</script>

<p class="max-w-80 text-sm text-ink-2">
  The build of <span class="font-mono text-xs">dpl_7f3a9c</span> failed at "Install dependencies".
  <Link href="/web-app/deploys/dpl_7f3a9c/logs">Read the deploy log</Link> or
  <Link href="/web-app/deploys/dpl_6e21b4">roll back to the last good deploy</Link>.
</p>
```

### View all deploys (standalone)

React · `view-all-deploys.tsx`

```tsx
import { ArrowRight } from "@phosphor-icons/react";
import { Link } from "@/components/ui/link";
import { StatusPill } from "@/components/ui/status-pill";

const DEPLOYS = [
  { id: "dpl_7f3a9c", branch: "main", status: "Failed", tone: "red" },
  { id: "dpl_6e21b4", branch: "feat/usage-alerts", status: "Ready", tone: "green" },
] as const;

export default function ViewAllDeploys() {
  return (
    <section className="flex w-80 flex-col gap-2 text-sm">
      <ul className="flex flex-col divide-y divide-line">
        {DEPLOYS.map((d) => (
          <li key={d.id} className="flex items-center justify-between gap-3 py-2">
            <span className="min-w-0"><span className="font-mono text-xs text-ink">{d.id}</span> <span className="text-ink-2">{d.branch}</span></span>
            <StatusPill size="sm" tone={d.tone}>{d.status}</StatusPill>
          </li>
        ))}
      </ul>
      <Link variant="standalone" href="/web-app/deploys" className="self-start">
        View all deploys <ArrowRight data-slot="icon" weight="bold" className="rtl:-scale-x-100" />
      </Link>
    </section>
  );
}
```

Vue · `view-all-deploys.vue`

```vue
<script setup lang="ts">
import { PhArrowRight } from "@phosphor-icons/vue";
import { Link } from "@/components/ui/link";
import { StatusPill } from "@/components/ui/status-pill";

const DEPLOYS = [
  { id: "dpl_7f3a9c", branch: "main", status: "Failed", tone: "red" },
  { id: "dpl_6e21b4", branch: "feat/usage-alerts", status: "Ready", tone: "green" },
] as const;
</script>

<template>
  <section class="flex w-80 flex-col gap-2 text-sm">
    <ul class="flex flex-col divide-y divide-line">
      <li v-for="d in DEPLOYS" :key="d.id" class="flex items-center justify-between gap-3 py-2">
        <span class="min-w-0"><span class="font-mono text-xs text-ink">{{ d.id }}</span> <span class="text-ink-2">{{ d.branch }}</span></span>
        <StatusPill size="sm" :tone="d.tone">{{ d.status }}</StatusPill>
      </li>
    </ul>
    <Link variant="standalone" href="/web-app/deploys" class="self-start">
      View all deploys <PhArrowRight data-slot="icon" weight="bold" class="rtl:-scale-x-100" />
    </Link>
  </section>
</template>
```

Svelte · `view-all-deploys.svelte`

```svelte
<script lang="ts">
  import ArrowRight from "phosphor-svelte/lib/ArrowRightIcon";
  import { Link } from "$lib/components/ui/link";
  import { StatusPill } from "$lib/components/ui/status-pill";

  const DEPLOYS = [
    { id: "dpl_7f3a9c", branch: "main", status: "Failed", tone: "red" },
    { id: "dpl_6e21b4", branch: "feat/usage-alerts", status: "Ready", tone: "green" },
  ] as const;
</script>

<section class="flex w-80 flex-col gap-2 text-sm">
  <ul class="flex flex-col divide-y divide-line">
    {#each DEPLOYS as d (d.id)}
      <li class="flex items-center justify-between gap-3 py-2">
        <span class="min-w-0"><span class="font-mono text-xs text-ink">{d.id}</span> <span class="text-ink-2">{d.branch}</span></span>
        <StatusPill size="sm" tone={d.tone}>{d.status}</StatusPill>
      </li>
    {/each}
  </ul>
  <Link variant="standalone" href="/web-app/deploys" class="self-start">
    View all deploys <ArrowRight data-slot="icon" weight="bold" class="rtl:-scale-x-100" />
  </Link>
</section>
```

### Status page (opens in a new tab)

React · `status-page.tsx`

```tsx
import { Link } from "@/components/ui/link";

export default function StatusPage() {
  return (
    <p className="max-w-80 text-sm text-ink-2">
      Deploys to Production are slower than usual. Follow the incident on our{" "}
      <Link href="https://status.northwind.example" external>status page</Link>.
    </p>
  );
}
```

Vue · `status-page.vue`

```vue
<script setup lang="ts">
import { Link } from "@/components/ui/link";
</script>

<template>
  <p class="max-w-80 text-sm text-ink-2">
    Deploys to Production are slower than usual. Follow the incident on our
    <Link href="https://status.northwind.example" external>status page</Link>.
  </p>
</template>
```

Svelte · `status-page.svelte`

```svelte
<script lang="ts">
  import { Link } from "$lib/components/ui/link";
</script>

<p class="max-w-80 text-sm text-ink-2">
  Deploys to Production are slower than usual. Follow the incident on our
  <Link href="https://status.northwind.example" external>status page</Link>.
</p>
```

### Terms under a form (neutral)

React · `terms-hint.tsx`

```tsx
import { Link } from "@/components/ui/link";

export default function TermsHint() {
  return (
    <p className="max-w-80 text-xs text-ink-2">
      By creating the Northwind workspace you agree to the{" "}
      <Link tone="neutral" href="/legal/terms">Terms of service</Link> and the{" "}
      <Link tone="neutral" href="/legal/privacy">Privacy policy</Link>.
    </p>
  );
}
```

Vue · `terms-hint.vue`

```vue
<script setup lang="ts">
import { Link } from "@/components/ui/link";
</script>

<template>
  <p class="max-w-80 text-xs text-ink-2">
    By creating the Northwind workspace you agree to the
    <Link tone="neutral" href="/legal/terms">Terms of service</Link> and the
    <Link tone="neutral" href="/legal/privacy">Privacy policy</Link>.
  </p>
</template>
```

Svelte · `terms-hint.svelte`

```svelte
<script lang="ts">
  import { Link } from "$lib/components/ui/link";
</script>

<p class="max-w-80 text-xs text-ink-2">
  By creating the Northwind workspace you agree to the
  <Link tone="neutral" href="/legal/terms">Terms of service</Link> and the
  <Link tone="neutral" href="/legal/privacy">Privacy policy</Link>.
</p>
```

## Recipe

`link.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";

/* link — a link in running text, or one on its own ("View all deploys").
 *
 * Inline: always underlined (colour alone does not mark a link, accessibility.md), a 1px line 3px
 * under the text in a softer shade of the link's colour; hover gives the line the full colour.
 * Standalone: medium weight, no line at rest, the line on hover. Both wrap anywhere (a pasted URL
 * never overflows its column) and keep their own direction (plaintext).
 *
 * Tone: accent (accent-ink) for a link in product text; neutral (ink, the line in ink-3: the line
 * is all that marks it) for a link in quiet text (a footnote, a field hint, terms). Visited links
 * look the same: a product's links are navigation, not a reading list.
 *
 * Press: text links never scale (as breadcrumb's); a pointer press turns the text
 * accent (accent) or ink-2 (neutral) at once, the release eases back over duration.fast. The focus
 * ring is the global one (2px accent, 2px out), following a 3px radius on every line of a wrapped
 * link (box-decoration-clone).
 *
 * External: the arrow-up-right marker after the text (it mirrors right-to-left), kept on the last
 * word's line, and a visually hidden "(opens in a new tab)". */

export const link = tv({
  slots: {
    base: [
      "rounded-[3px] box-decoration-clone wrap-anywhere [unicode-bidi:plaintext] [touch-action:manipulation]",
      "underline decoration-1 underline-offset-[3px]",
      "motion-colors-fast active:duration-0",
      /* an icon in the text (data-slot=icon, 1em) sits on the text line */
      "[&>[data-slot=icon]]:inline-block [&>[data-slot=icon]]:align-[-0.125em]",
    ],
    /* the external marker: an inline icon that the underline skips, held to the last word */
    external: [
      "inline-block ms-0.5 align-[-0.1em] no-underline whitespace-nowrap",
      "[&>[data-slot=icon]]:size-[0.85em] [&>[data-slot=icon]]:inline-block [:dir(rtl)_&>[data-slot=icon]]:[transform:scaleX(-1)]",
    ],
  },
  variants: {
    variant: {
      inline: {},
      standalone: {
        base: [
          "relative font-medium decoration-transparent hover:decoration-current",
          /* a taller hit area on touch, not wider (it never pokes out of a narrow row) */
          "pointer-coarse:after:absolute pointer-coarse:after:inset-x-0 pointer-coarse:after:-inset-y-2.5 pointer-coarse:after:content-['']",
        ],
      },
    },
    tone: {
      accent: { base: "text-accent-ink active:text-accent" },
      neutral: { base: "text-ink active:text-ink-2" },
    },
  },
  compoundVariants: [
    { variant: "inline", tone: "accent", class: { base: "decoration-[color-mix(in_srgb,var(--fndn-accent-ink)_40%,transparent)] hover:decoration-accent-ink" } },
    { variant: "inline", tone: "neutral", class: { base: "decoration-ink-3 hover:decoration-ink" } },
  ],
  defaultVariants: { variant: "inline", tone: "accent" },
});

export type LinkRecipeProps = VariantProps<typeof link>;
```
