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

# mds-horizontal-scroll - examples

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

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

#### Basic Horizontal Scroll with Cards

The canonical form. Slot any fixed-width children directly into the component; it wraps them in a snap-scrolling viewport with a proportional dot indicator and arrow buttons automatically.

```html
<mds-horizontal-scroll>
  <mds-card class="min-w-[320px]">
    <mds-card-header>Servizio 1</mds-card-header>
    <mds-card-content>Descrizione del primo servizio.</mds-card-content>
  </mds-card>
  <mds-card class="min-w-[320px]">
    <mds-card-header>Servizio 2</mds-card-header>
    <mds-card-content>Descrizione del secondo servizio.</mds-card-content>
  </mds-card>
  <mds-card class="min-w-[320px]">
    <mds-card-header>Servizio 3</mds-card-header>
    <mds-card-content>Descrizione del terzo servizio.</mds-card-content>
  </mds-card>
</mds-horizontal-scroll>
```

#### Controlling Navigation Arrow Visibility

Use `controls` to restrict arrow buttons to specific viewport tiers. The value is the minimum breakpoint at which arrows appear - `'desktop'` (default) shows them only on desktop and above; `'all'` shows them at every viewport size; `'none'` suppresses them entirely.

```html
<!-- Arrows only on desktop and above (default) -->
<mds-horizontal-scroll controls="desktop">
  <!-- slotted items -->
</mds-horizontal-scroll>

<!-- Arrows on all viewports, including mobile -->
<mds-horizontal-scroll controls="all">
  <!-- slotted items -->
</mds-horizontal-scroll>

<!-- No arrows - touch / keyboard scroll only -->
<mds-horizontal-scroll controls="none">
  <!-- slotted items -->
</mds-horizontal-scroll>
```

#### Scroll Progress Indicator

Use `navigation` to choose the scroll-position affordance shown below the items. `'position'` (default) renders a proportional translating dot; `'scrollbar'` defers to the styled native browser scrollbar; `'none'` hides both.

```html
<!-- Dot indicator (default) -->
<mds-horizontal-scroll navigation="position">
  <!-- slotted items -->
</mds-horizontal-scroll>

<!-- Native scrollbar instead of dot -->
<mds-horizontal-scroll navigation="scrollbar">
  <!-- slotted items -->
</mds-horizontal-scroll>

<!-- No progress indicator -->
<mds-horizontal-scroll navigation="none">
  <!-- slotted items -->
</mds-horizontal-scroll>
```

#### Snap Alignment

`snap` controls how each item aligns to the viewport edge when the scroll settles. Use `'start'` (default) for left-aligned cards, `'center'` for centred carousels, `'end'` for right-aligned layouts, or `'none'` to allow free scrolling without snapping.

```html
<!-- Leading-edge alignment (default, most common) -->
<mds-horizontal-scroll snap="start">
  <!-- slotted items -->
</mds-horizontal-scroll>

<!-- Centred alignment - good for full-bleed hero carousels -->
<mds-horizontal-scroll snap="center">
  <!-- slotted items -->
</mds-horizontal-scroll>

<!-- Free scroll - no snapping -->
<mds-horizontal-scroll snap="none">
  <!-- slotted items -->
</mds-horizontal-scroll>
```

#### Combining Props for a Mobile-Friendly Carousel

Pair `controls="all"` with `snap="center"` and `navigation="position"` to produce a touch-and-arrow carousel that works at every breakpoint.

```html
<mds-horizontal-scroll controls="all" snap="center" navigation="position">
  <mds-card class="min-w-[280px]">
    <mds-card-media>
      <mds-img src="https://example.com/img1.jpg" alt=""></mds-img>
    </mds-card-media>
    <mds-card-content>
      <mds-text typography="h5">Categoria A</mds-text>
    </mds-card-content>
  </mds-card>
  <mds-card class="min-w-[280px]">
    <mds-card-media>
      <mds-img src="https://example.com/img2.jpg" alt=""></mds-img>
    </mds-card-media>
    <mds-card-content>
      <mds-text typography="h5">Categoria B</mds-text>
    </mds-card-content>
  </mds-card>
</mds-horizontal-scroll>
```

#### Styling Customization

Style the component only through its public `--mds-horizontal-scroll-*` CSS custom properties, which set its layout: the width of the items area and how far the controls sit outside it. Set them on the host or a parent selector. The dot indicator and the controls take their colours from the semantic roles, so they follow dark mode without overrides.

```css
.sezione-evidenza mds-horizontal-scroll {
  --mds-horizontal-scroll-max-width: 1200px;
}
```

#### Styling the Scrollbar

When `navigation="scrollbar"` is used, the component styles the native scrollbar itself, from the semantic color roles, so it follows dark mode; its size and colours have no public custom property. When the scrollbar does not suit the layout, pick another affordance with `navigation` instead of restyling it.

#### Customizing the Content Part

The inner scroll container is exposed as `::part(content)`. Use it sparingly - only when a CSS custom property cannot satisfy your requirement - to apply layout overrides without piercing undocumented internals.

```css
mds-horizontal-scroll::part(content) {
  padding-block: calc(var(--spacing) * 800);
}
```
