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

# mds-header

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

The `<mds-header>` web component is the top-level page header container of the Magma Design System. It is a compound parent that wraps one or more `<mds-header-bar>` elements, orchestrating their scroll-driven appearance, auto-hide visibility, and an optional mobile menu rendered as a side modal.

#### Semantic Behavior

- **Compound parent**: Hosts `<mds-header-bar>` children in the default slot and relays its `menu` and `nav` settings down to the bar.
- **In the flow, and it stays put**: The header takes the room of its bar at the top of the page, so the page starts under it with no padding of its own, and it stays at the top of the window while the page scrolls (`position: sticky`, `surfaces/band` of the design language). The room is the bar alone, whatever the appearance: the floating bar (`'inline'`) stands its margin lower, over the space under the header, so the page never moves when `appearanceSet` changes the appearance. Sticky holds inside the box of the parent: place the header first in the element that holds the whole page (`body`, or the root of the application); an ancestor with `overflow: hidden` or `auto` that does not scroll the page stops it (`overflow: clip` does not).
- **Room for the focus**: While a header is on the page, the styles of Magma (`base.css`) stop a field reached with Shift+Tab under the bar, `rhythm/between-fields` lower (`scroll-padding-top`, WCAG 2.4.11), with no script that measures it: the bar is one row, its inset and a button. Content taller than a button (a logo over two lines of text) makes the bar taller than that room.
- **Clicks**: The box of the header takes no click, only its bar, its backdrop and its menu do: the space around the floating bar and where the bar was before auto-hide hid it leave the page under them usable.
- **Mobile menu**: A `[slot="menu"]` child is rendered inside a right-positioned modal. When it is absent there is no modal, and the bar receives `menu="none"` whatever `menu` says, so no hamburger shows that would open nothing.
- **Open/close control**: The menu modal is opened by the bar's hamburger or programmatically via the `setOpened()` method; when the user closes it, `mdsHeaderClose` is emitted (with the bound bar).
- **Scroll-driven appearance**: When `appearanceSet` names two appearances, `appearance` swaps between them as the page scrolls past its pixel threshold (300 when the third token is omitted).
- **Auto-hide on scroll**: When `autoHide` is set, scrolling down past that pixel offset hides the bar and scrolling up reveals it again, governed by `threshold` as the directional margin.
- **Visibility event**: Any change to `visibility` (`'visible'`/`'hidden'`) emits `mdsHeaderVisibilityChange`, whose `detail.visibility` is that string.

#### Properties & Visual Configurations

- **`appearance`** is the bar's current visual mode (`'stripe'` or `'inline'`) and is mutable because the component rewrites it as the page scrolls. `'inline'` floats the bar, at most as wide as the frame of the page (`--magma-width-page`) with its padding outside it, so on a wide window its content stays on the frame, as in `'stripe'`.
- **`appearanceSet`** is a space/comma-separated string declaring scroll behavior as three tokens: initial appearance, changed appearance, and the `scrollY` pixel threshold (e.g. `"stripe, inline 200"`). Use it instead of `appearance` when the header should transform on scroll; `appearance` alone keeps a fixed look.
- **`autoHide`** is the pixel offset past which the bar starts hiding on downward scroll; leave it unset to keep the bar always present.
- **`threshold`** tunes how many pixels of opposite-direction scroll are required to flip the auto-hide state - raise it to make hide/show less twitchy.
- **`menu`** and **`nav`** select on which viewports the hamburger menu and the navigation are shown (`'all'`, `'desktop'`, `'mobile'`, `'none'`); they are relayed to the child bar.
- **`hideBackdrop`** removes the blurred backdrop layer shown behind the bar when its appearance is `'inline'`.
- **`visibility`** reflects the current shown/hidden state of the bar and can be set to force it.

## 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-header--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 |
| --- | --- | --- | --- | --- |
| `appearance` | `appearance` | `string` | `'stripe'` | Sets the appearance of the header bar element when loaded, it can be changed depending on how `appearance-set` attribute is set |
| `appearanceSet` | `appearance-set` | `string \| undefined` | - | Sets the appearance of the header bar element depending on the scroll position: three values, the initial appearance, the appearance once scrolled and the `window.scrollY` threshold. `stripe, inline 200` starts with the stripe appearance and changes to inline once the page is scrolled more than 199 pixels |
| `autoHide` | `auto-hide` | `number \| undefined` | - | When the page is scrolled down, the component mds-header-bar is hidden starting from the `autoHide` attribute's value, then if the page is scrolled up it is shown again |
| `hideBackdrop` | `hide-backdrop` | `boolean \| undefined` | `false` | Hides the backdrop shown when the mds-header-bar attribute appearace is set to `inline` |
| `menu` | `menu` | `"all" \| "desktop" \| "mobile" \| "none"` | `'mobile'` | Sets the visibility type of the hamburger menu of mds-header-bar |
| `nav` | `nav` | `"all" \| "desktop" \| "mobile" \| "none"` | `'desktop'` | Sets the visibility type of the navigation menu of mds-header-bar |
| `threshold` | `threshold` | `number` | `1` | Sets the threshold margin to trigger hide or show status of the `mds-header-bar` when the page is scrolled |
| `visibility` | `visibility` | `"hidden" \| "visible" \| undefined` | `'visible'` | Sets the visibility type of the navigation menu of mds-header-bar |

## Events

| Event | Detail | Description |
| --- | --- | --- |
| `mdsHeaderClose` | `MdsHeaderEventDetail` | Emits when the component is closed |
| `mdsHeaderVisibilityChange` | `MdsHeaderVisibilityEventDetail` | Emits when the component mds-header-bar is shown or hidden |

## Methods

| Method | Signature | Description |
| --- | --- | --- |
| `setOpened` | `setOpened(isOpened?: boolean) => Promise<void>` | Opens or closes the header. |

## Slots

| Slot | Description |
| --- | --- |
| (default) | Add `mds-header-bar` element/s. |
| `menu` | Put actions and other contents that will be shown as mobile menu. Add `text string`, `HTML elements` or `components` to this slot. |

## Parts

| Part | Description |
| --- | --- |
| `menu` | The container element of the modal |

## CSS custom properties

| Property | Description |
| --- | --- |
| `--mds-header-backdrop-background-image` | Sets the background-image of the backdrop element visibile when the component attribute `appearance` is set to `inline`, by default is shown when mds-pref-consumtion is set to `medium` |
| `--mds-header-color` | Sets the text color of the header and the color of its icons, the hamburger toggler of `mds-header-bar` included |
| `--mds-header-inline-margin` | Sets inline margin of `the mds-header-bar` when attribute `appearance` is set to `inline` |
| `--mds-header-inline-margin-mobile` | Sets inline margin on mobile viewport of `the mds-header-bar` when attribute `appearance` is set to `inline` |
| `--mds-header-z-index` | Sets the z-index of the modal |

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

## Dependencies

Uses: `mds-modal`.
