# Link

> Renders an accessible and themeable anchor link for navigation. Use this to direct users to other pages or external websites.

Source: https://vaneui.com/docs/typography-components/link

Import: `import { Link, Col, PageTitle, Row, SectionTitle, Text, ThemeProvider, Title } from "@vaneui/ui"`

Use Link for inline links in running text, footers and help copy. When it opens a new tab through `external` or `target="_blank"`, it appends a visually hidden "(opens in new window)" note for screen readers, unless an `aria-label` is set. For navigation in a sidebar or header, use [NavLink](/docs/basic-components/navlink); for a call to action styled as a button, use [Button](/docs/basic-components/button), which also renders `<a>` when given `href`.

## Basic usage

Link renders a styled anchor element for navigation. Unlike other typography components which default to `inheritAppearance`, Link renders its blue link color by default (no explicit appearance) with `underline`, and ships with `focusVisible` on for a keyboard focus outline.

```tsx demo
<Link href="#">Click here to learn more</Link>
```

## Appearances

Links render their blue link color by default. Set an explicit appearance to override: `primary`, `accent`, `secondary`, `tertiary`, `success`, `danger`, `warning`, `info`.

```tsx demo
<Row flexWrap>
  <Link primary href="#">Primary</Link>
  <Link accent href="#">Accent</Link>
  <Link secondary href="#">Secondary</Link>
  <Link success href="#">Success</Link>
  <Link danger href="#">Danger</Link>
  <Link warning href="#">Warning</Link>
  <Link info href="#">Info</Link>
</Row>
```

## Variants

Link renders its own link colour rather than an appearance by default. Like all typography, Link is background-less: `filled` paints no surface behind it, and with an explicit appearance the text colour matches `outline`.

```tsx demo
<Row flexWrap itemsCenter>
  <Link href="#">outline, the default</Link>
  <Link filled info href="#">filled info</Link>
  <Link filled success href="#">filled success</Link>
</Row>
```

## Size inherits from context

Link defaults to `inheritSize: true` so a link inside a heading renders at the heading's font-size automatically. No `size` prop needed. The link keeps its own blue colour.

```tsx demo
<Col>
  <Text>Body text with a <Link href="#">link inline</Link>.</Text>
  <Title>Subheading with a <Link href="#">link</Link> inside.</Title>
  <SectionTitle>Section heading with a <Link href="#">link</Link>.</SectionTitle>
  <PageTitle>Page title <Link href="#">link</Link></PageTitle>
</Col>
```

## Fixed size with noInheritSize

Pass `noInheritSize` to render the Link at its own size instead of the parent's, useful when a link inside a heading should stay at body-text size.

```tsx demo
<Title>
  Subheading with <Link href="#" noInheritSize>a fixed-size link</Link> mid-sentence.
</Title>
```

## Explicit sizes

An explicit size, `xs`, `sm`, `md` (default), `lg` or `xl`, renders the Link at that size instead of the parent's. Pass `inheritSize` alongside it to keep following the parent.

```tsx demo
<Col>
  <Link href="#" xs>Extra small link</Link>
  <Link href="#" sm>Small link</Link>
  <Link href="#" md>Medium link</Link>
  <Link href="#" lg>Large link</Link>
  <Link href="#" xl>Extra large link</Link>
</Col>
```

## Styling

Use `fontBold`, `fontSemibold`, or `italic` for emphasis, or `noUnderline` to remove the default underline.

```tsx demo
<Col>
  <Link fontBold href="#">Bold link</Link>
  <Link fontSemibold href="#">Semibold link</Link>
  <Link italic href="#">Italic link</Link>
  <Link noUnderline href="#">Link without underline</Link>
</Col>
```

## Hover state

Links keep an underline at rest. With `noUnderline`, the underline appears on hover for affordance. Links also render a keyboard focus-visible outline by default for keyboard users (opt out with `noFocusVisible`).

```tsx demo
<Col>
  <Link href="#">Underlined at rest, stays underlined on hover</Link>
  <Link noUnderline href="#">No underline at rest, hover to reveal it</Link>
</Col>
```

## External links

Pass the `external` prop and Link auto-applies `target="_blank"` and `rel="noopener noreferrer"` for safe cross-origin navigation.

```tsx demo
<Link href="https://github.com/vaneui/vaneui" external>VaneUI on GitHub</Link>
```

## Manual target="_blank"

Setting `target="_blank"` directly also auto-applies `rel="noopener noreferrer"`. No need to spell it out.

```tsx demo
<Link href="https://github.com/vaneui/vaneui" target="_blank">Open in a new tab</Link>
```

## Inline in Text

Links integrate naturally with surrounding prose. Drop them inline inside `Text` and they inherit the parent size.

```tsx demo
<Text>
  Check out our <Link href="#">documentation</Link> to learn more about the features.
  You can also visit the <Link href="#">GitHub repository</Link> for source code.
</Text>
```

Link is inline, so `marginT`, `marginB`, and `marginY` have no visual effect. Use `marginX` for inline-side spacing, or `className` for an exact value.

## Inherits parent Text size

Links inside body text inherit the surrounding `Text` size. Set the size on the parent and the Link follows along.

```tsx demo
<Col>
  <Text sm>Read the <Link href="#">terms and conditions</Link> before proceeding.</Text>
  <Text>Visit our <Link href="#">help center</Link> for more information.</Text>
  <Text lg>Check out the <Link href="#">getting started guide</Link> to begin.</Text>
</Col>
```

## With icons

Combine links with icons using Row for visual navigation cues.

```tsx demo
<Col>
  <Row itemsCenter>
    <ExternalLink size={14} />
    <Link href="#">Open in new window</Link>
  </Row>
  <Row itemsCenter>
    <FileText size={14} />
    <Link href="#">View documentation</Link>
  </Row>
  <Row itemsCenter>
    <GitHub size={14} />
    <Link href="#">Source on GitHub</Link>
  </Row>
</Col>
```

## Next.js Link integration

Use the `tag` prop to render the VaneUI Link as a Next.js `Link` for client-side navigation. Alias the Next.js import so it doesn't shadow `Link` from `@vaneui/ui`.

```tsx
import NextLink from 'next/link';
import { Link } from '@vaneui/ui';

<Link href="/docs" tag={NextLink}>Documentation</Link>
```

## Customizing

Set app-wide Link defaults with `ThemeProvider`'s `themeDefaults`:

```tsx demo
<ThemeProvider themeDefaults={{
  link: { info: true, noUnderline: true },
}}>
  <Link href="/docs">Read more</Link>
</ThemeProvider>
```

## Frequently asked questions

### How do I change the link color across the site?

Re-declare the `--color-text-link` token, which every Link without an appearance reads. For a site with dark mode, set it as a `light-dark()` pair on the `data-theme` elements and the light value on `:root`, as described under [Changing a color in both schemes](/docs/customization/dark-mode#changing-a-color-in-both-schemes). To give every link an appearance color instead, use `themeDefaults={{ link: { info: true } }}`, as under [Customizing](#customizing).

### How do I disable a Link?

Pass `disabled`. An `<a>` has no native disabled state, so Link removes the `href`, blocks clicks and `Enter`, and sets `aria-disabled="true"`. The link stays focusable, so a screen reader user still finds it and hears that it is unavailable. Say near the link why it is disabled, since a disabled link gives no reason of its own.

### Why is my Link in a different font from the text around it?

Link is `fontSans` by default, so inside a `Text` with `fontSerif` or `fontMono`, or a heading whose `--font-heading` names another font, it switches to the sans font. Give the Link the same font prop as its parent, such as `fontMono` or `fontHeading`, or set that font on the `link` node in `themeDefaults` to change every Link.

## Props

| Prop | Category | Default | Description |
| --- | --- | --- | --- |
| `primary` | Appearance |  | Primary color appearance (gray) |
| `accent` | Appearance |  | Accent color appearance (rose) |
| `secondary` | Appearance |  | Secondary color appearance (gray) |
| `tertiary` | Appearance |  | Tertiary color appearance |
| `success` | Appearance |  | Success color appearance (green) |
| `danger` | Appearance |  | Danger color appearance (red) |
| `warning` | Appearance |  | Warning color appearance (amber) |
| `info` | Appearance |  | Info color appearance (cyan) |
| `inheritAppearance` | Appearance |  | Inherit appearance from parent — suppresses own data-appearance/data-variant, uses parent's CSS variables |
| `disabled` | Disabled |  | Disable the component — reduces opacity, changes cursor to not-allowed, and prevents interaction |
| `fontSans` | Font Family | yes | Sans-serif font family (default) — emits font-sans |
| `fontSerif` | Font Family |  | Serif font family — emits font-serif |
| `fontMono` | Font Family |  | Monospace font family — emits font-mono |
| `fontHeading` | Font Family |  | Heading font family (defaults to sans, customizable via --font-heading) — emits font-heading |
| `italic` | Font Style |  | Italic font style |
| `notItalic` | Font Style |  | Not italic (normal) font style |
| `fontThin` | Font Weight |  | Thin font weight (100) — emits font-thin |
| `fontExtralight` | Font Weight |  | Extra light font weight (200) — emits font-extralight |
| `fontLight` | Font Weight |  | Light font weight (300) — emits font-light |
| `fontNormal` | Font Weight |  | Normal font weight (400) — emits font-normal |
| `fontMedium` | Font Weight |  | Medium font weight (500) — emits font-medium |
| `fontSemibold` | Font Weight |  | Semibold font weight (600) — emits font-semibold |
| `fontBold` | Font Weight |  | Bold font weight (700) — emits font-bold |
| `fontExtrabold` | Font Weight |  | Extra bold font weight (800) — emits font-extrabold |
| `fontBlack` | Font Weight |  | Black font weight (900) — emits font-black |
| `inheritColor` | Inherit Color |  | Inherit text color from parent via CSS variable cascade (suppresses data-appearance emission) |
| `noInheritColor` | Inherit Color |  | Keep own text color; do not inherit from parent |
| `inheritSize` | Inherit Size | yes | Inherit font-size and line-height from the nearest parent typography element |
| `noInheritSize` | Inherit Size |  | Keep own font-size; do not inherit from parent |
| `trackingTighter` | Letter Spacing |  | Tighter letter spacing (-0.05em) |
| `trackingTight` | Letter Spacing |  | Tight letter spacing (-0.025em) |
| `trackingNormal` | Letter Spacing |  | Normal letter spacing (0) |
| `trackingWide` | Letter Spacing |  | Wide letter spacing (0.025em) |
| `trackingWider` | Letter Spacing |  | Wider letter spacing (0.05em) |
| `trackingWidest` | Letter Spacing |  | Widest letter spacing (0.1em) |
| `margin` | Margin |  | Enable margin on all sides |
| `marginX` | Margin |  | Enable only horizontal (inline) margin |
| `marginY` | Margin |  | Enable only vertical (block) margin |
| `marginT` | Margin |  | Enable only top margin |
| `marginB` | Margin |  | Enable only bottom margin |
| `noMargin` | Margin |  | Disable margin (reset to 0) |
| `xs` | Size |  | Extra small size |
| `sm` | Size |  | Small size |
| `md` | Size | yes | Medium size (default) |
| `lg` | Size |  | Large size |
| `xl` | Size |  | Extra large size |
| `skeleton` | Skeleton |  | Show the component as a loading placeholder in its own size and shape. On a container, every component inside it becomes a placeholder too |
| `srOnly` | Sr Only |  | Hide visually and keep it for screen readers (sr-only) |
| `textLeft` | Text Align |  | Align text to left (physical side, does not flip under RTL) |
| `textCenter` | Text Align |  | Align text to center |
| `textRight` | Text Align |  | Align text to right (physical side, does not flip under RTL) |
| `textJustify` | Text Align |  | Justify text |
| `textStart` | Text Align |  | Align text to the reading-direction start (left in LTR, right in RTL) |
| `textEnd` | Text Align |  | Align text to the reading-direction end (right in LTR, left in RTL) |
| `underline` | Text Decoration | yes | Add underline decoration below text |
| `lineThrough` | Text Decoration |  | Add strikethrough/line-through decoration across text |
| `noUnderline` | Text Decoration |  | Remove ALL text-decoration — underline, line-through, and overline (text-decoration: none) |
| `overline` | Text Decoration |  | Add overline decoration above text |
| `uppercase` | Text Transform |  | Transform text to uppercase |
| `lowercase` | Text Transform |  | Transform text to lowercase |
| `capitalize` | Text Transform |  | Capitalize first letter of each word |
| `normalCase` | Text Transform |  | Normal text case (no transformation) |
| `truncate` | Truncate |  | Single line truncation with ellipsis |
| `lineClamp2` | Truncate |  | Truncate at 2 lines with ellipsis |
| `lineClamp3` | Truncate |  | Truncate at 3 lines with ellipsis |
| `lineClamp4` | Truncate |  | Truncate at 4 lines with ellipsis |
| `lineClamp5` | Truncate |  | Truncate at 5 lines with ellipsis |
| `noTruncate` | Truncate |  | Remove truncation |
| `filled` | Variant |  | Filled variant - solid background with contrasting text color |
| `outline` | Variant |  | Outline variant - transparent background with border and colored text (default) |
| `ghost` | Variant |  | Ghost variant - transparent background, no border, appearance-colored text, tinted hover background |
| `breakNormal` | Word Break |  | Reset breaking - overflow-wrap and word-break normal |
| `breakWords` | Word Break |  | Break long words to prevent overflow - overflow-wrap: break-word |
| `breakAll` | Word Break |  | Break between any two characters - word-break: break-all |
| `breakKeep` | Word Break |  | Do not break CJK text - word-break: keep-all |

Layout and utility props (Cursor, Display, Focus Visible, Height, Hide, Items, Justify, Overflow, Position, Responsive Sizing, Responsive Width, Show, Whitespace, Width) are listed on [Common Props](https://vaneui.com/docs/reference/common-props.md).
