탐색

v2.1.0
미디어

캐러셀

CSS만으로 구현한 스크롤 및 스냅 방식의 가로 또는 세로 슬라이드 목록입니다.

이 페이지의 내용

캐러셀은 가로 또는 세로로 나열된 슬라이드를 스크롤하고 스냅하는 컴포넌트입니다. CSS만으로 구현하며, 트랙은 스크롤 스냅이 적용된 스크롤 컨테이너입니다. 따라서 터치, 트랙패드, 키보드, 보조 기술로 일반 스크롤 영역과 같은 방식으로 조작할 수 있습니다. 브라우저가 지원하는 경우 스타일시트는 이전·다음 버튼과 슬라이드별 점을 추가합니다. 브라우저는 이를 포커스할 수 있는 실제 컨트롤로 생성합니다.

캐러셀

<div class="carousel" role="region" aria-label="Featured projects" tabindex="0">  <article class="carousel-slide card card-flat">    <header class="card-header">      <h3 class="card-title">Atlas</h3>      <p class="card-description">A map of every deployment, live.</p>    </header>    <div class="card-body">1.28M requests in the last 24 hours.</div>  </article>  <article class="carousel-slide card card-flat">    <header class="card-header">      <h3 class="card-title">Borealis</h3>      <p class="card-description">Edge functions close to the reader.</p>    </header>    <div class="card-body">Served from 14 regions.</div>  </article>  <article class="carousel-slide card card-flat">    <header class="card-header">      <h3 class="card-title">Cirrus</h3>      <p class="card-description">Storage that follows the project.</p>    </header>    <div class="card-body">7.4 of 10 GB in use.</div>  </article></div>
<div className="carousel" role="region" aria-label="Featured projects" tabIndex={0}>  <article className="carousel-slide card card-flat">    <header className="card-header">      <h3 className="card-title">Atlas</h3>      <p className="card-description">A map of every deployment, live.</p>    </header>    <div className="card-body">1.28M requests in the last 24 hours.</div>  </article>  <article className="carousel-slide card card-flat">    <header className="card-header">      <h3 className="card-title">Borealis</h3>      <p className="card-description">Edge functions close to the reader.</p>    </header>    <div className="card-body">Served from 14 regions.</div>  </article>  <article className="carousel-slide card card-flat">    <header className="card-header">      <h3 className="card-title">Cirrus</h3>      <p className="card-description">Storage that follows the project.</p>    </header>    <div className="card-body">7.4 of 10 GB in use.</div>  </article></div>
<div class="carousel" role="region" aria-label="Featured projects" tabindex="0">  <article class="carousel-slide card card-flat">    <header class="card-header">      <h3 class="card-title">Atlas</h3>      <p class="card-description">A map of every deployment, live.</p>    </header>    <div class="card-body">1.28M requests in the last 24 hours.</div>  </article>  <article class="carousel-slide card card-flat">    <header class="card-header">      <h3 class="card-title">Borealis</h3>      <p class="card-description">Edge functions close to the reader.</p>    </header>    <div class="card-body">Served from 14 regions.</div>  </article>  <article class="carousel-slide card card-flat">    <header class="card-header">      <h3 class="card-title">Cirrus</h3>      <p class="card-description">Storage that follows the project.</p>    </header>    <div class="card-body">7.4 of 10 GB in use.</div>  </article></div>
<template>  <div class="carousel" role="region" aria-label="Featured projects" tabindex="0">    <article class="carousel-slide card card-flat">      <header class="card-header">        <h3 class="card-title">Atlas</h3>        <p class="card-description">A map of every deployment, live.</p>      </header>      <div class="card-body">1.28M requests in the last 24 hours.</div>    </article>    <article class="carousel-slide card card-flat">      <header class="card-header">        <h3 class="card-title">Borealis</h3>        <p class="card-description">Edge functions close to the reader.</p>      </header>      <div class="card-body">Served from 14 regions.</div>    </article>    <article class="carousel-slide card card-flat">      <header class="card-header">        <h3 class="card-title">Cirrus</h3>        <p class="card-description">Storage that follows the project.</p>      </header>      <div class="card-body">7.4 of 10 GB in use.</div>    </article>  </div></template>

#캐러셀 컨트롤

버튼과 점에 해당하는 요소는 마크업에 없으며, 다음과 같은 의사 요소로 생성됩니다.

  • ::scroll-button(inline-start)과 ::scroll-button(inline-end)은 트랙을 한 페이지씩 스크롤합니다. 다른 버튼처럼 볼록한 표면으로 표시되며, 호버하면 떠오르고 누르면 내려갑니다. 브라우저는 트랙의 양 끝에서 해당 방향의 버튼을 비활성화합니다. 스타일시트는 비활성화된 버튼을 서서히 흐리게 한 뒤 숨겨, 버튼 아래에 있는 슬라이드를 가리지 않게 합니다.
  • 각 슬라이드의 ::scroll-marker는 점으로 표시되며, ::scroll-marker-group은 이 점들을 트랙 아래에 모읍니다. 현재 표시 중인 슬라이드의 점은 :target-current와 일치하며, 길어지고 전경색으로 표시됩니다. 각 점에 안쪽 여백을 넣어 조작 영역을 넓힙니다. 터치 화면에서는 이 영역이 더 넓어져 손가락으로 6픽셀 크기의 점을 정확히 누를 필요가 없습니다.

컨트롤은 앵커 위치 지정을 통해 자신이 속한 캐러셀을 기준으로 배치됩니다. 앵커 이름의 범위가 캐러셀별로 제한되므로 한 페이지에 캐러셀이 여러 개 있어도 컨트롤을 공유하지 않습니다. 이 의사 요소를 지원하지 않는 브라우저에서는 컨트롤만 빠지며, 슬라이드는 그대로 스와이프하고 스크롤할 수 있습니다. 이때는 얇은 스크롤 막대가 표시되어, 스와이프할 수 없는 마우스로도 옆으로 이동할 수 있습니다. 버튼과 점이 그려지는 브라우저와 carousel-view 안에서는 스크롤 막대가 표시되지 않습니다.

#여러 슬라이드 동시 표시

carousel-2와 carousel-3은 한 번에 슬라이드 두 장 또는 세 장을 표시합니다. 트랙 너비에서 슬라이드 사이의 간격을 뺀 뒤 표시할 슬라이드 수로 나누면, 화면에 보이는 마지막 슬라이드가 트랙 가장자리에 맞습니다.

여러 슬라이드 동시 표시

<div class="carousel carousel-3" role="region" aria-label="Team" tabindex="0">  <div class="carousel-slide sheet sheet-flat flex flex-col items-center gap-xs p-md">    <span class="avatar avatar-lg"><img class="avatar-image" src="/demo/portrait-1.svg" alt></span>    <span class="text-sm fg-text-strong">Ada</span>  </div>  <div class="carousel-slide sheet sheet-flat flex flex-col items-center gap-xs p-md">    <span class="avatar avatar-lg"><img class="avatar-image" src="/demo/portrait-2.svg" alt></span>    <span class="text-sm fg-text-strong">Alan</span>  </div>  <div class="carousel-slide sheet sheet-flat flex flex-col items-center gap-xs p-md">    <span class="avatar avatar-lg"><img class="avatar-image" src="/demo/portrait-3.svg" alt></span>    <span class="text-sm fg-text-strong">Katherine</span>  </div>  <div class="carousel-slide sheet sheet-flat flex flex-col items-center gap-xs p-md">    <span class="avatar avatar-lg" role="img" aria-label="Grace">GH</span>    <span class="text-sm fg-text-strong">Grace</span>  </div>  <div class="carousel-slide sheet sheet-flat flex flex-col items-center gap-xs p-md">    <span class="avatar avatar-lg" role="img" aria-label="Margaret">MH</span>    <span class="text-sm fg-text-strong">Margaret</span>  </div></div>
<div className="carousel carousel-3" role="region" aria-label="Team" tabIndex={0}>  <div className="carousel-slide sheet sheet-flat flex flex-col items-center gap-xs p-md">    <span className="avatar avatar-lg">      <img className="avatar-image" src="/demo/portrait-1.svg" alt="" />    </span>    <span className="text-sm fg-text-strong">Ada</span>  </div>  <div className="carousel-slide sheet sheet-flat flex flex-col items-center gap-xs p-md">    <span className="avatar avatar-lg">      <img className="avatar-image" src="/demo/portrait-2.svg" alt="" />    </span>    <span className="text-sm fg-text-strong">Alan</span>  </div>  <div className="carousel-slide sheet sheet-flat flex flex-col items-center gap-xs p-md">    <span className="avatar avatar-lg">      <img className="avatar-image" src="/demo/portrait-3.svg" alt="" />    </span>    <span className="text-sm fg-text-strong">Katherine</span>  </div>  <div className="carousel-slide sheet sheet-flat flex flex-col items-center gap-xs p-md">    <span className="avatar avatar-lg" role="img" aria-label="Grace">GH</span>    <span className="text-sm fg-text-strong">Grace</span>  </div>  <div className="carousel-slide sheet sheet-flat flex flex-col items-center gap-xs p-md">    <span className="avatar avatar-lg" role="img" aria-label="Margaret">MH</span>    <span className="text-sm fg-text-strong">Margaret</span>  </div></div>
<div class="carousel carousel-3" role="region" aria-label="Team" tabindex="0">  <div class="carousel-slide sheet sheet-flat flex flex-col items-center gap-xs p-md">    <span class="avatar avatar-lg"><img class="avatar-image" src="/demo/portrait-1.svg" alt></span>    <span class="text-sm fg-text-strong">Ada</span>  </div>  <div class="carousel-slide sheet sheet-flat flex flex-col items-center gap-xs p-md">    <span class="avatar avatar-lg"><img class="avatar-image" src="/demo/portrait-2.svg" alt></span>    <span class="text-sm fg-text-strong">Alan</span>  </div>  <div class="carousel-slide sheet sheet-flat flex flex-col items-center gap-xs p-md">    <span class="avatar avatar-lg"><img class="avatar-image" src="/demo/portrait-3.svg" alt></span>    <span class="text-sm fg-text-strong">Katherine</span>  </div>  <div class="carousel-slide sheet sheet-flat flex flex-col items-center gap-xs p-md">    <span class="avatar avatar-lg" role="img" aria-label="Grace">GH</span>    <span class="text-sm fg-text-strong">Grace</span>  </div>  <div class="carousel-slide sheet sheet-flat flex flex-col items-center gap-xs p-md">    <span class="avatar avatar-lg" role="img" aria-label="Margaret">MH</span>    <span class="text-sm fg-text-strong">Margaret</span>  </div></div>
<template>  <div class="carousel carousel-3" role="region" aria-label="Team" tabindex="0">    <div class="carousel-slide sheet sheet-flat flex flex-col items-center gap-xs p-md">      <span class="avatar avatar-lg">        <img class="avatar-image" src="/demo/portrait-1.svg" alt>      </span>      <span class="text-sm fg-text-strong">Ada</span>    </div>    <div class="carousel-slide sheet sheet-flat flex flex-col items-center gap-xs p-md">      <span class="avatar avatar-lg">        <img class="avatar-image" src="/demo/portrait-2.svg" alt>      </span>      <span class="text-sm fg-text-strong">Alan</span>    </div>    <div class="carousel-slide sheet sheet-flat flex flex-col items-center gap-xs p-md">      <span class="avatar avatar-lg">        <img class="avatar-image" src="/demo/portrait-3.svg" alt>      </span>      <span class="text-sm fg-text-strong">Katherine</span>    </div>    <div class="carousel-slide sheet sheet-flat flex flex-col items-center gap-xs p-md">      <span class="avatar avatar-lg" role="img" aria-label="Grace">GH</span>      <span class="text-sm fg-text-strong">Grace</span>    </div>    <div class="carousel-slide sheet sheet-flat flex flex-col items-center gap-xs p-md">      <span class="avatar avatar-lg" role="img" aria-label="Margaret">MH</span>      <span class="text-sm fg-text-strong">Margaret</span>    </div>  </div></template>

#다음 슬라이드 일부 노출

--carousel-slide 값을 트랙 너비보다 작게 설정하면 다음 슬라이드의 가장자리가 보입니다. 점을 확인하기 전에도 슬라이드가 더 있다는 것을 알 수 있고, 점이 표시되지 않는 브라우저에서는 이 가장자리가 유일한 시각적 단서입니다. 이미지는 그림으로 구성합니다. 트랙에 --figure-ratio를 지정하면 이미지가 로드되기 전부터 모두 같은 비율로 공간을 차지하므로 슬라이드 줄이 갑자기 움직이지 않습니다.

다음 슬라이드 일부 노출

<div class="carousel" style="--carousel-slide: 84%; --figure-ratio: 16 / 10" role="region" aria-label="Field notes" tabindex="0">  <figure class="carousel-slide figure">    <img class="figure-media" src="/demo/harbor.svg" alt="A wooden jetty running out over calm water">    <figcaption class="figure-caption">The jetty at high water</figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/demo/tide.svg" alt="A pale sun low over flat water">    <figcaption class="figure-caption">Low tide at seven</figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/demo/moonstone.svg" alt="A full moon above two ridges">    <figcaption class="figure-caption">Moonrise over the ridges</figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/demo/pines.svg" alt="A line of pines in mist">    <figcaption class="figure-caption">Pines in the morning fog</figcaption>  </figure></div>
<div className="carousel" style={{ '--carousel-slide': '84%', '--figure-ratio': '16 / 10' } as React.CSSProperties} role="region" aria-label="Field notes" tabIndex={0}>  <figure className="carousel-slide figure">    <img className="figure-media" src="/demo/harbor.svg" alt="A wooden jetty running out over calm water" />    <figcaption className="figure-caption">The jetty at high water</figcaption>  </figure>  <figure className="carousel-slide figure">    <img className="figure-media" src="/demo/tide.svg" alt="A pale sun low over flat water" />    <figcaption className="figure-caption">Low tide at seven</figcaption>  </figure>  <figure className="carousel-slide figure">    <img className="figure-media" src="/demo/moonstone.svg" alt="A full moon above two ridges" />    <figcaption className="figure-caption">Moonrise over the ridges</figcaption>  </figure>  <figure className="carousel-slide figure">    <img className="figure-media" src="/demo/pines.svg" alt="A line of pines in mist" />    <figcaption className="figure-caption">Pines in the morning fog</figcaption>  </figure></div>
<div class="carousel" style="--carousel-slide: 84%; --figure-ratio: 16 / 10" role="region" aria-label="Field notes" tabindex="0">  <figure class="carousel-slide figure">    <img class="figure-media" src="/demo/harbor.svg" alt="A wooden jetty running out over calm water">    <figcaption class="figure-caption">The jetty at high water</figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/demo/tide.svg" alt="A pale sun low over flat water">    <figcaption class="figure-caption">Low tide at seven</figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/demo/moonstone.svg" alt="A full moon above two ridges">    <figcaption class="figure-caption">Moonrise over the ridges</figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/demo/pines.svg" alt="A line of pines in mist">    <figcaption class="figure-caption">Pines in the morning fog</figcaption>  </figure></div>
<template>  <div class="carousel" style="--carousel-slide: 84%; --figure-ratio: 16 / 10" role="region" aria-label="Field notes" tabindex="0">    <figure class="carousel-slide figure">      <img class="figure-media" src="/demo/harbor.svg" alt="A wooden jetty running out over calm water">      <figcaption class="figure-caption">The jetty at high water</figcaption>    </figure>    <figure class="carousel-slide figure">      <img class="figure-media" src="/demo/tide.svg" alt="A pale sun low over flat water">      <figcaption class="figure-caption">Low tide at seven</figcaption>    </figure>    <figure class="carousel-slide figure">      <img class="figure-media" src="/demo/moonstone.svg" alt="A full moon above two ridges">      <figcaption class="figure-caption">Moonrise over the ridges</figcaption>    </figure>    <figure class="carousel-slide figure">      <img class="figure-media" src="/demo/pines.svg" alt="A line of pines in mist">      <figcaption class="figure-caption">Pines in the morning fog</figcaption>    </figure>  </div></template>

#슬라이드 중앙 정렬

carousel-center는 현재 슬라이드를 중앙에 배치하고 양옆에 인접 슬라이드의 가장자리를 보여 줍니다. 첫 슬라이드 앞과 마지막 슬라이드 뒤에도 공간을 두어 두 슬라이드 모두 중앙에 올 수 있게 합니다. 슬라이드 하나는 트랙 너비의 80%를 차지합니다. --carousel-slide 값을 설정해 양옆 슬라이드가 보이는 정도를 조절하세요. 양 끝의 공간은 안쪽 여백 대신 빈 플렉스 항목 두 개로 확보하므로 슬라이드 너비는 전체 트랙 너비를 기준으로 계산됩니다.

슬라이드 중앙 정렬

<div class="carousel carousel-center" style="--figure-ratio: 16 / 10" role="region" aria-label="Material studies" tabindex="0">  <figure class="carousel-slide figure">    <img class="figure-media" src="/home/slides/pearl.svg" alt="A pearl on a stone plinth, in soft morning light">    <figcaption class="figure-caption">Pearl, in morning light</figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/home/slides/obsidian.svg" alt="A polished obsidian sphere on a dark glossy floor, a softbox reflected in it">    <figcaption class="figure-caption">Obsidian, under a softbox</figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/home/slides/dune.svg" alt="Dunes at first light, their ridges catching a low sun">    <figcaption class="figure-caption">Dunes, at first light</figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/home/slides/tide.svg" alt="A still sea at dusk, the moon low over the horizon and its light broken on the water">    <figcaption class="figure-caption">Tide, at dusk</figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/home/slides/arches.svg" alt="A plaster hall with three arched openings, low sun laying their shapes across the floor">    <figcaption class="figure-caption">Arches, in low sun</figcaption>  </figure></div>
<div className="carousel carousel-center" style={{ '--figure-ratio': '16 / 10' } as React.CSSProperties} role="region" aria-label="Material studies" tabIndex={0}>  <figure className="carousel-slide figure">    <img className="figure-media" src="/home/slides/pearl.svg" alt="A pearl on a stone plinth, in soft morning light" />    <figcaption className="figure-caption">Pearl, in morning light</figcaption>  </figure>  <figure className="carousel-slide figure">    <img className="figure-media" src="/home/slides/obsidian.svg" alt="A polished obsidian sphere on a dark glossy floor, a softbox reflected in it" />    <figcaption className="figure-caption">Obsidian, under a softbox</figcaption>  </figure>  <figure className="carousel-slide figure">    <img className="figure-media" src="/home/slides/dune.svg" alt="Dunes at first light, their ridges catching a low sun" />    <figcaption className="figure-caption">Dunes, at first light</figcaption>  </figure>  <figure className="carousel-slide figure">    <img className="figure-media" src="/home/slides/tide.svg" alt="A still sea at dusk, the moon low over the horizon and its light broken on the water" />    <figcaption className="figure-caption">Tide, at dusk</figcaption>  </figure>  <figure className="carousel-slide figure">    <img className="figure-media" src="/home/slides/arches.svg" alt="A plaster hall with three arched openings, low sun laying their shapes across the floor" />    <figcaption className="figure-caption">Arches, in low sun</figcaption>  </figure></div>
<div class="carousel carousel-center" style="--figure-ratio: 16 / 10" role="region" aria-label="Material studies" tabindex="0">  <figure class="carousel-slide figure">    <img class="figure-media" src="/home/slides/pearl.svg" alt="A pearl on a stone plinth, in soft morning light">    <figcaption class="figure-caption">Pearl, in morning light</figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/home/slides/obsidian.svg" alt="A polished obsidian sphere on a dark glossy floor, a softbox reflected in it">    <figcaption class="figure-caption">Obsidian, under a softbox</figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/home/slides/dune.svg" alt="Dunes at first light, their ridges catching a low sun">    <figcaption class="figure-caption">Dunes, at first light</figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/home/slides/tide.svg" alt="A still sea at dusk, the moon low over the horizon and its light broken on the water">    <figcaption class="figure-caption">Tide, at dusk</figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/home/slides/arches.svg" alt="A plaster hall with three arched openings, low sun laying their shapes across the floor">    <figcaption class="figure-caption">Arches, in low sun</figcaption>  </figure></div>
<template>  <div class="carousel carousel-center" style="--figure-ratio: 16 / 10" role="region" aria-label="Material studies" tabindex="0">    <figure class="carousel-slide figure">      <img class="figure-media" src="/home/slides/pearl.svg" alt="A pearl on a stone plinth, in soft morning light">      <figcaption class="figure-caption">Pearl, in morning light</figcaption>    </figure>    <figure class="carousel-slide figure">      <img class="figure-media" src="/home/slides/obsidian.svg" alt="A polished obsidian sphere on a dark glossy floor, a softbox reflected in it">      <figcaption class="figure-caption">Obsidian, under a softbox</figcaption>    </figure>    <figure class="carousel-slide figure">      <img class="figure-media" src="/home/slides/dune.svg" alt="Dunes at first light, their ridges catching a low sun">      <figcaption class="figure-caption">Dunes, at first light</figcaption>    </figure>    <figure class="carousel-slide figure">      <img class="figure-media" src="/home/slides/tide.svg" alt="A still sea at dusk, the moon low over the horizon and its light broken on the water">      <figcaption class="figure-caption">Tide, at dusk</figcaption>    </figure>    <figure class="carousel-slide figure">      <img class="figure-media" src="/home/slides/arches.svg" alt="A plaster hall with three arched openings, low sun laying their shapes across the floor">      <figcaption class="figure-caption">Arches, in low sun</figcaption>    </figure>  </div></template>

#고정 너비 슬라이드 목록

모든 슬라이드의 너비를 같은 고정값으로 지정하면 트랙에 들어가는 만큼 표시되고, 그다음 슬라이드는 트랙 가장자리에서 일부가 잘립니다. 근접 스냅을 적용하면 빠르게 밀었을 때 슬라이드마다 멈추지 않고 여러 장을 지나갈 수 있으며, 스크롤이 멈추는 지점에서 가까운 슬라이드에 맞춰 정렬됩니다.

고정 너비 슬라이드 목록

<div class="carousel (scroll-snap-type:x|proximity)" style="--carousel-slide: 8.5rem; --carousel-gap: .75rem; --figure-ratio: 4 / 5" role="region" aria-label="Prints" tabindex="0">  <figure class="carousel-slide figure">    <img class="figure-media" src="/demo/cairn.svg" alt="Five stones balanced on a beach">    <figcaption class="figure-caption">      <span class="block fg-text-strong">Cairn</span>$48    </figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/demo/dunes.svg" alt="Dunes in the afternoon, their lee sides in shadow">    <figcaption class="figure-caption">      <span class="block fg-text-strong">Dunes</span>$56    </figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/demo/lighthouse.svg" alt="A lighthouse on a dark headland, its beam over the sea">    <figcaption class="figure-caption">      <span class="block fg-text-strong">Headland</span>$64    </figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/demo/pines.svg" alt="Rows of pines fading into fog">    <figcaption class="figure-caption">      <span class="block fg-text-strong">Pines</span>$48    </figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/demo/steps.svg" alt="Concrete steps half in shadow">    <figcaption class="figure-caption">      <span class="block fg-text-strong">Steps</span>$40    </figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/demo/harbor.svg" alt="Jetty posts standing in the water">    <figcaption class="figure-caption">      <span class="block fg-text-strong">Jetty</span>$56    </figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/demo/tide.svg" alt="The sea at slack tide">    <figcaption class="figure-caption">      <span class="block fg-text-strong">Slack tide</span>$48    </figcaption>  </figure></div>
<div className="carousel (scroll-snap-type:x|proximity)" style={{ '--carousel-slide': '8.5rem', '--carousel-gap': '.75rem', '--figure-ratio': '4 / 5' } as React.CSSProperties} role="region" aria-label="Prints" tabIndex={0}>  <figure className="carousel-slide figure">    <img className="figure-media" src="/demo/cairn.svg" alt="Five stones balanced on a beach" />    <figcaption className="figure-caption">      <span className="block fg-text-strong">Cairn</span>$48    </figcaption>  </figure>  <figure className="carousel-slide figure">    <img className="figure-media" src="/demo/dunes.svg" alt="Dunes in the afternoon, their lee sides in shadow" />    <figcaption className="figure-caption">      <span className="block fg-text-strong">Dunes</span>$56    </figcaption>  </figure>  <figure className="carousel-slide figure">    <img className="figure-media" src="/demo/lighthouse.svg" alt="A lighthouse on a dark headland, its beam over the sea" />    <figcaption className="figure-caption">      <span className="block fg-text-strong">Headland</span>$64    </figcaption>  </figure>  <figure className="carousel-slide figure">    <img className="figure-media" src="/demo/pines.svg" alt="Rows of pines fading into fog" />    <figcaption className="figure-caption">      <span className="block fg-text-strong">Pines</span>$48    </figcaption>  </figure>  <figure className="carousel-slide figure">    <img className="figure-media" src="/demo/steps.svg" alt="Concrete steps half in shadow" />    <figcaption className="figure-caption">      <span className="block fg-text-strong">Steps</span>$40    </figcaption>  </figure>  <figure className="carousel-slide figure">    <img className="figure-media" src="/demo/harbor.svg" alt="Jetty posts standing in the water" />    <figcaption className="figure-caption">      <span className="block fg-text-strong">Jetty</span>$56    </figcaption>  </figure>  <figure className="carousel-slide figure">    <img className="figure-media" src="/demo/tide.svg" alt="The sea at slack tide" />    <figcaption className="figure-caption">      <span className="block fg-text-strong">Slack tide</span>$48    </figcaption>  </figure></div>
<div class="carousel (scroll-snap-type:x|proximity)" style="--carousel-slide: 8.5rem; --carousel-gap: .75rem; --figure-ratio: 4 / 5" role="region" aria-label="Prints" tabindex="0">  <figure class="carousel-slide figure">    <img class="figure-media" src="/demo/cairn.svg" alt="Five stones balanced on a beach">    <figcaption class="figure-caption">      <span class="block fg-text-strong">Cairn</span>$48    </figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/demo/dunes.svg" alt="Dunes in the afternoon, their lee sides in shadow">    <figcaption class="figure-caption">      <span class="block fg-text-strong">Dunes</span>$56    </figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/demo/lighthouse.svg" alt="A lighthouse on a dark headland, its beam over the sea">    <figcaption class="figure-caption">      <span class="block fg-text-strong">Headland</span>$64    </figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/demo/pines.svg" alt="Rows of pines fading into fog">    <figcaption class="figure-caption">      <span class="block fg-text-strong">Pines</span>$48    </figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/demo/steps.svg" alt="Concrete steps half in shadow">    <figcaption class="figure-caption">      <span class="block fg-text-strong">Steps</span>$40    </figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/demo/harbor.svg" alt="Jetty posts standing in the water">    <figcaption class="figure-caption">      <span class="block fg-text-strong">Jetty</span>$56    </figcaption>  </figure>  <figure class="carousel-slide figure">    <img class="figure-media" src="/demo/tide.svg" alt="The sea at slack tide">    <figcaption class="figure-caption">      <span class="block fg-text-strong">Slack tide</span>$48    </figcaption>  </figure></div>
<template>  <div class="carousel (scroll-snap-type:x|proximity)" style="--carousel-slide: 8.5rem; --carousel-gap: .75rem; --figure-ratio: 4 / 5" role="region" aria-label="Prints" tabindex="0">    <figure class="carousel-slide figure">      <img class="figure-media" src="/demo/cairn.svg" alt="Five stones balanced on a beach">      <figcaption class="figure-caption">        <span class="block fg-text-strong">Cairn</span>$48      </figcaption>    </figure>    <figure class="carousel-slide figure">      <img class="figure-media" src="/demo/dunes.svg" alt="Dunes in the afternoon, their lee sides in shadow">      <figcaption class="figure-caption">        <span class="block fg-text-strong">Dunes</span>$56      </figcaption>    </figure>    <figure class="carousel-slide figure">      <img class="figure-media" src="/demo/lighthouse.svg" alt="A lighthouse on a dark headland, its beam over the sea">      <figcaption class="figure-caption">        <span class="block fg-text-strong">Headland</span>$64      </figcaption>    </figure>    <figure class="carousel-slide figure">      <img class="figure-media" src="/demo/pines.svg" alt="Rows of pines fading into fog">      <figcaption class="figure-caption">        <span class="block fg-text-strong">Pines</span>$48      </figcaption>    </figure>    <figure class="carousel-slide figure">      <img class="figure-media" src="/demo/steps.svg" alt="Concrete steps half in shadow">      <figcaption class="figure-caption">        <span class="block fg-text-strong">Steps</span>$40      </figcaption>    </figure>    <figure class="carousel-slide figure">      <img class="figure-media" src="/demo/harbor.svg" alt="Jetty posts standing in the water">      <figcaption class="figure-caption">        <span class="block fg-text-strong">Jetty</span>$56      </figcaption>    </figure>    <figure class="carousel-slide figure">      <img class="figure-media" src="/demo/tide.svg" alt="The sea at slack tide">      <figcaption class="figure-caption">        <span class="block fg-text-strong">Slack tide</span>$48      </figcaption>    </figure>  </div></template>

#컨테이너 너비에 따른 표시 개수

표시할 슬라이드 수는 창 너비 대신 캐러셀에 주어진 공간에 맞춰 바꿀 수 있습니다. 부모 요소를 쿼리 컨테이너로 지정하고, 너비 구간마다 트랙 너비에서 간격을 뺀 값을 표시할 슬라이드 수로 나누어 --carousel-slide에 설정하세요. carousel-2와 carousel-3도 이 방식으로 값을 설정합니다. 미리보기 너비를 줄이면 슬라이드가 세 장에서 두 장, 다시 한 장으로 줄어드는 것을 확인할 수 있습니다.

컨테이너 너비에 따른 표시 개수

656 px
<div class="container-inline">  <div class="carousel (--carousel-slide:calc((100%-1rem)/2))@container(--sm) (--carousel-slide:calc((100%-2rem)/3))@container(--xl)" role="region" aria-label="Projects" tabindex="0">    <article class="carousel-slide card card-flat">      <header class="card-header">        <h3 class="card-title">Atlas</h3>        <p class="card-description">A map of every deployment.</p>      </header>    </article>    <article class="carousel-slide card card-flat">      <header class="card-header">        <h3 class="card-title">Borealis</h3>        <p class="card-description">Edge functions near the reader.</p>      </header>    </article>    <article class="carousel-slide card card-flat">      <header class="card-header">        <h3 class="card-title">Cirrus</h3>        <p class="card-description">Storage that follows the project.</p>      </header>    </article>    <article class="carousel-slide card card-flat">      <header class="card-header">        <h3 class="card-title">Delta</h3>        <p class="card-description">Previews for every branch.</p>      </header>    </article>    <article class="carousel-slide card card-flat">      <header class="card-header">        <h3 class="card-title">Ember</h3>        <p class="card-description">Logs that keep a week.</p>      </header>    </article>  </div></div>
<div className="container-inline">  <div className="carousel (--carousel-slide:calc((100%-1rem)/2))@container(--sm) (--carousel-slide:calc((100%-2rem)/3))@container(--xl)" role="region" aria-label="Projects" tabIndex={0}>    <article className="carousel-slide card card-flat">      <header className="card-header">        <h3 className="card-title">Atlas</h3>        <p className="card-description">A map of every deployment.</p>      </header>    </article>    <article className="carousel-slide card card-flat">      <header className="card-header">        <h3 className="card-title">Borealis</h3>        <p className="card-description">Edge functions near the reader.</p>      </header>    </article>    <article className="carousel-slide card card-flat">      <header className="card-header">        <h3 className="card-title">Cirrus</h3>        <p className="card-description">Storage that follows the project.</p>      </header>    </article>    <article className="carousel-slide card card-flat">      <header className="card-header">        <h3 className="card-title">Delta</h3>        <p className="card-description">Previews for every branch.</p>      </header>    </article>    <article className="carousel-slide card card-flat">      <header className="card-header">        <h3 className="card-title">Ember</h3>        <p className="card-description">Logs that keep a week.</p>      </header>    </article>  </div></div>
<div class="container-inline">  <div class="carousel (--carousel-slide:calc((100%-1rem)/2))@container(--sm) (--carousel-slide:calc((100%-2rem)/3))@container(--xl)" role="region" aria-label="Projects" tabindex="0">    <article class="carousel-slide card card-flat">      <header class="card-header">        <h3 class="card-title">Atlas</h3>        <p class="card-description">A map of every deployment.</p>      </header>    </article>    <article class="carousel-slide card card-flat">      <header class="card-header">        <h3 class="card-title">Borealis</h3>        <p class="card-description">Edge functions near the reader.</p>      </header>    </article>    <article class="carousel-slide card card-flat">      <header class="card-header">        <h3 class="card-title">Cirrus</h3>        <p class="card-description">Storage that follows the project.</p>      </header>    </article>    <article class="carousel-slide card card-flat">      <header class="card-header">        <h3 class="card-title">Delta</h3>        <p class="card-description">Previews for every branch.</p>      </header>    </article>    <article class="carousel-slide card card-flat">      <header class="card-header">        <h3 class="card-title">Ember</h3>        <p class="card-description">Logs that keep a week.</p>      </header>    </article>  </div></div>
<template>  <div class="container-inline">    <div class="carousel (--carousel-slide:calc((100%-1rem)/2))@container(--sm) (--carousel-slide:calc((100%-2rem)/3))@container(--xl)" role="region" aria-label="Projects" tabindex="0">      <article class="carousel-slide card card-flat">        <header class="card-header">          <h3 class="card-title">Atlas</h3>          <p class="card-description">A map of every deployment.</p>        </header>      </article>      <article class="carousel-slide card card-flat">        <header class="card-header">          <h3 class="card-title">Borealis</h3>          <p class="card-description">Edge functions near the reader.</p>        </header>      </article>      <article class="carousel-slide card card-flat">        <header class="card-header">          <h3 class="card-title">Cirrus</h3>          <p class="card-description">Storage that follows the project.</p>        </header>      </article>      <article class="carousel-slide card card-flat">        <header class="card-header">          <h3 class="card-title">Delta</h3>          <p class="card-description">Previews for every branch.</p>        </header>      </article>      <article class="carousel-slide card card-flat">        <header class="card-header">          <h3 class="card-title">Ember</h3>          <p class="card-description">Logs that keep a week.</p>        </header>      </article>    </div>  </div></template>

#세로 방향

carousel-vertical은 가로 행을 높이가 --carousel-viewport(기본값 20rem)인 세로 열로 바꾸며, 위아래로 스크롤하고 스냅합니다. 슬라이드는 높이의 --carousel-slide만큼을 차지합니다. 버튼은 위쪽과 아래쪽 가장자리의 가운데에 놓이고, 점은 끝 가장자리 옆에 세로로 나열됩니다.

세로 방향

<div class="carousel carousel-vertical w-full max-w(360)" style="--carousel-viewport: 15rem; --carousel-slide: 50%" role="region" aria-label="This week" tabindex="0">  <article class="carousel-slide card card-flat">    <header class="card-header">      <h3 class="card-title">Monday</h3>      <p class="card-description">Planning, then the design review.</p>    </header>  </article>  <article class="carousel-slide card card-flat">    <header class="card-header">      <h3 class="card-title">Tuesday</h3>      <p class="card-description">Pairing on the schedule view.</p>    </header>  </article>  <article class="carousel-slide card card-flat">    <header class="card-header">      <h3 class="card-title">Wednesday</h3>      <p class="card-description">Release notes and the changelog.</p>    </header>  </article></div>
<div className="carousel carousel-vertical w-full max-w(360)" style={{ '--carousel-viewport': '15rem', '--carousel-slide': '50%' } as React.CSSProperties} role="region" aria-label="This week" tabIndex={0}>  <article className="carousel-slide card card-flat">    <header className="card-header">      <h3 className="card-title">Monday</h3>      <p className="card-description">Planning, then the design review.</p>    </header>  </article>  <article className="carousel-slide card card-flat">    <header className="card-header">      <h3 className="card-title">Tuesday</h3>      <p className="card-description">Pairing on the schedule view.</p>    </header>  </article>  <article className="carousel-slide card card-flat">    <header className="card-header">      <h3 className="card-title">Wednesday</h3>      <p className="card-description">Release notes and the changelog.</p>    </header>  </article></div>
<div class="carousel carousel-vertical w-full max-w(360)" style="--carousel-viewport: 15rem; --carousel-slide: 50%" role="region" aria-label="This week" tabindex="0">  <article class="carousel-slide card card-flat">    <header class="card-header">      <h3 class="card-title">Monday</h3>      <p class="card-description">Planning, then the design review.</p>    </header>  </article>  <article class="carousel-slide card card-flat">    <header class="card-header">      <h3 class="card-title">Tuesday</h3>      <p class="card-description">Pairing on the schedule view.</p>    </header>  </article>  <article class="carousel-slide card card-flat">    <header class="card-header">      <h3 class="card-title">Wednesday</h3>      <p class="card-description">Release notes and the changelog.</p>    </header>  </article></div>
<template>  <div class="carousel carousel-vertical w-full max-w(360)" style="--carousel-viewport: 15rem; --carousel-slide: 50%" role="region" aria-label="This week" tabindex="0">    <article class="carousel-slide card card-flat">      <header class="card-header">        <h3 class="card-title">Monday</h3>        <p class="card-description">Planning, then the design review.</p>      </header>    </article>    <article class="carousel-slide card card-flat">      <header class="card-header">        <h3 class="card-title">Tuesday</h3>        <p class="card-description">Pairing on the schedule view.</p>      </header>    </article>    <article class="carousel-slide card card-flat">      <header class="card-header">        <h3 class="card-title">Wednesday</h3>        <p class="card-description">Release notes and the changelog.</p>      </header>    </article>  </div></template>

#표시 중인 슬라이드 읽기와 설정

어떤 슬라이드가 표시되어 있는지 알아야 하거나 특정 슬라이드를 보여 주어야 하는 페이지에서는 트랙을 carousel-view에 넣고 이전·다음 버튼과 점 행을 직접 작성합니다. 뷰 안에서는 생성된 컨트롤이 물러나므로 버튼은 한 세트만 남습니다. 이 컨트롤은 carousel 동작이 제어합니다.

  • IntersectionObserver로 각 슬라이드가 얼마나 보이는지 추적합니다. 스크롤이 scrollend로 끝나면 가장 많이 보이는 슬라이드가 현재 항목이 됩니다. 이 이벤트를 지원하지 않는 브라우저에서는 스크롤이 잠시 멈춘 뒤에 판단합니다. 표시 비율이 같으면 그중 현재 슬라이드를 유지하고, 현재 슬라이드가 없으면 문서 순서상 첫 항목을 선택합니다. 여러 슬라이드가 뷰 안에 동시에 들어갈 때 브라우저의 스냅 대상은 다른 슬라이드일 수 있습니다.
  • 이전, 다음 버튼과 점은 플랫폼에 해당 슬라이드를 자체 스냅 정렬 위치로 스크롤해 달라고 요청하며, 동작 줄이기 설정에서는 즉시 이동합니다. 동작이 위치를 직접 설정하지는 않습니다.
  • 현재 슬라이드의 점에는 aria-current="true"가 지정되고, 처음에는 이전 버튼이, 끝에서는 다음 버튼이 비활성화됩니다. 여러 슬라이드가 함께 보일 수 있지만 현재 슬라이드는 하나이며, 다른 슬라이드는 숨겨지지 않습니다.
  • 각 슬라이드는 data-value 또는 id로 식별하므로, 앞에 슬라이드가 추가되어도 현재 슬라이드는 그대로 유지됩니다. 독자가 변경하면 input과 change 이벤트가 발행됩니다. 이 동작이 반환하는 함수의 value는 읽고 설정할 수 있으며, 값을 설정할 때는 이벤트가 발행되지 않습니다.

표시 중인 슬라이드 읽기와 설정

<div class="carousel-view w-full">  <div class="carousel" role="region" aria-label="Releases" tabindex="0">    <article class="carousel-slide card card-flat" id="release-atlas" data-value="atlas">      <header class="card-header">        <h3 class="card-title">Atlas</h3>        <p class="card-description">A map of every deployment, live.</p>      </header>    </article>    <article class="carousel-slide card card-flat" id="release-borealis" data-value="borealis">      <header class="card-header">        <h3 class="card-title">Borealis</h3>        <p class="card-description">Edge functions close to the reader.</p>      </header>    </article>    <article class="carousel-slide card card-flat" id="release-cirrus" data-value="cirrus">      <header class="card-header">        <h3 class="card-title">Cirrus</h3>        <p class="card-description">Storage that follows the project.</p>      </header>    </article>  </div>  <button type="button" class="btn btn-square btn-sm btn-pill carousel-previous" aria-label="Previous slide">    <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">      <path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform="rotate(180 8 8)" />    </svg>  </button>  <button type="button" class="btn btn-square btn-sm btn-pill carousel-next" aria-label="Next slide">    <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">      <path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" />    </svg>  </button>  <div class="carousel-dots">    <button type="button" class="carousel-dot" aria-controls="release-atlas" aria-label="Slide 1 of 3"></button>    <button type="button" class="carousel-dot" aria-controls="release-borealis" aria-label="Slide 2 of 3"></button>    <button type="button" class="carousel-dot" aria-controls="release-cirrus" aria-label="Slide 3 of 3"></button>  </div></div><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'import ChevronLeftIcon from '@master/icons-react/native/16/soft/chevron-left'import ChevronRightIcon from '@master/icons-react/native/16/soft/chevron-right'export function Example() {  const root = useRef<HTMLDivElement>(null)  useEffect(() => attach(root.current!), [])  return (    <div ref={root} className="carousel-view w-full">      <div className="carousel" role="region" aria-label="Releases" tabIndex={0}>        <article className="carousel-slide card card-flat" id="release-atlas" data-value="atlas">          <header className="card-header">            <h3 className="card-title">Atlas</h3>            <p className="card-description">A map of every deployment, live.</p>          </header>        </article>        <article className="carousel-slide card card-flat" id="release-borealis" data-value="borealis">          <header className="card-header">            <h3 className="card-title">Borealis</h3>            <p className="card-description">Edge functions close to the reader.</p>          </header>        </article>        <article className="carousel-slide card card-flat" id="release-cirrus" data-value="cirrus">          <header className="card-header">            <h3 className="card-title">Cirrus</h3>            <p className="card-description">Storage that follows the project.</p>          </header>        </article>      </div>      <button type="button" className="btn btn-square btn-sm btn-pill carousel-previous" aria-label="Previous slide">        <ChevronLeftIcon className="icon" />      </button>      <button type="button" className="btn btn-square btn-sm btn-pill carousel-next" aria-label="Next slide">        <ChevronRightIcon className="icon" />      </button>      <div className="carousel-dots">        <button type="button" className="carousel-dot" aria-controls="release-atlas" aria-label="Slide 1 of 3"></button>        <button type="button" className="carousel-dot" aria-controls="release-borealis" aria-label="Slide 2 of 3"></button>        <button type="button" className="carousel-dot" aria-controls="release-cirrus" aria-label="Slide 3 of 3"></button>      </div>    </div>  )}
<script>  import { attach } from '@master/ui/behaviors'  import ChevronLeftIcon from '@master/icons-svelte/native/16/soft/chevron-left'  import ChevronRightIcon from '@master/icons-svelte/native/16/soft/chevron-right'</script><div class="carousel-view w-full" {@attach attach}>  <div class="carousel" role="region" aria-label="Releases" tabindex="0">    <article class="carousel-slide card card-flat" id="release-atlas" data-value="atlas">      <header class="card-header">        <h3 class="card-title">Atlas</h3>        <p class="card-description">A map of every deployment, live.</p>      </header>    </article>    <article class="carousel-slide card card-flat" id="release-borealis" data-value="borealis">      <header class="card-header">        <h3 class="card-title">Borealis</h3>        <p class="card-description">Edge functions close to the reader.</p>      </header>    </article>    <article class="carousel-slide card card-flat" id="release-cirrus" data-value="cirrus">      <header class="card-header">        <h3 class="card-title">Cirrus</h3>        <p class="card-description">Storage that follows the project.</p>      </header>    </article>  </div>  <button type="button" class="btn btn-square btn-sm btn-pill carousel-previous" aria-label="Previous slide">    <ChevronLeftIcon class="icon" />  </button>  <button type="button" class="btn btn-square btn-sm btn-pill carousel-next" aria-label="Next slide">    <ChevronRightIcon class="icon" />  </button>  <div class="carousel-dots">    <button type="button" class="carousel-dot" aria-controls="release-atlas" aria-label="Slide 1 of 3"></button>    <button type="button" class="carousel-dot" aria-controls="release-borealis" aria-label="Slide 2 of 3"></button>    <button type="button" class="carousel-dot" aria-controls="release-cirrus" aria-label="Slide 3 of 3"></button>  </div></div>
<script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'import ChevronLeftIcon from '@master/icons-vue/native/16/soft/chevron-left'import ChevronRightIcon from '@master/icons-vue/native/16/soft/chevron-right'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template>  <div ref="root" class="carousel-view w-full">    <div class="carousel" role="region" aria-label="Releases" tabindex="0">      <article class="carousel-slide card card-flat" id="release-atlas" data-value="atlas">        <header class="card-header">          <h3 class="card-title">Atlas</h3>          <p class="card-description">A map of every deployment, live.</p>        </header>      </article>      <article class="carousel-slide card card-flat" id="release-borealis" data-value="borealis">        <header class="card-header">          <h3 class="card-title">Borealis</h3>          <p class="card-description">Edge functions close to the reader.</p>        </header>      </article>      <article class="carousel-slide card card-flat" id="release-cirrus" data-value="cirrus">        <header class="card-header">          <h3 class="card-title">Cirrus</h3>          <p class="card-description">Storage that follows the project.</p>        </header>      </article>    </div>    <button type="button" class="btn btn-square btn-sm btn-pill carousel-previous" aria-label="Previous slide">      <ChevronLeftIcon class="icon" />    </button>    <button type="button" class="btn btn-square btn-sm btn-pill carousel-next" aria-label="Next slide">      <ChevronRightIcon class="icon" />    </button>    <div class="carousel-dots">      <button type="button" class="carousel-dot" aria-controls="release-atlas" aria-label="Slide 1 of 3"></button>      <button type="button" class="carousel-dot" aria-controls="release-borealis" aria-label="Slide 2 of 3"></button>      <button type="button" class="carousel-dot" aria-controls="release-cirrus" aria-label="Slide 3 of 3"></button>    </div>  </div></template>
app.js
import { carousel } from '@master/ui/behaviors/carousel.js'const releases = carousel(document.querySelector('.carousel-view'), { value: 'borealis' })releases.value // 'borealis'

#접근성

  • 방향키로 트랙을 스크롤할 수 있도록 트랙에 role="region"과 레이블, tabindex="0"을 지정하세요.
  • 스타일시트는 생성된 버튼에 각각 "Previous slide"와 "Next slide"라는 이름을 지정합니다. 페이지 언어로 이름을 지정하려면 --carousel-previous-label과 --carousel-next-label에 따옴표로 묶은 문자열을 설정하세요. 캐러셀 자체나 루트 같은 상위 요소에 설정합니다. 각 점의 이름은 해당 슬라이드 콘텐츠의 이름을 따릅니다.
  • 캐러셀은 자동으로 이동하지 않습니다. 타이머에 따라 콘텐츠가 넘어가도록 구현하려면 스크립트로 일시정지 컨트롤을 제공해야 합니다.
  • 동작 줄이기 설정이 켜져 있으면 트랙은 부드럽게 스크롤하는 대신 슬라이드 사이를 즉시 이동합니다.
  • 강제 색상 모드에서는 버튼에 버튼 색상의 윤곽선이 표시되고, 점에는 시스템 색상이 유지됩니다. 현재 표시 중인 슬라이드의 점에는 시스템 강조 색상이 적용됩니다.
  • carousel-view에서는 버튼과 점의 이름을 페이지 언어로 지정하세요. 점의 이름은 전체 슬라이드 중 몇 번째 슬라이드로 이동하는지 알려 주어야 합니다.

#React, Svelte 및 Vue

carousel 컴포넌트는 항목 목록으로 슬라이드를 작성하고 그 옆에 뷰의 버튼과 점을 작성합니다. 각 항목의 value는 항목 목록이 바뀌어도 그대로 유지되어야 합니다. 컴포넌트의 값은 현재 슬라이드입니다. npx master-ui add carousel로 프로젝트에 복사하세요. 컴포넌트의 구성과 사용법은 React, Svelte 및 Vue에서 확인할 수 있습니다. 현재 슬라이드를 읽을 필요가 없는 캐러셀이라면 컴포넌트가 필요 없으며 위의 마크업으로 충분합니다.

ui/carousel.tsx
'use client'import { useId, useState, type ComponentProps, type ReactNode } from 'react'import { carousel, type CarouselOptions } from '@master/ui/behaviors/carousel.js'import { useBehavior } from './use-behavior'export interface CarouselItem {  /** What the slide stands for: the carousel's value while it is current. Keep it the same when items move. */  value: string}export interface CarouselProps<T extends CarouselItem> extends Omit<ComponentProps<'div'>, 'children' | 'defaultValue' | 'ref'> {  items: T[]  /** The current slide, as its item's value. The first slide by default. */  value?: string  defaultValue?: string  onValueChange?: (value: string) => void  /** What a slide shows. */  children: (item: T) => ReactNode  /** The accessible name of the track. */  label: string  /** A column that scrolls up and down. */  vertical?: boolean  /** Classes of the track, such as `carousel-2` or `carousel-center`. */  trackClassName?: string  /** Classes of each slide. */  slideClassName?: string  previousLabel?: string  nextLabel?: string  /** The accessible name of a dot. `Slide 2 of 5` by default. */  dotLabel?: (index: number, count: number) => string}const chevron = (turn?: number) => (  <svg className="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform={turn ? `rotate(${turn} 8 8)` : undefined} /></svg>)/** * A carousel whose slide in view the application can read and set. React writes the slides from the items * and the controls beside them; the carousel behavior follows the scroll, marks the current dot and moves the * track through the platform when a control is pressed. */export function Carousel<T extends CarouselItem>({ items, value, defaultValue, onValueChange, children, label, vertical, trackClassName, slideClassName, previousLabel = 'Previous slide', nextLabel = 'Next slide', dotLabel = (index, count) => `Slide ${index + 1} of ${count}`, className, ...root }: CarouselProps<T>) {  const id = useId()  // The first value is drawn into the first render; after that the behavior marks what is current.  const [first] = useState(() => value ?? defaultValue ?? items[0]?.value)  // Drawn into the first render only; after that the behavior marks the buttons, and a render with other items  // does not draw the first state over the one it gave.  const [at] = useState(() => items.findIndex(item => item.value === first))  // The behavior's value is null only for a carousel with no slides, which never reports a change.  const ref = useBehavior<HTMLDivElement, CarouselOptions, string | null>(carousel, { value: first }, { value, defaultValue, onValueChange: onValueChange as ((value: string | null) => void) | undefined })  const track = ['carousel', vertical && 'carousel-vertical', trackClassName].filter(Boolean).join(' ')  return (    <div className={className ? `carousel-view ${className}` : 'carousel-view'} ref={ref} {...root}>      <div className={track} role="region" aria-label={label} tabIndex={0}>        {items.map(item => (          <div className={slideClassName ? `carousel-slide ${slideClassName}` : 'carousel-slide'} id={`${id}${item.value}`} data-value={item.value} key={item.value}>{children(item)}</div>        ))}      </div>      <button type="button" className="btn btn-square btn-sm btn-pill carousel-previous" aria-label={previousLabel} disabled={at <= 0}>{chevron(vertical ? -90 : 180)}</button>      <button type="button" className="btn btn-square btn-sm btn-pill carousel-next" aria-label={nextLabel} disabled={at >= items.length - 1}>{chevron(vertical ? 90 : 0)}</button>      <div className="carousel-dots">        {items.map((item, index) => (          <button type="button" className="carousel-dot" aria-controls={`${id}${item.value}`} aria-label={dotLabel(index, items.length)} aria-current={item.value === first ? 'true' : undefined} key={item.value} />        ))}      </div>    </div>  )}
ui/Carousel.svelte
<script lang="ts" module>  import type { Snippet } from 'svelte'  import type { HTMLAttributes } from 'svelte/elements'  export interface CarouselItem {    /** What the slide stands for: the carousel's value while it is current. Keep it the same when items move. */    value: string  }  export interface CarouselProps<T extends CarouselItem> extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {    items: T[]    /** The current slide, as its item's value. Bind it, or leave it out and the first slide is current. */    value?: string    onValueChange?: (value: string) => void    /** What a slide shows. */    children: Snippet<[T]>    /** The accessible name of the track. */    label: string    /** A column that scrolls up and down. */    vertical?: boolean    /** Classes of the track, such as `carousel-2` or `carousel-center`. */    trackClass?: string    /** Classes of each slide. */    slideClass?: string    previousLabel?: string    nextLabel?: string    /** The accessible name of a dot. `Slide 2 of 5` by default. */    dotLabel?: (index: number, count: number) => string  }</script><script lang="ts" generics="T extends CarouselItem">  import { untrack } from 'svelte'  import { carousel } from '@master/ui/behaviors/carousel.js'  import { behavior } from './behavior.svelte.js'  let { items, value = $bindable(), onValueChange, children, label, vertical, trackClass, slideClass, previousLabel = 'Previous slide', nextLabel = 'Next slide', dotLabel = (index, count) => `Slide ${index + 1} of ${count}`, class: className, ...root }: CarouselProps<T> = $props()  const id = $props.id()  // The first value is drawn into the first render; after that the behavior marks what is current.  const first = untrack(() => value ?? items[0]?.value)  // Drawn into the first render only; after that the behavior marks the buttons and the dots. The first state is  // spread from a constant, so the template's own updates never draw it over the state the behavior gave.  const atStart = { disabled: untrack(() => items.findIndex(item => item.value === first) <= 0) }  const atEnd = { disabled: untrack(() => items.findIndex(item => item.value === first) >= items.length - 1) }  // A dot written later, from new items, is drawn with the slide current then, which is not read as state.  const current = { value: first }  const attach = behavior(carousel, () => ({ value: first }), {    value: () => value,    // The behavior's value is null only for a carousel with no slides, which never reports a change.    change: (next) => { if (next === null) return; current.value = next; value = next; onValueChange?.(next) },    settled: (held) => { if (held !== null) current.value = held },  })</script><!--  @component  A carousel whose slide in view the application can read and set. Svelte writes the slides from the items  and the controls beside them; the carousel behavior follows the scroll, marks the current dot and moves the  track through the platform when a control is pressed.--><div class={['carousel-view', className]} {@attach attach} {...root}>  <!-- The track is a scroll container: in the tab order, so the arrow keys scroll it. -->  <!-- svelte-ignore a11y_no_noninteractive_tabindex -->  <div class={['carousel', vertical && 'carousel-vertical', trackClass]} role="region" aria-label={label} tabindex="0">    {#each items as item (item.value)}      <div class={['carousel-slide', slideClass]} id="{id}{item.value}" data-value={item.value}>{@render children(item)}</div>    {/each}  </div>  <button type="button" class="btn btn-square btn-sm btn-pill carousel-previous" aria-label={previousLabel} {...atStart}>    <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform={vertical ? 'rotate(-90 8 8)' : 'rotate(180 8 8)'} /></svg>  </button>  <button type="button" class="btn btn-square btn-sm btn-pill carousel-next" aria-label={nextLabel} {...atEnd}>    <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" transform={vertical ? 'rotate(90 8 8)' : undefined} /></svg>  </button>  <div class="carousel-dots">    {#each items as item, index (item.value)}      <button type="button" class="carousel-dot" aria-controls="{id}{item.value}" aria-label={dotLabel(index, items.length)} aria-current={item.value === current.value ? 'true' : undefined}></button>    {/each}  </div></div>
ui/Carousel.vue
<script lang="ts">export interface CarouselItem {  /** What the slide stands for: the carousel's value while it is current. Keep it the same when items move. */  value: string}</script><script setup lang="ts" generic="T extends CarouselItem">import { useId, useTemplateRef } from 'vue'import { carousel } from '@master/ui/behaviors/carousel.js'import { useBehavior } from './use-behavior'defineOptions({ inheritAttrs: false })const { items, label, vertical, trackClass, slideClass, previousLabel = 'Previous slide', nextLabel = 'Next slide', dotLabel = (index: number, count: number) => `Slide ${index + 1} of ${count}` } = defineProps<{  /** The slides. An item's `value` is what the slide stands for; keep it the same when items move. */  items: T[]  /** The accessible name of the track. */  label: string  /** A column that scrolls up and down. */  vertical?: boolean  /** Classes of the track, such as `carousel-2` or `carousel-center`. */  trackClass?: string  /** Classes of each slide. */  slideClass?: string  previousLabel?: string  nextLabel?: string  /** The accessible name of a dot. `Slide 2 of 5` by default. */  dotLabel?: (index: number, count: number) => string}>()/** The current slide, as its item's value: `v-model`. */const model = defineModel<string>()defineSlots<{  /** What a slide shows. */  default: (props: { item: T }) => unknown}>()/* * A carousel whose slide in view the application can read and set. Vue writes the slides from the items and * the controls beside them; the carousel behavior follows the scroll, marks the current dot and moves the * track through the platform when a control is pressed. */const id = useId()// The first value is drawn into the first render; after that the behavior marks what is current.const first = model.value ?? items[0]?.valueconst at = items.findIndex(item => item.value === first)const root = useTemplateRef<HTMLDivElement>('root')useBehavior(root, carousel, () => ({ value: first }), model)</script><template>  <div class="carousel-view" ref="root" v-bind="$attrs">    <div class="carousel" :class="[{ 'carousel-vertical': vertical }, trackClass]" role="region" :aria-label="label" tabindex="0">      <div v-for="item in items" :key="item.value" class="carousel-slide" :class="slideClass" :id="`${id}-${item.value}`" :data-value="item.value"><slot :item="item" /></div>    </div>    <button type="button" class="btn btn-square btn-sm btn-pill carousel-previous" :aria-label="previousLabel" :disabled="at <= 0">      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" :transform="vertical ? 'rotate(-90 8 8)' : 'rotate(180 8 8)'" /></svg>    </button>    <button type="button" class="btn btn-square btn-sm btn-pill carousel-next" :aria-label="nextLabel" :disabled="at >= items.length - 1">      <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5" :transform="vertical ? 'rotate(90 8 8)' : undefined" /></svg>    </button>    <div class="carousel-dots">      <button v-for="(item, index) in items" :key="item.value" type="button" class="carousel-dot" :aria-controls="`${id}-${item.value}`" :aria-label="dotLabel(index, items.length)" :aria-current="item.value === first ? 'true' : undefined"></button>    </div>  </div></template>

#클래스

클래스설명
carousel스크롤 스냅이 적용된 트랙입니다. 방향키로 스크롤할 수 있도록 role="region", 레이블, tabindex="0"을 지정하세요
carousel-slide슬라이드는 트랙의 시작 위치에 스냅하며, carousel-center에서는 트랙 중앙에 스냅합니다. 슬라이드 너비는 트랙 너비를 기준으로 --carousel-slide가 정합니다
carousel-2슬라이드 2개 표시적용할 클래스는 carousel입니다
carousel-3슬라이드 3개 표시적용할 클래스는 carousel입니다
carousel-center현재 슬라이드는 중앙에 놓이고 양옆으로 인접 슬라이드의 가장자리가 보입니다. 첫 슬라이드와 마지막 슬라이드도 중앙까지 이동합니다. --carousel-slide에 별도 값을 지정하지 않으면 각 슬라이드는 트랙 너비의 80%를 차지합니다적용할 클래스는 carousel입니다
carousel-vertical높이가 --carousel-viewport인 세로 열로, 위아래로 스크롤하고 스냅합니다. 슬라이드는 높이의 --carousel-slide만큼을 차지하며, 버튼은 위쪽과 아래쪽에, 점은 끝 가장자리 옆에 놓입니다.적용할 클래스는 carousel입니다
carousel-view페이지에서 직접 작성한 이전·다음 버튼과 점을 캐러셀과 함께 담으며, carousel 동작이 이를 제어합니다. 이 안에서는 생성된 컨트롤이 물러납니다.
carousel-previous현재 슬라이드의 이전 슬라이드로 이동합니다. 트랙의 시작 가장자리 위에, 세로 뷰에서는 위쪽에 놓입니다. 첫 번째 슬라이드에서는 비활성화됩니다.
carousel-next현재 슬라이드의 다음 슬라이드로 이동합니다. 트랙의 끝 가장자리 위에, 세로 뷰에서는 아래쪽에 놓입니다. 마지막 슬라이드에서는 비활성화됩니다.
carousel-dots트랙 아래의 점 행이며, 세로 캐러셀에서는 그 옆의 점 열입니다
carousel-dotaria-controls에 지정된 슬라이드로 이동합니다. 접근 가능한 이름은 전체 슬라이드 중 몇 번째 슬라이드인지 알려 줍니다.

#사용자 지정 속성

속성기본값설명
--carousel-gap1rem슬라이드 사이 간격
--carousel-slide100%슬라이드 너비입니다. carousel-center에서는 기본값이 80%입니다. 인접 슬라이드가 일부 보이도록 원하는 너비를 지정할 수 있습니다.
--carousel-viewport20rem세로 캐러셀의 높이carousel-vertical에 설정합니다
--carousel-control2rem브라우저가 그리는 이전 및 다음 버튼의 크기입니다.
--carousel-previous-label브라우저가 그리는 이전 버튼의 이름을 따옴표로 묶은 문자열로 지정합니다. 설정하지 않으면 'Previous slide'입니다. 캐러셀이나 상위 요소에 페이지 언어로 설정하세요.
--carousel-next-label브라우저가 그리는 다음 버튼의 이름을 따옴표로 묶은 문자열로 지정합니다. 설정하지 않으면 'Next slide'입니다.

#소스

@master/ui/components/carousel.css
/* * Carousel: a row of slides that scrolls and snaps, built from CSS alone. * The track is a scroll container with scroll snapping, so touch, trackpad, keys and assistive technology * all work as scrolling does. Where the browser supports them, ::scroll-button() adds previous and next * buttons and ::scroll-marker adds a dot per slide that follows the scroll position; both are real, * focusable controls the browser generates, named by --carousel-previous-label and --carousel-next-label, so a * page names them in its own language. Elsewhere the carousel is a swipeable, scrollable row with a thin scrollbar. * carousel-vertical turns the row into a column --carousel-viewport tall, with its buttons above and below. * * A carousel-view holds a track and controls of the page's own: previous and next buttons and a row of dots, * which the carousel behavior drives, so a page or a framework can read and set the slide in view. Inside a * view the generated controls step aside, so there is never a second set of buttons. */@layer components.ui {  .carousel {    --carousel-gap: 1rem;    --carousel-slide: 100%;    --carousel-control: 2rem;    /* A neutral mid-grey chevron reads on moonstone and obsidian alike. */    --carousel-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23777' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 3.5L10.3586 7.8586A0.2 0.2 0 0 1 10.3586 8.1414L6 12.5'/%3E%3C/svg%3E");    position: relative;    display: flex;    gap: var(--carousel-gap);    min-width: 0;    margin: 0;    padding: 0;    overflow: auto hidden;    overscroll-behavior-x: contain;    list-style: none;    scroll-snap-type: x mandatory;    scroll-behavior: smooth;    /*     * Without generated buttons, a thin scrollbar is the way across for a mouse that cannot swipe. Where the browser     * draws the buttons and the dots, or in a view with buttons of the page's own, the scrollbar steps aside.     */    scrollbar-width: thin;    scrollbar-color: var(--color-line-strong) transparent;    .carousel-view & {      scrollbar-width: none;    }    .carousel-view &::-webkit-scrollbar {      display: none;    }    &:focus-visible {      @apply --focus-ring;    }    @media (prefers-reduced-motion: reduce) {      scroll-behavior: auto;    }    /*     * Centered: the slide in view stands in the middle and its neighbors show an edge on either side. Room before     * the first slide and after the last lets both reach the middle too. That room is two empty flex items, not     * padding: a percentage in a slide is read from the track less its padding, so padding would shrink the slide     * it is measured from. A flex item's percentage is read from the whole track, as the slide's is.     */    &.carousel-center {      --carousel-slide: 80%;      &::before, &::after {        content: '';        flex: 0 0 max(0px, calc((100% - var(--carousel-slide)) / 2 - var(--carousel-gap)));      }      .carousel-slide {        scroll-snap-align: center;      }    }    /*     * Vertical: a column of slides --carousel-viewport tall that scrolls and snaps up and down. A slide takes     * --carousel-slide of the height; the buttons stand at the middle of the top and the bottom edges, and the     * dots in a column beside the end edge.     */    &.carousel-vertical {      --carousel-viewport: 20rem;      flex-direction: column;      height: var(--carousel-viewport);      overflow: hidden auto;      overscroll-behavior: auto contain;      scroll-snap-type: y mandatory;      .carousel-slide {        min-height: 0;      }    }    @supports selector(::scroll-marker) {      scrollbar-width: none;      &::-webkit-scrollbar {        display: none;      }      /* Room under the track for the markers, which sit on the carousel's own edge. */      margin-block-end: 1.75rem;      /* The controls anchor to their own carousel: the name is scoped, so several on a page do not share it. */      anchor-name: --carousel;      anchor-scope: --carousel;      scroll-marker-group: after;      /*       * The dots: a row centered under the track. Each dot is padded into a larger target, so the row has no gap of       * its own: the padding on either side of a dot is the space between them, and the dot stays .75rem under the track.       */      &::scroll-marker-group {        position: fixed;        position-anchor: --carousel;        top: calc(anchor(bottom) + .5625rem);        left: anchor(left);        right: anchor(right);        display: flex;        justify-content: center;        /* A finger's dots are padded to 24px: the row moves up by the extra padding, so each dot stays where it was. */        @media (pointer: coarse) {          top: calc(anchor(bottom) + .1875rem);        }      }      /* Previous and next: small raised squares on the track's edges, at its middle. */      &::scroll-button(inline-start), &::scroll-button(inline-end) {        position: fixed;        position-anchor: --carousel;        top: calc(anchor(center) - var(--carousel-control) / 2);        display: grid;        place-items: center;        width: var(--carousel-control);        height: var(--carousel-control);        padding: 0;        border: 0;        border-radius: 999px;        background: var(--carousel-chevron) center / .875rem no-repeat, var(--color-surface-floating);        box-shadow: var(--shadow-raised);        cursor: pointer;        touch-action: manipulation;        -webkit-tap-highlight-color: transparent;        transition: box-shadow var(--duration-quick) var(--easing-glide), opacity var(--duration-quick) var(--easing-glide), visibility var(--duration-quick);      }      &::scroll-button(inline-start) {        content: '' / var(--carousel-previous-label, 'Previous slide');        left: calc(anchor(left) + .5rem);        scale: -1 1;      }      &::scroll-button(inline-end) {        content: '' / var(--carousel-next-label, 'Next slide');        right: calc(anchor(right) + .5rem);      }      /* Where slides run from the right, previous is on the right and both chevrons turn round. */      &:dir(rtl)::scroll-button(inline-start) {        right: calc(anchor(right) + .5rem);        left: auto;        scale: none;      }      &:dir(rtl)::scroll-button(inline-end) {        right: auto;        left: calc(anchor(left) + .5rem);        scale: -1 1;      }      @media (hover: hover) {        &::scroll-button(inline-start):hover, &::scroll-button(inline-end):hover {          box-shadow: var(--shadow-raised-hover);        }      }      /* Pressed, the button sinks into the well, as every raised control does. */      &::scroll-button(inline-start):active:not(:disabled), &::scroll-button(inline-end):active:not(:disabled) {        background: var(--carousel-chevron) center / .875rem no-repeat, var(--color-surface-inset);        box-shadow: var(--shadow-pressed);      }      &::scroll-button(inline-start):focus-visible, &::scroll-button(inline-end):focus-visible {        outline: 2px solid var(--color-focus);        outline-offset: 2px;      }      /* A column: its buttons go up and down at the middle of its top and bottom edges, its dots down its end. */      &.carousel-vertical {        margin-block-end: 0;        margin-inline-end: 1.75rem;        &::scroll-marker-group {          top: anchor(top);          bottom: anchor(bottom);          left: calc(anchor(right) + .5625rem);          right: auto;          flex-direction: column;          justify-content: center;        }        &:dir(rtl)::scroll-marker-group {          left: auto;          right: calc(anchor(left) + .5625rem);        }        /* A finger's dots are padded to 24px: the column moves in by the extra padding, so each dot stays where it was. */        @media (pointer: coarse) {          &::scroll-marker-group {            left: calc(anchor(right) + .1875rem);          }          &:dir(rtl)::scroll-marker-group {            left: auto;            right: calc(anchor(left) + .1875rem);          }        }        &::scroll-button(block-start), &::scroll-button(block-end) {          position: fixed;          position-anchor: --carousel;          left: calc(anchor(center) - var(--carousel-control) / 2);          display: grid;          width: var(--carousel-control);          height: var(--carousel-control);          padding: 0;          border: 0;          border-radius: 999px;          background: var(--carousel-chevron) center / .875rem no-repeat, var(--color-surface-floating);          box-shadow: var(--shadow-raised);          cursor: pointer;          touch-action: manipulation;          -webkit-tap-highlight-color: transparent;          transition: box-shadow var(--duration-quick) var(--easing-glide), opacity var(--duration-quick) var(--easing-glide), visibility var(--duration-quick);        }        &::scroll-button(block-start) {          content: '' / var(--carousel-previous-label, 'Previous slide');          top: calc(anchor(top) + .5rem);          rotate: -90deg;        }        &::scroll-button(block-end) {          content: '' / var(--carousel-next-label, 'Next slide');          top: calc(anchor(bottom) - .5rem - var(--carousel-control));          rotate: 90deg;        }        @media (hover: hover) {          &::scroll-button(block-start):hover, &::scroll-button(block-end):hover {            box-shadow: var(--shadow-raised-hover);          }        }        &::scroll-button(block-start):active:not(:disabled), &::scroll-button(block-end):active:not(:disabled) {          background: var(--carousel-chevron) center / .875rem no-repeat, var(--color-surface-inset);          box-shadow: var(--shadow-pressed);        }        &::scroll-button(block-start):focus-visible, &::scroll-button(block-end):focus-visible {          outline: 2px solid var(--color-focus);          outline-offset: 2px;        }        &::scroll-button(block-start):disabled, &::scroll-button(block-end):disabled,        &::scroll-button(inline-start), &::scroll-button(inline-end) {          opacity: 0;          visibility: hidden;          cursor: default;        }      }      /* In a view the page's own controls drive the track: the generated ones step aside. */      .carousel-view & {        margin: 0;        scroll-marker-group: none;        &::scroll-button(*) {          content: none;        }      }      /*       * At either end there is nowhere to go: the button fades out and then leaves, so it no longer covers what the       * slide under it holds.       */      &::scroll-button(inline-start):disabled, &::scroll-button(inline-end):disabled {        opacity: 0;        visibility: hidden;        cursor: default;      }    }    /* Shadows vanish in forced colors: an outline draws the buttons' edge without changing their size. */    @media (forced-colors: active) {      &::scroll-button(inline-start), &::scroll-button(inline-end), &::scroll-button(block-start), &::scroll-button(block-end) {        outline: 1px solid ButtonText;        outline-offset: -1px;      }    }  }  /*   * A view: the track, with the page's previous and next buttons over its edges and its dots under it. The   * buttons stand in the track's own cell, so they keep to its middle at any height; at either end the behavior   * disables the one that has nowhere to go, and it fades out of the way.   */  .carousel-view {    position: relative;    /* Its buttons stand over the track inside the view, not over a sticky header that scrolls past it. */    isolation: isolate;    display: grid;    grid-template: 'track' minmax(0, auto) 'dots' auto / minmax(0, 1fr);    min-width: 0;    .carousel {      grid-area: track;    }  }  .carousel-previous, .carousel-next {    z-index: 1;    grid-area: track;    align-self: center;    margin-inline: .5rem;    transition-property: box-shadow, translate, color, opacity, visibility;    &:disabled {      opacity: 0;      visibility: hidden;    }  }  .carousel-previous {    justify-self: start;  }  .carousel-next {    justify-self: end;  }  /*   * Back and on point the way the slides run: where they run from the right, previous stands on the right and the   * chevrons turn round. An up or down chevron of a vertical view is the same either way.   */  .carousel-previous, .carousel-next {    &:dir(rtl) {      scale: -1 1;    }  }  /* A vertical view: the buttons at the middle of the top and the bottom, the dots in a column at the end. */  .carousel-view:has(.carousel-vertical) {    grid-template: 'track dots' auto / minmax(0, 1fr) auto;    .carousel-previous, .carousel-next {      justify-self: center;      margin: .5rem 0;    }    .carousel-previous {      align-self: start;    }    .carousel-next {      align-self: end;    }    .carousel-dots {      flex-direction: column;      padding: 0;      padding-inline-start: .5625rem;      @media (pointer: coarse) {        padding-inline-start: .1875rem;      }    }  }  /*   * The dots: one button for each slide, centered under the track, the one in view lengthened and in ink. Each   * dot stands .75rem from the track, as the browser's own do.   */  .carousel-dots {    grid-area: dots;    display: flex;    justify-content: center;    align-items: center;    padding-block-start: .5625rem;    /* A finger's dots carry .375rem more padding: the row gives it back, so the dots stay where they were. */    @media (pointer: coarse) {      padding-block-start: .1875rem;    }  }  .carousel-dot {    display: block;    box-sizing: content-box;    width: .375rem;    height: .375rem;    margin: 0;    padding: .1875rem;    border: 0;    border-radius: 999px;    corner-shape: round;    background: var(--color-line-mark) content-box;    appearance: none;    cursor: pointer;    touch-action: manipulation;    -webkit-tap-highlight-color: transparent;    transition: width var(--duration-base) var(--easing-glide), height var(--duration-base) var(--easing-glide), background-color var(--duration-quick) var(--easing-glide);    /* Packed edge to edge, a dot is its own target: on touch it is padded to 24px, the floor, and the dot stays 6px. */    @media (pointer: coarse) {      padding: .5625rem;    }    @media (hover: hover) {      &:hover {        background-color: var(--color-text-muted);      }    }    &[aria-current="true"] {      width: 1rem;      background-color: var(--color-text-strong);      cursor: default;      .carousel-view:has(.carousel-vertical) & {        width: .375rem;        height: 1rem;      }    }    &:focus-visible {      outline: 2px solid var(--color-focus);      outline-offset: 0;    }    @media (prefers-reduced-motion: reduce) {      transition-property: background-color;    }    /* The dots keep system colors of their own, so their hover and their focus ring are system colors too. */    @media (forced-colors: active) {      forced-color-adjust: none;      background-color: GrayText;      @media (hover: hover) {        &:hover {          background-color: CanvasText;        }      }      &[aria-current="true"] {        background-color: Highlight;      }      &:focus-visible {        outline-color: Highlight;      }    }  }  /* A slide: it snaps to the start of the track and takes --carousel-slide of its width. */  .carousel-slide {    flex: 0 0 var(--carousel-slide);    min-width: 0;    scroll-snap-align: start;    @supports selector(::scroll-marker) {      /*       * A 6px dot painted in the middle of its padding, which is the target and the space beside it. The padding is       * even on every side: the round corner less the padding is what rounds the dot, so it stays a dot and a pill.       */      &::scroll-marker {        content: '';        box-sizing: content-box;        width: .375rem;        height: .375rem;        padding: .1875rem;        border-radius: 999px;        corner-shape: round;        background: var(--color-line-mark) content-box;        cursor: pointer;        -webkit-tap-highlight-color: transparent;        transition: width var(--duration-base) var(--easing-glide), height var(--duration-base) var(--easing-glide), background-color var(--duration-quick) var(--easing-glide);        /* On a touch screen the target grows to 24px, the floor for a target that cannot reach past itself; the dot does not. */        @media (pointer: coarse) {          padding: .5625rem;        }        @media (prefers-reduced-motion: reduce) {          transition-property: background-color;        }      }      @media (hover: hover) {        &::scroll-marker:hover {          background-color: var(--color-text-muted);        }      }      /* The slide in view: the dot lengthens and takes ink. */      &::scroll-marker:target-current {        width: 1rem;        background-color: var(--color-text-strong);        cursor: default;      }      /* In a column of dots the one in view lengthens down the column, as a view's own dot does. */      .carousel-vertical &::scroll-marker:target-current {        width: .375rem;        height: 1rem;      }      &::scroll-marker:focus-visible {        outline: 2px solid var(--color-focus);        outline-offset: 0;      }      /* The dots keep their system colors, and the one in view its highlight, instead of the forced canvas. */      @media (forced-colors: active) {        &::scroll-marker {          forced-color-adjust: none;          background-color: GrayText;        }        @media (hover: hover) {          &::scroll-marker:hover {            background-color: CanvasText;          }        }        &::scroll-marker:target-current {          background-color: Highlight;        }        &::scroll-marker:focus-visible {          outline-color: Highlight;        }      }    }  }  /* Several slides in view: each takes a share of the track, less the gaps between them. */  .carousel-2 {    --carousel-slide: calc((100% - var(--carousel-gap)) / 2);  }  .carousel-3 {    --carousel-slide: calc((100% - var(--carousel-gap) * 2) / 3);  }}