# Link

A semantic anchor with Zenos visual treatments and sizes.

A semantic anchor for standalone navigation and links embedded in running text.

```tsx
import { Link, Stack, Text } from "@zentara-co/zenos-ui";

type CatalogVariantProps = { limit?: number };

const limited = <T,>(items: readonly T[], limit?: number) =>
  limit === undefined ? items : items.slice(0, limit);

function LinkVariantsExample({ limit }: CatalogVariantProps = {}) {
  return (
    <Stack gap="5" className="w-full max-w-2xl">
      {limited(["default", "muted", "prose"] as const, limit).map((variant) => (
        <Stack key={variant} gap="2">
          <Text as="h3" type="emphasis" size="s" color="subtle">
            {variant}
          </Text>
          {variant === "prose" ? (
            <Text as="p" color="subtle">
              Build readable layouts with the{" "}
              <Link href="#link-api" variant="prose">
                composition guide
              </Link>{" "}
              and keep the link in the flow of the sentence.
            </Text>
          ) : (
            <Link href="#link-api" variant={variant}>
              {variant === "default" ? "Read documentation" : "View release notes"}
            </Link>
          )}
        </Stack>
      ))}
    </Stack>
  );
}
```

## Import

```tsx
import { Link } from "@zentara-co/zenos-ui";
```

## Link or Button

Use Link when activation navigates to another URL, file, or page location. Use Button for actions that change local state, submit data, or open an overlay. Styling an action like a link does not change its required semantics.

## Variants

Use `default` for standalone navigation at the surrounding text's full emphasis. It shifts to the link accent on hover. Use `muted` when a secondary destination should begin at a lower emphasis, then gain the same accent on interaction.

Use `prose` inside paragraphs and other running text. It inherits the surrounding text color, stays underlined, and uses inline layout so a long link can wrap naturally with the sentence. Its underline and text both move to the link accent on hover.

`subtle` remains available as a compatibility alias for `muted`. Use `contrary` only for links placed on an inverse surface.

## Sizes

Sizes use the matching design-system body typography and scale SVGs placed inside `Link.Icon`.

```tsx
import { Link, Stack } from "@zentara-co/zenos-ui";

function LinkSizesExample() {
  return (
    <Stack direction="row" gap="5" align="center" wrap="wrap">
      <Link href="#link-api" size="sm">
        Small link
      </Link>
      <Link href="#link-api" size="md">
        Medium link
      </Link>
      <Link href="#link-api" size="lg">
        Large link
      </Link>
    </Stack>
  );
}
```

## Underline

Standalone links default to `none` because their color change and surrounding navigation context provide the affordance. Use `hover` to reveal an underline on hover and keyboard focus, or `always` when the destination needs a persistent cue. `prose` always remains underlined, even when `underline="none"` is supplied.

```tsx
import { Link, Stack } from "@zentara-co/zenos-ui";

function LinkUnderlineExample() {
  return (
    <Stack direction="row" gap="5" align="center" wrap="wrap">
      <Link href="#link-api" underline="hover">
        Underline on hover
      </Link>
      <Link href="#link-api" underline="always">
        Always underlined
      </Link>
      <Link href="#link-api" underline="none">
        No underline
      </Link>
    </Stack>
  );
}
```

## Icons

Place `Link.Icon` before or after the label according to meaning. The icon is decorative and hidden from assistive technology, so the link text must remain understandable on its own.

```tsx
import { ArrowLeftIcon, ArrowRightIcon } from "@phosphor-icons/react";
import { Link, Stack } from "@zentara-co/zenos-ui";

function LinkIconExample() {
  return (
    <Stack direction="row" gap="5" align="center" wrap="wrap">
      <Link href="#link-api">
        <Link.Icon>
          <ArrowLeftIcon className="rtl:rotate-180" />
        </Link.Icon>
        Previous page
      </Link>
      <Link href="#link-api">
        View documentation
        <Link.Icon>
          <ArrowRightIcon className="rtl:rotate-180" />
        </Link.Icon>
      </Link>
      <Link href="https://example.com" target="_blank" rel="noreferrer">
        External resource
        <Link.Icon>↗</Link.Icon>
      </Link>
    </Stack>
  );
}
```

## Custom styling

Use `className` with semantic tokens when a navigation treatment needs a distinct surface. Native anchor props and the Link focus treatment remain intact.

```tsx
import { ArrowRightIcon } from "@phosphor-icons/react";
import { Link } from "@zentara-co/zenos-ui";

function LinkCustomExample() {
  return (
    <Link
      href="#link-api"
      underline="none"
      className="rounded-full bg-background-accent-purple-subtlest-default px-3 py-1.5 text-text-accent-purple-bolder visited:text-text-accent-purple-bolder hover:bg-background-accent-purple-subtlest-hover active:bg-background-accent-purple-subtlest-pressed"
    >
      Campaign guide
      <Link.Icon>
        <ArrowRightIcon className="rtl:rotate-180" />
      </Link.Icon>
    </Link>
  );
}
```

## Composition

Link renders a native anchor. Use `render` to apply the same color, size, underline, and focus treatment to another component, such as a router link, without wrapping it in a second anchor. Actions that change local state still belong on Button.

```tsx
import { Link, Stack } from "@zentara-co/zenos-ui";
import { forwardRef, type AnchorHTMLAttributes } from "react";

const WorkspaceLink = forwardRef<
  HTMLAnchorElement,
  { to: string } & AnchorHTMLAttributes<HTMLAnchorElement>
>(function WorkspaceLink({ to, ...props }, ref) {
  return <a {...props} ref={ref} href={to} />;
});

function LinkRenderExample() {
  return (
    <Stack direction="row" gap="5" align="center" wrap="wrap">
      <Link render={<WorkspaceLink to="/components/link/#composition" />}>Workspace settings</Link>
      <Link
        variant="muted"
        underline="hover"
        render={(props) => <a {...props} href="/components/link/#accessibility" />}
      >
        Activity log
      </Link>
    </Stack>
  );
}
```

Put `href`, `target`, and `rel` on the rendered element when that element owns the destination. Link still accepts those anchor props when it renders its own anchor. Base UI joins `className` and `style`, runs both event handlers, and merges refs. If you pass a function, spread its props argument onto your element so the classes, data attributes, and ref stay attached.

The component you render must forward its ref and the props it receives to a DOM node. Do not put another link or button inside it. Place the label in Link's children. If the rendered element already has children, those children are the visible label.

## External destinations

For links that open a new tab, use `target="_blank"` with the appropriate `rel` policy and make the destination change clear through the label, surrounding copy, or a trailing icon. `Link.Icon` is decorative, so do not rely on the icon alone to communicate that context. The same `target` and `rel` pairing applies when those props live on the element passed to `render`.

## Variants

default, muted, prose, subtle, contrary, underline: hover, underline: always, underline: none

## Sizes

sm, md, lg

## Anatomy

```text
Link
Link.Icon
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| variant | default \| muted \| prose \| subtle \| contrary | default | Treatment for standalone, secondary, inline prose, or inverse-surface navigation. Subtle is a compatibility alias for muted. |
| underline | hover \| always \| none | none | Optional underline behavior; hover also underlines on keyboard focus. Prose always stays underlined. |
| size | sm \| md \| lg | md | Body typography and composed SVG icon size. |
| render | ReactElement \| ((props, state) => ReactElement) | — | Composes Link styling onto another element, such as a router link. Base UI merges classes, styles, handlers, and refs. |
| Link.Icon | HTMLAttributes<HTMLSpanElement> | — | Decorative leading or trailing icon wrapper hidden from assistive technology. |
| native props | React.AnchorHTMLAttributes<HTMLAnchorElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

Link renders a native anchor by default and preserves `href`, `target`, `rel`, download, ARIA, event, and ref behavior. With `render`, that contract moves to the element you supply, which must forward props and its ref. Use text that describes the destination instead of generic phrases such as “click here.” The visible focus ring supplements, but does not replace, a meaningful accessible name. Prefer the persistently underlined `prose` variant when color alone would be the only cue inside body copy.

Source: https://zenos-ui.pages.dev/components/link/