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

# mds-pref-contrast

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

The `<mds-pref-contrast>` web component is a preference control that lets users switch the application's contrast mode (`more`, `system`, or `no-preference`). It is usually a child of the [`<mds-pref>`](../mds-pref/AGENTS.md) panel and renders as a segmented tab of icon options rather than any single native HTML primitive.

#### Semantic Behavior

- **Usually inside `<mds-pref>`**: It is designed to be placed as a direct slot child of `<mds-pref>` alongside the other preference children (`mds-pref-animation`, `mds-pref-consumption`, `mds-pref-language`, `mds-pref-mode`, `mds-pref-theme`); it also works on its own, since it applies and stores the preference by itself.
- **Mode resolution on load**: The active mode is resolved once, on load, in order from the `mode` prop, the persisted value, then the `system` default, and applied immediately - so it acts on the document even before any user interaction.
- **Applies the preference globally**: Selecting a mode applies it across the whole document and persists the choice.
- **System resolution**: With `system` the component writes `pref-contrast-system` on `<html>`, and the styles follow the OS `prefers-contrast` setting through their own media query; the component does not map the OS value itself.
- **Change event**: Every mode change emits `mdsPrefChange` with `{ preference: 'contrast' }`, once the new mode is applied; a pick of the mode already active and the first application on load do not emit it. It bubbles up to `<mds-pref>`; a contrast change needs no reload, so it raises no reload notice.
- **Instances stay in sync**: Instances mounted together (a hidden `<mds-pref controller>` and a visible settings panel) share the applied contrast: a pick in one is mirrored by the others, which neither apply it again nor emit `mdsPrefChange`. A `pref-contrast-*` class written on `<html>` by other code is mirrored the same way.

#### Properties & Visual Configurations

- **`mode`** - the active contrast preference. Leave it unset to let the component restore the last persisted choice or fall back to `system`; set it explicitly (`more`, `system`, `no-preference`) only when the host wants to force a contrast level. Pick `more` for high-contrast output, `no-preference` for the default theme, and `system` to defer to the OS `prefers-contrast` setting.
- **`size`** - sizes the nested tab items (`sm` / `md`). Inside `<mds-pref>`, set it on the parent instead: the parent's `size` reaches every `mds-pref-*` child on load and when it changes, and overwrites the child's own.

The component does not use the shared `variant` / `tone` ladders documented in [`agents/variants.md`](../../../../agents/variants.md); its visual states are driven entirely by the resolved `mode`.

## 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-preferences-contrast--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 |
| --- | --- | --- | --- | --- |
| `mode` | `mode` | `"more" \| "no-preference" \| "system" \| undefined` | - | Specifies the preference mode |
| `size` | `size` | `"md" \| "sm" \| undefined` | - | Sets the size of the component items nested inside it |

## Events

| Event | Detail | Description |
| --- | --- | --- |
| `mdsPrefChange` | `MdsPrefChangeEventDetail` | Emits when the component is triggered |

## Dependencies

Uses: `mds-text`, `mds-tab`, `mds-tab-item`.
