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

# mds-text

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

The `<mds-text>` web component is the foundational typography primitive of the Magma Design System. It decouples the _semantic typography role_ of a piece of text from the _HTML element_ that renders it, replacing raw heading, paragraph, label and inline tags (`<h1>`-`<h6>`, `<p>`, `<span>`, `<label>`, `<code>`, ...) with a single design-tokenized text node that is consumed internally by nearly every other Magma component.

#### Semantic Behavior

- **Typography drives the rendered tag**: when `tag` is left unset, a sensible default element is resolved from the chosen `typography` (e.g. `typography="h2"` -> `<h2>`, `paragraph`/`detail` -> `<p>`, `label`/`option` -> `<label>`, `snippet`/`hack` -> `<code>`, `tip` -> `<div>`). Setting `tag` explicitly overrides this.
- **A title is written by its role**: `page`, `section`, `dialog`, `part` and `group` are the titles of the design language (`titles/page` and the others). Each takes the style of its role, the level the role is styled as (the title of a page is styled as `h3`, of a section and a dialog as `h5`, of a part and a group as `h6`), so a theme moves a role in one place. Left without `tag`, a role renders the tag of that level; the outline of the page sets the tag (`titles/tag-is-structure`), so the title of a page is `typography="page" tag="h1"`.
- **Semantics vs. visual style are independent**: `typography` controls the visual ramp and the default element, but you may pin any allowed `tag` to keep the correct document outline (accessibility) while choosing a different visual scale.
- **Text to read stops at the reading measure**: with the tag `p`, `li` or `figcaption` (`p` is the default of `detail` and `paragraph`) the host is capped at `max-w-text`, the reading measure (`--spacing-text`, `56ch`), as the reset caps the plain tags. The cap sits on the host, which carries the type style, so the `ch` is that of its own text; every other tag leaves the host as wide as its container.
- **Text source is slot or prop**: text is normally provided through the default slot. Passing the `text` prop renders that string instead of the slotted content - required for the animation path, since the animation watches the `text` value.
- **Default-slot is text only**: the default slot is intended for a plain text string; HTML elements or other components should not be slotted in. The one exception is `<mds-link>`, made to sit inside the text: it takes the font of the typography role and wraps with the words around it.
- **Animated reveal**: with `animation="yugop"` the component runs a randomized character "decode" reveal whenever the `text` prop changes after load (the initial value is rendered as is); `animation="none"` (the default) skips all animation. The revealed string is always painted as text, never parsed as HTML.
- **Animation tuning via CSS**: the yugop reveal reads `--mds-text-animation-speed` and `--mds-text-animation-placeholder-char`, so speed and placeholder glyph are themeable through CSS custom properties rather than props. They are read each time a reveal starts, so a value changed after load applies to the next reveal. The placeholder is one character (a longer string keeps its first one); a speed that is not a positive number, or an empty placeholder, falls back to the defaults (`0.5` and a space).

#### Properties & Visual Configurations

- **`typography`** selects the semantic text role from the shared typography ramp (titles `h1`-`h6` and `action`; informational `detail`, `paragraph`, `caption`, `label`, `option`, `tip`; monospaced `snippet`, `hack`) or, for a title, its role in the design language (`page`, `section`, `dialog`, `part`, `group`, values of `mds-text` only). It is the primary prop and also determines the default rendered tag. Defaults to `'detail'`.
- **`variant`** refines the _tone of a typography role_ and is specific to this component - it is the typography variation (`'title'`, `'info'`, `'read'`, `'code'`), not the shared component tone/variant ladder. Only `'read'` has a visual effect, and only on `paragraph`, `detail` and `caption` (it switches them to the reading family); the other values change nothing, and leaving it unset uses the role's default styling.
- **`tag`** is an escape hatch to force a specific HTML element independently of `typography`, e.g. rendering a visually large heading as a `<span>` or marking text as `<strong>`/`<em>`/`<mark>` without changing the visual scale.
- **`truncate`** governs overflow clipping: `'word'` forces single-line truncation (no wrapping), `'all'` clamps to a multi-line block whose line count is controlled by `--mds-text-line-clamp`, and `'none'` lets text flow normally. `'word'` and `'none'` clip only the end of the line, for the ellipsis, so the accents and the descenders of the `label` and `option` typographies (whose box is trimmed to the capitals) stay visible. `'all'` has to hide the lines after the clamp: the accents of its first line stay visible, while the descenders of its last visible line (a cedilla, the tail of a comma) are cut where the box ends.

## 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/design-typography--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 |
| --- | --- | --- | --- | --- |
| `animation` | `animation` | `"none" \| "yugop" \| undefined` | `'none'` | Specifies if the text is animated when it is rendered |
| `tag` | `tag` | `"abbr" \| "address" \| "article" \| "b" \| "bdo" \| "blockquote" \| "cite" \| "code" \| "dd" \| "del" \| "details" \| "dfn" \| "div" \| "dl" \| "dt" \| "em" \| "figcaption" \| "h1" \| "h2" \| "h3" \| "h4" \| "h5" \| "h6" \| "i" \| "ins" \| "kbd" \| "label" \| "legend" \| "li" \| "mark" \| "ol" \| "p" \| "pre" \| "q" \| "rb" \| "rt" \| "ruby" \| "s" \| "samp" \| "small" \| "span" \| "strong" \| "sub" \| "summary" \| "sup" \| "time" \| "u" \| "ul" \| "var"` | - | Specifies the HTML tag of the element. With `p`, `li` or `figcaption` the text stops at the reading measure (`max-w-text`), as the reset does for the plain tags |
| `text` | `text` | `string \| undefined` | - | Specifies the text string to the component instead of passing an HTML node |
| `truncate` | `truncate` | `"all" \| "none" \| "word" \| undefined` | - | Specifies if the text shoud be truncated or should behave as a normal text |
| `typography` | `typography` | `"action" \| "caption" \| "detail" \| "dialog" \| "group" \| "h1" \| "h2" \| "h3" \| "h4" \| "h5" \| "h6" \| "hack" \| "label" \| "option" \| "page" \| "paragraph" \| "part" \| "section" \| "snippet" \| "tip"` | `'detail'` | Specifies the font typography of the element. A title is written by its role (`page`, `section`, `dialog`, `part`, `group`), which takes the style of that role, and the tag of the level it is styled as unless `tag` gives the level of its place in the outline |
| `variant` | `variant` | `"code" \| "info" \| "read" \| "title" \| undefined` | - | Specifies the variant for `typography` |

## Slots

| Slot | Description |
| --- | --- |
| (default) | Add `text string` to this slot, **avoid** to add `HTML elements` or `components` here. |

## CSS custom properties

| Property | Description |
| --- | --- |
| `--mds-text-animation-placeholder-char` | Placeholder character used during text animation. |
| `--mds-text-animation-speed` | Speed of text animation. |
| `--mds-text-line-clamp` | Number of lines to clamp text to (line-clamp). |

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

## Dependencies

Used by: `mds-accordion-item`, `mds-accordion-timer-item`, `mds-badge`, `mds-banner`, `mds-benchmark-bar`, `mds-bibliography`, `mds-button`, `mds-chip`, `mds-file`, `mds-file-preview`, `mds-filter`, `mds-filter-item`, `mds-img`, `mds-input-date-range`, `mds-input-field`, `mds-input-range`, `mds-input-switch`, `mds-input-tip-item`, `mds-input-upload`, `mds-keyboard`, `mds-keyboard-key`, `mds-kpi-item`, `mds-label`, `mds-list-item`, `mds-mention`, `mds-notification`, `mds-paginator-item`, `mds-policy-ai`, `mds-pref`, `mds-pref-animation`, `mds-pref-consumption`, `mds-pref-contrast`, `mds-pref-language`, `mds-pref-mode`, `mds-pref-theme`, `mds-price-table-features`, `mds-price-table-features-cell`, `mds-price-table-list-item`, `mds-push-notification-item`, `mds-quote`, `mds-radial-progress`, `mds-status-bar`, `mds-stepper-bar-item`, `mds-tab-bar-item`, `mds-table`, `mds-table-header-cell`, `mds-toast`, `mds-tooltip`, `mds-url-view`, `mds-usage`.
