# Link

A styled anchor for navigation in running text, lists and footers. It marks external links, secures new-tab links and tells screen-reader users when a link opens a new tab; use `vig-button` with an `href` when navigation should look like an action.

- Package: [@vigdx/ui](https://www.npmjs.com/package/@vigdx/ui)
- Selectors: `vig-link`
- Source: [libs/ui/src/lib/atoms/link/link.ts](https://github.com/bakyurekk/vigdx/blob/main/libs/ui/src/lib/atoms/link/link.ts)

```typescript title="Import"
import { Link } from '@vigdx/ui/link';
```

## Basic

Wrap the link text in `vig-link` and pass an `href`. The link takes the font size of the surrounding text.

```typescript title="link-basic.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Link } from '@vigdx/ui/link';

@Component({
  selector: 'app-link-basic',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Link],
  template: `
    <p class="max-w-prose text-sm text-foreground">
      Refunds are processed within five working days. Read the
      <vig-link href="/help/refunds">refund policy</vig-link> or
      <vig-link href="/help/contact">contact support</vig-link> if a payment is missing.
    </p>
  `,
})
export class LinkBasicDemo {}
```

## Variants

`variant` is `default` (link color), `muted` (soft until hovered) or `inherit`, which takes the color of its context, e.g. inside an error message.

```typescript title="link-variants.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Link } from '@vigdx/ui/link';

@Component({
  selector: 'app-link-variants',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Link],
  template: `
    <div class="flex flex-col gap-3 text-sm">
      <p class="text-foreground">
        <vig-link href="/settings/billing">Billing settings</vig-link> — default, in the link color.
      </p>
      <p class="text-foreground">
        <vig-link href="/terms" variant="muted">Terms of service</vig-link> — muted, for secondary
        navigation such as footers.
      </p>
      <p class="text-error">
        Your card was declined.
        <vig-link href="/settings/billing" variant="inherit">Update payment method</vig-link>
      </p>
    </div>
  `,
})
export class LinkVariantsDemo {}
```

## Underline

`underline` is `always` (default), `hover` or `none`. Keep links in running text underlined so they do not rely on color alone.

```typescript title="link-underline.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Link } from '@vigdx/ui/link';

@Component({
  selector: 'app-link-underline',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Link],
  template: `
    <div class="flex flex-wrap items-center gap-6 text-sm">
      <vig-link href="/docs" underline="always">Always underlined</vig-link>
      <vig-link href="/docs" underline="hover">Underlined on hover</vig-link>
      <vig-link href="/docs" underline="none" variant="muted">Never underlined</vig-link>
    </div>
  `,
})
export class LinkUnderlineDemo {}
```

## External links

`external` appends an icon and opens in a new tab unless `target` is set. Every `target="_blank"` link gets `rel="noopener noreferrer"` and a screen-reader note, translatable with `newTabAriaLabel`.

```typescript title="link-external.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Link } from '@vigdx/ui/link';

@Component({
  selector: 'app-link-external',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Link],
  template: `
    <ul class="flex flex-col gap-3 text-sm">
      <li><vig-link href="https://angular.dev" external>Angular documentation</vig-link></li>
      <li>
        <vig-link href="https://tailwindcss.com/docs" target="_blank">
          Tailwind CSS docs (new tab, no icon)
        </vig-link>
      </li>
      <li>
        <vig-link
          href="https://developer.mozilla.org/de/"
          external
          newTabAriaLabel="(öffnet in einem neuen Tab)"
        >
          MDN auf Deutsch
        </vig-link>
      </li>
    </ul>
  `,
})
export class LinkExternalDemo {}
```

## Disabled

`disabled` removes the `href`, so the link cannot be followed and leaves the tab order, and greys it out.

```typescript title="link-disabled.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Link } from '@vigdx/ui/link';

@Component({
  selector: 'app-link-disabled',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Link],
  template: `
    <p class="text-sm text-foreground">
      <vig-link href="/reports/2026-q3.pdf" disabled>Download Q3 report</vig-link>
      <span class="text-muted-foreground"> — available once the quarter is closed.</span>
    </p>
  `,
})
export class LinkDisabledDemo {}
```

## Styling hooks

Internal elements carry a stable `data-part` and the component's `data-scope`; both are public API, so removing one is a breaking change. Select a part by both, e.g. `[data-scope="link"][data-part="anchor"] { … }`: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through `aria-*` and, where listed, a `data-state`; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other `data-*` attributes listed below (such as `data-opening` while an overlay animates) are API too. See [Customizing](https://vigdx.com/docs/theming.md#customizing).

Scope: `[data-scope="link"]`

| Part | Element | data-state |
| --- | --- | --- |
| `anchor` | The native `<a>`. |   |
| `icon` | The external-link icon (`external`). |   |
| `new-tab` | Screen-reader text for links that open a new tab. |   |

## Accessibility

- Renders a native `<a href>`, announced as a link and followed with Enter. The projected text is its accessible name, so make it meaningful out of context and avoid “click here”.
- Links opening a new tab carry visually hidden text (the `linkNewTabLabel` label, or `newTabAriaLabel` per instance) so the change of context is announced.
- A disabled link keeps `role="link"` with `aria-disabled="true"` but has no `href`, so the Tab key skips it.
- Focus shows the `--shadow-focus-ring` halo; the default and muted colors meet WCAG AA against the page background in light and dark mode.

## API

### Link

Selector: `vig-link` · Kind: component

Styled anchor. `target="_blank"` gets `rel="noopener noreferrer"` automatically; `external` opens in a new tab by default and appends an icon plus screen-reader text saying so. `disabled` removes the `href`.

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `disabled` | `boolean` | `false` | Renders a non-interactive link (`aria-disabled`, no `href`). |
| `external` | `boolean` | `false` | Marks an off-site link: appends an icon and opens in a new tab unless `target` is set. |
| `href` | `string \| undefined` | `undefined` | — |
| `newTabAriaLabel` | `string \| undefined` | `undefined` | Screen-reader note for new-tab links; defaults to the `linkNewTabLabel` label. |
| `newTabLabel` | `string \| undefined` | `undefined` | **Deprecated**: Use `newTabAriaLabel`; still honored when `newTabAriaLabel` is unset. |
| `rel` | `string \| undefined` | `undefined` | Extra `rel` tokens, merged with `noopener noreferrer` for `_blank`. |
| `target` | `string \| undefined` | `undefined` | Browsing context; `external` links default to `_blank`. |
| `underline` | `LinkUnderline` | `'always'` | — |
| `variant` | `LinkVariant` | `'default'` | — |
