<!--
  GENERATED FILE - do not edit by hand.
  Source of truth: src/components/mds-badge/usage/ in the magma monorepo.
-->

# mds-badge - examples

> The API of this component: [`AGENTS.md`](AGENTS.md).

Correct and idiomatic ways to use the `<mds-badge>` component, ordered from most common to most specialized. The examples assume a working knowledge of the variant / tone ladders documented in [`agents/variants.md`](../../../../agents/variants.md) and the shared component rules in [`agents/conventions.md`](../../../../agents/conventions.md).

#### Basic Badge via `label` Prop

The canonical form. Use the `label` prop for the badge's text content - it is the preferred source and the slot is deprecated.

```html
<mds-badge label="Attivo" variant="success" tone="weak"></mds-badge>
```

#### Variant and Tone for Emphasis

Pair the same `variant` with a different `tone` to control visual weight. `tone="weak"` (default) is the lightest fill; `tone="strong"` is a saturated solid; `tone="outline"` adds a visible border with a transparent background.

```html
<!-- Low emphasis: subtle tinted fill (default) -->
<mds-badge label="Bozza" variant="warning" tone="weak"></mds-badge>

<!-- High emphasis: solid saturated fill -->
<mds-badge label="Urgente" variant="error" tone="strong"></mds-badge>

<!-- Minimal emphasis: bordered, no fill -->
<mds-badge label="Archiviato" variant="dark" tone="outline"></mds-badge>
```

#### Status Variants

Use status variants (`info`, `success`, `warning`, `error`) to communicate state. Match the variant to the meaning, not to the colour you want.

```html
<mds-badge label="Completato" variant="success" tone="weak"></mds-badge>
<mds-badge label="In attesa" variant="info" tone="weak"></mds-badge>
<mds-badge label="Attenzione" variant="warning" tone="weak"></mds-badge>
<mds-badge label="Errore" variant="error" tone="weak"></mds-badge>
```

#### Decorative Label Variants

Use decorative label variants (`green`, `blue`, `violet`, `red`, `orange`, `yellow`, `lime`, `aqua`, `sky`, `orchid`, `purple`, `amaranth`) for categorical tags, topics, or visual grouping that carries no semantic state meaning. The default variant is `green`.

```html
<mds-badge label="Ambiente" variant="green"></mds-badge>
<mds-badge label="Tecnologia" variant="blue"></mds-badge>
<mds-badge label="Design" variant="violet"></mds-badge>
<mds-badge label="Marketing" variant="orange"></mds-badge>
```

#### Neutral Variants

`variant="dark"` and `variant="light"` are painted with neutral roles that follow the mode, so neither is tied to a light or dark background. They differ only with `tone="strong"`: `dark` is the inverse chip (dark on a light UI, light on a dark UI), `light` is the paper of the mode (white in light, black in dark). With `weak` and `outline` the two render the same.

```html
<!-- Inverse chip, flips with the mode -->
<mds-badge label="Categoria" variant="dark" tone="strong"></mds-badge>

<!-- Paper of the mode -->
<mds-badge label="Categoria" variant="light" tone="strong"></mds-badge>
```

#### Typography Scale

The default `"option"` is the smaller scale and suits dense contexts such as table cells; use `typography="label"`, which is larger, when the badge needs more presence.

```html
<!-- Default, smaller scale - inside tables or tight UI rows -->
<mds-badge label="Nuovo" variant="sky" typography="option"></mds-badge>

<!-- Larger scale - standalone labels, cards, sidebars -->
<mds-badge label="Nuovo" variant="sky" typography="label"></mds-badge>
```

#### Badge Inside a Table Cell

`<mds-badge>` is commonly used as a status indicator inside [`mds-table`](../mds-table/AGENTS.md) cells.

```html
<mds-table>
  <mds-table-body>
    <mds-table-row>
      <mds-table-cell>
        <mds-badge label="Approvato" variant="success" tone="weak"></mds-badge>
      </mds-table-cell>
      <mds-table-cell>
        <mds-badge label="In revisione" variant="warning" tone="weak"></mds-badge>
      </mds-table-cell>
    </mds-table-row>
  </mds-table-body>
</mds-table>
```

#### Badge Inside a File Listing

[`mds-file`](../mds-file/AGENTS.md) and [`mds-file-preview`](../mds-file-preview/AGENTS.md) render a badge internally to show the file type; you do not slot a badge into them. When adding a badge alongside file content elsewhere, compose it in the surrounding markup.

```html
<div class="file-meta">
  <mds-file filename="relazione-2024.pdf"></mds-file>
  <mds-badge label="Firmato" variant="success" tone="weak"></mds-badge>
</div>
```

#### Styling Customization

Style the badge only through its public `--mds-badge-*` CSS custom properties. Use Magma color tokens via `rgb(var(--<token>))` so dark mode and high-contrast modes keep working.

```css
.custom-tag mds-badge {
  --mds-badge-background: rgb(var(--label-orchid-09));
  --mds-badge-color: rgb(var(--label-orchid-02));
}
```

For `tone="outline"`, the border is not a public custom property: its color follows the `variant` prop. The outline badge is always transparent, so `--mds-badge-background` has no effect on it:

```html
<mds-badge label="Archiviato" variant="orchid" tone="outline"></mds-badge>
```
