탐색
목차
페이지 안의 각 제목을 링크로 나열하고 화면에 보이는 섹션을 CSS로 표시하는 목차입니다.
이 페이지의 내용
목차는 페이지 안의 각 제목을 링크로 만들어 가느다란 세로선 옆에 한 줄씩 나열합니다. 화면에 보이는 섹션의 링크는 잉크색으로 표시되며, 세로선 위의 표시가 링크 사이를 부드럽게 이동합니다. 브라우저가 scroll-target-group을 지원하면 페이지가 현재 섹션을 자동으로 표시합니다. 목록이 스크롤 위치를 추적하고, 대상 섹션이 화면에 보이는 링크가 :target-current 선택자와 일치합니다. 옵저버나 스크립트가 필요 없습니다.
목차
<div class="grid grid-cols(2) gap-lg"> <div class="h(240) overflow-y-auto scroll-area text-sm leading-md fg-text-body"> <h3 class="m(0) fg-text-strong" id="toc-install">Install</h3> <p> Add the package and import it after the preset. The stylesheet has no build step of its own. </p> <p>It ships as plain CSS files, one per component.</p> <h3 class="fg-text-strong" id="toc-theme">Theme</h3> <p> Moonstone and obsidian share one set of tokens. Override a token and every component follows. </p> <p>The brand color is one token.</p> <h3 class="fg-text-strong" id="toc-corners">Corners</h3> <p> Corners turn with continuous curvature where the browser can draw them, and nest by their inset. </p> <p>Elsewhere they are circular.</p> <h3 class="fg-text-strong" id="toc-motion">Motion</h3> <p> One easing family. Interaction is quick, explanation calm, and reduced motion keeps the fade. </p> <p class="mb(160)">That is the whole system.</p> </div> <nav class="toc self-start" aria-label="On this page"> <p class="toc-title">On this page</p> <ul class="toc-list"> <li><a class="toc-link" href="#toc-install">Install</a></li> <li><a class="toc-link" href="#toc-theme">Theme</a></li> <li><a class="toc-link" href="#toc-corners">Corners</a></li> <li><a class="toc-link" href="#toc-motion">Motion</a></li> </ul> </nav></div><div className="grid grid-cols(2) gap-lg"> <div className="h(240) overflow-y-auto scroll-area text-sm leading-md fg-text-body"> <h3 className="m(0) fg-text-strong" id="toc-install">Install</h3> <p> Add the package and import it after the preset. The stylesheet has no build step of its own. </p> <p>It ships as plain CSS files, one per component.</p> <h3 className="fg-text-strong" id="toc-theme">Theme</h3> <p> Moonstone and obsidian share one set of tokens. Override a token and every component follows. </p> <p>The brand color is one token.</p> <h3 className="fg-text-strong" id="toc-corners">Corners</h3> <p> Corners turn with continuous curvature where the browser can draw them, and nest by their inset. </p> <p>Elsewhere they are circular.</p> <h3 className="fg-text-strong" id="toc-motion">Motion</h3> <p> One easing family. Interaction is quick, explanation calm, and reduced motion keeps the fade. </p> <p className="mb(160)">That is the whole system.</p> </div> <nav className="toc self-start" aria-label="On this page"> <p className="toc-title">On this page</p> <ul className="toc-list"> <li><a className="toc-link" href="#toc-install">Install</a></li> <li><a className="toc-link" href="#toc-theme">Theme</a></li> <li><a className="toc-link" href="#toc-corners">Corners</a></li> <li><a className="toc-link" href="#toc-motion">Motion</a></li> </ul> </nav></div><div class="grid grid-cols(2) gap-lg"> <div class="h(240) overflow-y-auto scroll-area text-sm leading-md fg-text-body"> <h3 class="m(0) fg-text-strong" id="toc-install">Install</h3> <p> Add the package and import it after the preset. The stylesheet has no build step of its own. </p> <p>It ships as plain CSS files, one per component.</p> <h3 class="fg-text-strong" id="toc-theme">Theme</h3> <p> Moonstone and obsidian share one set of tokens. Override a token and every component follows. </p> <p>The brand color is one token.</p> <h3 class="fg-text-strong" id="toc-corners">Corners</h3> <p> Corners turn with continuous curvature where the browser can draw them, and nest by their inset. </p> <p>Elsewhere they are circular.</p> <h3 class="fg-text-strong" id="toc-motion">Motion</h3> <p> One easing family. Interaction is quick, explanation calm, and reduced motion keeps the fade. </p> <p class="mb(160)">That is the whole system.</p> </div> <nav class="toc self-start" aria-label="On this page"> <p class="toc-title">On this page</p> <ul class="toc-list"> <li><a class="toc-link" href="#toc-install">Install</a></li> <li><a class="toc-link" href="#toc-theme">Theme</a></li> <li><a class="toc-link" href="#toc-corners">Corners</a></li> <li><a class="toc-link" href="#toc-motion">Motion</a></li> </ul> </nav></div><template> <div class="grid grid-cols(2) gap-lg"> <div class="h(240) overflow-y-auto scroll-area text-sm leading-md fg-text-body"> <h3 class="m(0) fg-text-strong" id="toc-install">Install</h3> <p> Add the package and import it after the preset. The stylesheet has no build step of its own. </p> <p>It ships as plain CSS files, one per component.</p> <h3 class="fg-text-strong" id="toc-theme">Theme</h3> <p> Moonstone and obsidian share one set of tokens. Override a token and every component follows. </p> <p>The brand color is one token.</p> <h3 class="fg-text-strong" id="toc-corners">Corners</h3> <p> Corners turn with continuous curvature where the browser can draw them, and nest by their inset. </p> <p>Elsewhere they are circular.</p> <h3 class="fg-text-strong" id="toc-motion">Motion</h3> <p> One easing family. Interaction is quick, explanation calm, and reduced motion keeps the fade. </p> <p class="mb(160)">That is the whole system.</p> </div> <nav class="toc self-start" aria-label="On this page"> <p class="toc-title">On this page</p> <ul class="toc-list"> <li><a class="toc-link" href="#toc-install">Install</a></li> <li><a class="toc-link" href="#toc-theme">Theme</a></li> <li><a class="toc-link" href="#toc-corners">Corners</a></li> <li><a class="toc-link" href="#toc-motion">Motion</a></li> </ul> </nav> </div></template>본문을 스크롤하면 표시가 화면에 보이는 섹션을 따라갑니다. scroll-target-group을 지원하지 않는 브라우저에서는 스크립트가 aria-current를 설정해야 표시가 나타납니다.
#목차 계층
목록 항목 안에 toc-list를 넣으면 한 단계 더 깊은 계층이 됩니다. 같은 세로선을 공유하며 링크는 한 단계 들여씁니다. 한 페이지에는 두 단계면 충분합니다. 세 번째 단계가 필요하다면 페이지를 나눌 시점입니다.
목차 계층
<nav class="toc max-w(220)" aria-label="On this page"> <ul class="toc-list"> <li><a class="toc-link" href="#">Overview</a></li> <li> <a class="toc-link" href="#" aria-current="true">Theme</a> <ul class="toc-list"> <li><a class="toc-link" href="#">Surfaces</a></li> <li><a class="toc-link" href="#">Lines and shadows</a></li> <li><a class="toc-link" href="#">The brand color</a></li> </ul> </li> <li><a class="toc-link" href="#">Accessibility</a></li> </ul></nav><nav className="toc max-w(220)" aria-label="On this page"> <ul className="toc-list"> <li><a className="toc-link" href="#">Overview</a></li> <li> <a className="toc-link" href="#" aria-current="true">Theme</a> <ul className="toc-list"> <li><a className="toc-link" href="#">Surfaces</a></li> <li><a className="toc-link" href="#">Lines and shadows</a></li> <li><a className="toc-link" href="#">The brand color</a></li> </ul> </li> <li><a className="toc-link" href="#">Accessibility</a></li> </ul></nav><nav class="toc max-w(220)" aria-label="On this page"> <ul class="toc-list"> <li><a class="toc-link" href="#">Overview</a></li> <li> <a class="toc-link" href="#" aria-current="true">Theme</a> <ul class="toc-list"> <li><a class="toc-link" href="#">Surfaces</a></li> <li><a class="toc-link" href="#">Lines and shadows</a></li> <li><a class="toc-link" href="#">The brand color</a></li> </ul> </li> <li><a class="toc-link" href="#">Accessibility</a></li> </ul></nav><template> <nav class="toc max-w(220)" aria-label="On this page"> <ul class="toc-list"> <li><a class="toc-link" href="#">Overview</a></li> <li> <a class="toc-link" href="#" aria-current="true">Theme</a> <ul class="toc-list"> <li><a class="toc-link" href="#">Surfaces</a></li> <li><a class="toc-link" href="#">Lines and shadows</a></li> <li><a class="toc-link" href="#">The brand color</a></li> </ul> </li> <li><a class="toc-link" href="#">Accessibility</a></li> </ul> </nav></template>#현재 섹션 직접 표시
링크에 aria-current="true"를 지정하면 :target-current 선택자와 일치할 때와 같은 상태로 표시됩니다. 정적 목록에서는 서버에서 설정하고, scroll-target-group을 지원하지 않는 환경에서는 IntersectionObserver로 설정하세요. 둘 다 적용하면 화면에 보이는 같은 섹션을 기준으로 하므로 표시가 일치합니다.
#접근성
- 목록은
<nav>이며, ‘이 페이지의 목차’와 같은 레이블을 붙입니다. 이렇게 하면 페이지의 랜드마크에서 목차를 찾고 주 탐색 영역과 구별할 수 있습니다. - 링크는
id를 통해 해당 제목으로 이동합니다. 스크롤 영역 상단에 내비게이션 바가 고정되어 있다면, 이동한 제목이 내비게이션 바에 가리지 않도록 스크롤 영역에scroll-padding-top을 지정하세요. - 현재 링크의 잉크색이 바뀌고, 그 옆에 1.5px 두께의 잉크색 표시가 나타납니다. 두 변화 모두 색상 계열의 차이에 의존하지 않습니다. 동작 줄이기가 설정되어 있으면 표시가 애니메이션 없이 이동합니다.
#클래스
| 클래스 | 설명 |
|---|---|
toc | "이 페이지의 목차"와 같은 레이블을 지정한 nav 요소에 적용하는 컨테이너입니다. 스크롤 대상 그룹으로 동작합니다. |
toc-title | 목록 위의 캡션 |
toc-list | 가는 레일을 따라 배치된 링크 목록입니다. 목록 항목 안의 toc-list는 하위 단계입니다. 같은 레일을 공유하고 링크는 한 단계 들여씁니다. |
toc-link | 제목의 id로 연결되는 링크입니다. 현재 화면에 보이는 섹션의 링크는 기본 글자색으로 강조하고 레일에 표시를 붙입니다. |
#사용자 지정 속성
| 속성 | 기본값 | 설명 |
|---|---|---|
--toc-indent | .875rem | 레일과 텍스트 사이의 간격이자 한 단계의 들여쓰기 너비 |