<!--
  GENERATED FILE - do not edit by hand.
  Source of truth: src/components/mds-link/ in the magma monorepo (usage/*.md and the
  component's JSDoc). Regenerated on every stencil build (scripts/component-docs.ts).
-->

# mds-link

> `@maggioli-design-system/magma` 2.15.0. Shadow DOM: style it only through the public CSS custom properties and the parts below.

The `<mds-link>` web component is the inline link of Magma: a word or a phrase inside running text, usually inside an `<mds-text>`, that opens a URL or runs an inline action. It replaces a raw `<a>` styled by hand, so links look and behave the same in every app, focus ring included.

#### Semantic Behavior

- **A word of the sentence**: the host is inline and has no typography of its own. It takes the font of the text around it (family, size, weight, line height, letter spacing), whatever the `typography` of the `<mds-text>` it sits in, and wraps across lines with the rest of the text.
- **A real anchor with `href`**: the link is an `<a href>` in the shadow root, and it is the element that takes the focus. The browser gives it what it gives every link: a new tab on a modifier or middle click, the context menu, drag. A click listener on the host can cancel the navigation with `preventDefault()`, and a client-side router registered with `NavigationService.setHandler()` (from `@maggioli-design-system/magma/services`) takes the plain clicks over. A `click()` from a script follows the link too, unless a listener cancels it.
- **An inline button without `href`**: the link becomes an element with `role="button"` in the tab order; a click, Enter and Space each fire one native `click` on the host. It never submits the form it sits in. It is not a native `<button>`, which cannot wrap across lines.
- **New tab**: `target="blank"` opens the URL in a new tab without giving it access to the page (`rel="noopener noreferrer"`) and adds a hidden "(opens in a new tab)", in the language of the page, to the name the assistive technology reads. No icon is added: pick one with `icon` if the design wants it.
- **Download**: `download` saves the file of `href` instead of opening it, as on a native `<a download>`: with no value the file keeps the name the server gives it, a value names the saved file. A file the browser can show (JSON, XML, a PDF) opens in the tab without it. Browsers apply it to the URLs of the origin of the page, `blob:` and `data:` only: a link to another origin opens the file. A download never goes to the router: the browser saves the file on a click, on Enter and on the `click()` of a script.
- **Icon**: `icon` draws an icon, hidden from the assistive technology, sized on a step of the spacing scale, the same in every typography. It stays on the line of the word next to it: it never wraps to a line of its own.
- **Underline always visible**: the underline is what tells the link from the text without its color (WCAG 1.4.1), so every style keeps one, and its weight never changes. Under the pointer every link fills with a faint background that rises from the bottom, and a `weak` one also gives its line the whole color; under high contrast the tints take the full color.

#### Properties & Visual Configurations

- **`href`** decides what the link is: with it, a link to a page; without it, an inline action that the host's `click` listener runs. Navigation always goes through `href`, never through a click handler that changes the location.
- **`label`** sets the text of the link; without it the link shows its default slot, which is the usual form in running text.
- **`variant`** sets the color: `primary` (the default) paints the link with the accent, the color of links and actions on a neutral surface; `inherit` takes the color of the text around it, for a link on a colored surface (a status message, a filled banner), where the accent would lose contrast.
- **`underline`** sets the style of the underline:
  - `solid` (the default): a thin line;
  - `dotted`: a dotted line;
  - `marker`: a tinted band under the text, lighter with `weak`, which rises under the pointer to fill the line like a highlighter, with the same faint background in both tones.
- **`tone`** sets how much of the color the line takes: `strong` (the default) the whole color; `weak` a light tint of it, which steps back in a text dense with links and takes the whole color under the pointer. The text of the link keeps the whole color in both tones.
- **`icon-position`** puts the icon after the text (`right`, the default: an external link, a download, a forward arrow) or before it (`left`: a back arrow).

## Read next

- [`examples.md`](examples.md) - correct usage, from the most common case
- [`mistakes.md`](mistakes.md) - the wrong forms, each with the right one
- [Storybook](https://magma-design-system.github.io/magma/storybook/?path=/docs/ui-link--docs) - the live examples, in the published Storybook of `main`
- [`conventions.md`](../../../../agents/conventions.md), [`variants.md`](../../../../agents/variants.md), [`mistakes.md`](../../../../agents/mistakes.md) - the rules shared by every component

## Props

| Prop | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `download` | `download` | `boolean \| string \| undefined` | - | Saves the file of `href` instead of opening it, as the `download` attribute of `<a>`: present with no value, or `true`, the file takes the name the server gives it; a string is the name of the saved file. Browsers apply it to the URLs of the origin of the page, `blob:` and `data:`: a link to another origin opens the file as without it. A download never goes to the router registered with `NavigationService` |
| `href` | `href` | `string \| undefined` | - | The URL of the link: a real anchor in its shadow root, so the browser gives it what it gives every link (new tab on a modifier or middle click, the context menu, drag). A client-side router takes the plain clicks over once registered with `NavigationService.setHandler()` (from `@maggioli-design-system/magma/services`); without one, a click listener on the host can still cancel the navigation with `preventDefault()`. Without `href` the link is an inline button: it answers to click, Enter and Space with a `click` event and never submits a form. |
| `icon` | `icon` | `string \| undefined` | - | The icon displayed in the link |
| `iconPosition` | `icon-position` | `"left" \| "right" \| undefined` | `'right'` | Specifies the horizontal position of the icon, which never wraps to a line of its own |
| `label` | `label` | `string \| undefined` | - | The text of the link; without it, the text of the default slot |
| `target` | `target` | `"blank" \| "self"` | `'self'` | Specifies the target of the URL, if self or blank: blank opens a new tab, without giving it access to the page (`rel="noopener noreferrer"`), and tells the assistive technology so |
| `tone` | `tone` | `"strong" \| "weak" \| undefined` | `'strong'` | Specifies the tone of the underline: `strong` draws it in the color of the link, `weak` in a tint of it, which takes the full color under the pointer |
| `underline` | `underline` | `"dotted" \| "marker" \| "solid" \| undefined` | `'solid'` | Specifies the style of the underline, which is always visible |
| `variant` | `variant` | `"inherit" \| "primary" \| undefined` | `'primary'` | Specifies the color of the link: `primary` paints it with the accent, `inherit` takes the color of the text around it, for a link on a colored surface |

## Slots

| Slot | Description |
| --- | --- |
| (default) | Add `text string` to this slot, the text of the link when `label` is not set; **avoid** to add `HTML elements` or `components` here. |

## Parts

| Part | Description |
| --- | --- |
| `icon` | The icon of the link |
| `link` | The element that carries the link and the focus: an anchor with `href`, an inline button without it |

## CSS custom properties

| Property | Description |
| --- | --- |
| `--mds-link-color` | The color of the text, the underline and the icon of the link. |

Only these are public. Its other 7 are internal: they may change in any release, do not set them.

## Dependencies

Uses: `mds-icon`.
