<!-- index: /slotted/llms.txt -->
# link

`data-ui="link"` · Text link to another page or resource.

## Import

```tsx
import { Link, LinkDefaultsProvider } from '@slotted/react';
```

## Minimal example

Example

```tsx
import { Link } from '@slotted/react/link';
import { Text } from '@slotted/react/typography';

export default function LinkBasic() {
  return (
    <Text>
      Payment is due 30 days after the invoice date. Read the{' '}
      <Link href="#terms">terms of service</Link> before you confirm the order.
    </Text>
  );
}
```

## Anatomy

| Part | Element | Required |
| --- | --- | --- |
| `root` | a | yes |
| `external-icon` | span | no |
| `external-hint` | span | no |

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `underline` | `'always' \| 'hover' \| 'none'` | always | Link | When the underline is drawn. |
| `variant` | `'accent' \| 'neutral' \| 'inverse'` | accent | Link | The accent color, the color of the surrounding text, or the color for a solid surface. |
| `size` | `'xs' \| 'sm' \| 'md'` | — | Link | The text size: 12, 13 or 14 pixels on the type scale. Unset, the link takes the size its action slot states — a stat card’s action, a section’s or a chart’s actions state sm — or else its parent’s. |
| `external` | `boolean` | false | Link | Opens a new tab and warns that it does. |
| `messages` | `Partial<LinkMessages>` | — | Link | Words laid over the language in force: the wording of that warning (externalHint). |
| `disabled` | `boolean` | false | Link | Withholds the destination, keeps the role, the state and the tab stop. |
| `visited` | `boolean` | false | Link | Paints a destination the reader already followed. |
| `href` | `string` | — | Link | The destination, and every other anchor attribute — target, rel, download, hreflang — reaches the element unchanged. |
| `render` | `(props: LinkRootProps) => ReactNode` | — | Link | Substitutes the rendered element. The destination and every data attribute are handed to it, so a router link keeps both. |
| `ref` | `Ref<HTMLAnchorElement>` | — | Link | Reaches the anchor, and focus() with it. |
| `onClick, onAuxClick, onKeyDown` | `EventHandler` | — | Link | Composed rather than replaced. While disabled, Link refuses the event first and the handler is not called. |
| `LinkDefaultsProvider` | `underline \| variant \| visited` | — | Application | Sets those three once for everything below it. A prop on the link still wins. |

## Axes and defaults

| Axis | Values | Default |
| --- | --- | --- |
| `size` | `xs`, `sm`, `md` | — |
| `underline` | `always`, `hover`, `none` | `always` |
| `variant` | `accent`, `neutral`, `inverse` | `accent` |

## Rules

- The rendered element is a plain anchor with an href, so the link role, Enter, the context menu and every modified click come from the platform. Space does not activate a link, and nothing here makes it. An action inside a line that runs a handler and goes nowhere is a Button with inline, not a Link without an href.
- underline="always" is the default because color alone does not distinguish a link: the accent text color clears 4.5:1 against the surface and not 3:1 against the body text beside it.
- variant="neutral" takes the color of the text around it, so it belongs where nothing on the line could be mistaken for it — a cell, a title, a row — and never inside a sentence.
- Whatever the underline axis says, the underline returns under forced-colors, where the palette flattens the color contrast a bare link relies on.
- A new browsing context is announced in the accessible name and marked with a glyph, and both follow the resolved target: a target="_blank" you write is warned about exactly like external.
- external also sets rel="noopener noreferrer"; a rel or target you pass is kept instead of rewritten.
- A disabled link renders no href, which is what stops a middle click as well as a left one, and keeps role="link", aria-disabled and its place in the tab sequence so the state can be discovered.
- The current page is painted from aria-current, the attribute a router already writes; Link adds no prop for it.

## Tokens

`--slotted-control-radius`, `--slotted-disabled-foreground`, `--slotted-duration-short`, `--slotted-easing-standard`, `--slotted-focus-ring-color`, `--slotted-focus-ring-width`, `--slotted-font-size-md`, `--slotted-font-size-sm`, `--slotted-font-size-xs`, `--slotted-link-color`, `--slotted-link-color-active`, `--slotted-link-color-current`, `--slotted-link-color-disabled`, `--slotted-link-color-hover`, `--slotted-link-color-visited`, `--slotted-link-external-icon-gap`, `--slotted-link-external-icon-size`, `--slotted-link-focus-ring-offset`, `--slotted-link-font-size`, `--slotted-link-radius`, `--slotted-link-underline-color`, `--slotted-link-underline-offset`, `--slotted-link-underline-thickness`, `--slotted-text`, `--slotted-text-inverse`, `--slotted-text-muted`, `--slotted-tone-accent-text`

## Examples

### Playground

Every axis on one link inside a sentence, driven by the controls below the canvas. Change underline and watch what a reader has left to recognize the link by.

Excerpt — not a complete module

```tsx
<p>
  Read the <Link href="/terms">terms of service</Link> before continuing.
</p>;
```

### When the underline is drawn

always is the default and the only value safe inside a sentence: the accent text color clears 4.5:1 against the surface but not 3:1 against the body text beside it.

Example

```tsx
import { Inline } from '@slotted/react/inline';
import { Link } from '@slotted/react/link';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

export default function LinkUnderline() {
  return (
    <Stack gap={3}>
      <Inline gap={3}>
        <Text size="sm" tone="muted">
          always
        </Text>
        <Link href="#register">Invoice register</Link>
      </Inline>
      <Inline gap={3}>
        <Text size="sm" tone="muted">
          hover
        </Text>
        <Link href="#payments" underline="hover">
          Payment runs
        </Link>
      </Inline>
      <Inline gap={3}>
        <Text size="sm" tone="muted">
          none
        </Text>
        <Link href="#suppliers" underline="none">
          Supplier directory
        </Link>
      </Inline>
    </Stack>
  );
}
```

### How the link is painted

accent invites, neutral takes the color of the text around it for a cell or a title, and inverse is the link on a solid surface. Hover moves each one toward the strongest text color its context has.

Example

```tsx
import { Alert, AlertContent, AlertDescription } from '@slotted/react/alert';
import { Inline } from '@slotted/react/inline';
import { Link } from '@slotted/react/link';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

export default function LinkVariants() {
  return (
    <Stack gap={4}>
      <Text>
        Review the <Link href="#history">payment history</Link> before the due date.
      </Text>
      <Inline gap={3}>
        <Text size="sm" tone="muted">
          Invoice
        </Text>
        <Link href="#invoice" underline="hover" variant="neutral">
          INV-2026-08-0041
        </Link>
      </Inline>
      <Alert tone="accent" variant="solid">
        <AlertContent>
          <AlertDescription>
            Your trial ends in three days.{' '}
            <Link href="#plans" variant="inverse">
              Choose a plan
            </Link>
          </AlertDescription>
        </AlertContent>
      </Alert>
    </Stack>
  );
}
```

### Leaving the application

One fact told three ways: the safe rel, the marker for the eye, the warning in the accessible name. All three follow the resolved target, so a target written by hand is announced the same way.

Example

```tsx
import { Link } from '@slotted/react/link';
import { Stack } from '@slotted/react/stack';

export default function LinkExternal() {
  return (
    <Stack gap={3}>
      <Link external href="https://example.com/carriers/northwind-freight">
        Carrier tracking page
      </Link>
      <Link href="https://example.com/status" target="_blank">
        Carrier service status
      </Link>
      <Link
        external
        href="https://example.com/customs/guide"
        messages={{ externalHint: '(opens in a new window)' }}
      >
        Customs documentation guide
      </Link>
    </Stack>
  );
}
```

### States

Hover darkens the text and fills the underline, press goes one step further, and an unavailable link keeps its underline so it still reads as a link rather than as plain text.

Example

```tsx
import { Link } from '@slotted/react/link';
import { Stack } from '@slotted/react/stack';

export default function LinkStates() {
  return (
    <Stack gap={3}>
      <Link href="#order-4821">Open order 4821</Link>
      <Link href="#order-4820" visited>
        Order 4820, in the visited color once followed
      </Link>
      <Link disabled href="#order-4822">
        Order 4822, available once it ships
      </Link>
    </Stack>
  );
}
```

### The page you are on

aria-current is the input, because it is the attribute a router already writes. The link takes the body color and keeps its underline, and no width changes, so the column beside it does not shift.

Example

```tsx
import { Inline } from '@slotted/react/inline';
import { Link } from '@slotted/react/link';

export default function LinkCurrent() {
  return (
    <nav aria-label="Workspace">
      <Inline gap={4}>
        <Link aria-current="page" href="#orders" underline="hover">
          Orders
        </Link>
        <Link href="#shipments" underline="hover">
          Shipments
        </Link>
        <Link href="#returns" underline="hover">
          Returns
        </Link>
        <Link href="#suppliers" underline="hover">
          Suppliers
        </Link>
      </Inline>
    </nav>
  );
}
```

### Content the link did not choose

A pasted URL with no spaces, a long German compound, and an Arabic sentence. The first two break inside the column instead of widening it; the third mirrors the marker without mirroring the Latin island beside it.

Excerpt — not a complete module

```tsx
<Link href="/reconciliation">
  https://billing.example.com/accounts/8412/invoices/2026-08/reconciliation-report
</Link>;
```

### Composition

render substitutes the element for a router link and hands it the destination, and LinkDefaultsProvider decides for a whole application what a link looks like. An explicit prop still wins over both.

Excerpt — not a complete module

```tsx
<Link href="/invoices" render={(props) => <RouterLink {...props} to={props.href} />}>
  Invoices
</Link>;

<LinkDefaultsProvider underline="hover">
  <App />
</LinkDefaultsProvider>;
```

### Keyboard and announcement

Tab reaches every link including the unavailable one, Enter follows the one that has a destination, and Space does nothing because Space does not activate a link.

Excerpt — not a complete module

```tsx
<Link href="/invoices">A link with a destination</Link>;
<Link external href="https://example.com/status">
  A link that leaves the application
</Link>;
<Link disabled href="/invoices/0042">
  A link that is unavailable
</Link>;
```

### action.tsx

Example

```tsx
import { Button } from '@slotted/react/button';
import { Link } from '@slotted/react/link';
import { Text } from '@slotted/react/typography';

export default function LinkAction() {
  return (
    <Text>
      Invoice INV-2026-08-0041 was sent to the buyer on September 3.{' '}
      <Link href="#invoice">View the invoice</Link> or <Button inline>send it again</Button>.
    </Text>
  );
}
```

### defaults.tsx

Example

```tsx
import { Link, LinkDefaultsProvider } from '@slotted/react/link';
import { Stack } from '@slotted/react/stack';

export default function LinkApplicationDefaults() {
  return (
    <LinkDefaultsProvider underline="hover" variant="neutral">
      <Stack gap={2}>
        <Link href="#inv-0041">INV-2026-08-0041</Link>
        <Link href="#inv-0042">INV-2026-08-0042</Link>
        <Link href="#inv-0043">INV-2026-08-0043</Link>
        <Link href="#register" underline="always" variant="accent">
          Open the invoice register
        </Link>
      </Stack>
    </LinkDefaultsProvider>
  );
}
```

### router.tsx

Example

```tsx
import { Inline } from '@slotted/react/inline';
import { Link } from '@slotted/react/link';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';
import { useState } from 'react';
import type { MouseEvent, ReactNode } from 'react';

const VIEWS = [
  { href: '#orders', label: 'Orders' },
  { href: '#shipments', label: 'Shipments' },
  { href: '#returns', label: 'Returns' },
] as const;

interface RouterLinkProps {
  children: ReactNode;
  current: boolean;
  href: string;
  onNavigate: (href: string) => void;
}

export default function LinkRouter() {
  const [path, setPath] = useState<string>(VIEWS[0].href);
  const label = VIEWS.find((view) => view.href === path)?.label;

  return (
    <Stack gap={3}>
      <nav aria-label="Workspace">
        <Inline gap={4}>
          {VIEWS.map((view) => (
            <RouterLink
              current={view.href === path}
              href={view.href}
              key={view.href}
              onNavigate={setPath}
            >
              {view.label}
            </RouterLink>
          ))}
        </Inline>
      </nav>
      <Text size="sm" tone="muted">
        Showing {label}.
      </Text>
    </Stack>
  );
}

function RouterLink({ children, current, href, onNavigate }: RouterLinkProps) {
  function handleClick(event: MouseEvent<HTMLAnchorElement>) {
    event.preventDefault();
    onNavigate(href);
  }

  return (
    <Link
      aria-current={current ? 'page' : undefined}
      href={href}
      render={(props) => <a {...props} onClick={handleClick} />}
      underline="hover"
    >
      {children}
    </Link>
  );
}
```

### sizes.tsx

Example

```tsx
import { Inline } from '@slotted/react/inline';
import { Link } from '@slotted/react/link';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

export default function LinkSizes() {
  return (
    <Stack gap={3}>
      <Inline align="baseline" gap={4}>
        <Link href="#orders" size="xs">
          Orders
        </Link>
        <Link href="#shipments" size="sm">
          Shipments
        </Link>
        <Link href="#returns" size="md">
          Returns
        </Link>
      </Inline>
      <Text size="lg">
        Without a size, a link takes the text around it:{' '}
        <Link href="#forecast">open the demand forecast</Link>.
      </Text>
    </Stack>
  );
}
```
