ナビゲーション

v2.1.0
フィードバック

スケルトン

読み込み中のコンテンツの形を先に表示し、表示されたときにページがずれないようにします。

このページの内容

スケルトンは、読み込み中のコンテンツと同じ形の仮表示で、読み込みが完了したときにページのレイアウトがずれるのを防ぎます。チップと同じ色調のブロックに、やわらかな光の帯が流れます。ブラウザーがsibling-index()に対応している場合、同じブロック内のスケルトンが順番に動き始め、1本の光がブロック全体を上から下へ通過するように見えます。それぞれ、置き換えるコンテンツと同じサイズにします。表示済みのコンテンツを再取得する場合はビジー状態を使います。

スケルトン

<section class="flex items-center gap-sm" aria-busy="true" aria-label="Loading member">  <span class="skeleton skeleton-circle w(40)" aria-hidden="true"></span>  <div class="flex flex-col w-full text-sm" aria-hidden="true">    <span class="skeleton skeleton-text max-w(160)"></span>    <span class="skeleton skeleton-text max-w(320)"></span>  </div></section>
<section className="flex items-center gap-sm" aria-busy="true" aria-label="Loading member">  <span className="skeleton skeleton-circle w(40)" aria-hidden="true"></span>  <div className="flex flex-col w-full text-sm" aria-hidden="true">    <span className="skeleton skeleton-text max-w(160)"></span>    <span className="skeleton skeleton-text max-w(320)"></span>  </div></section>
<section class="flex items-center gap-sm" aria-busy="true" aria-label="Loading member">  <span class="skeleton skeleton-circle w(40)" aria-hidden="true"></span>  <div class="flex flex-col w-full text-sm" aria-hidden="true">    <span class="skeleton skeleton-text max-w(160)"></span>    <span class="skeleton skeleton-text max-w(320)"></span>  </div></section>
<template>  <section class="flex items-center gap-sm" aria-busy="true" aria-label="Loading member">    <span class="skeleton skeleton-circle w(40)" aria-hidden="true"></span>    <div class="flex flex-col w-full text-sm" aria-hidden="true">      <span class="skeleton skeleton-text max-w(160)"></span>      <span class="skeleton skeleton-text max-w(320)"></span>    </div>  </section></template>

#形状

  • skeletonを単独で使うとブロックになります。画像、グラフ、カードなど、置き換える要素と同じ高さを指定します。
  • skeleton-textは1行のテキストを表します。文字と同じ高さで行の中央に配置されるため、読み込み後のテキストも同じベースライングリッドに揃います。周囲のフォントサイズと行の高さに従います。
  • skeleton-circleはアバターやアイコンに使います。幅を指定すると、高さもそれに合わせて決まります。

読み込み中のカード

<article class="card max-w(320) mx-auto" aria-busy="true" aria-label="Loading project">  <span class="skeleton card-media" aria-hidden="true"></span>  <div class="flex flex-col" aria-hidden="true">    <span class="skeleton skeleton-text max-w(160)"></span>    <span class="skeleton skeleton-text"></span>    <span class="skeleton skeleton-text max-w(240)"></span>  </div></article>
<article className="card max-w(320) mx-auto" aria-busy="true" aria-label="Loading project">  <span className="skeleton card-media" aria-hidden="true"></span>  <div className="flex flex-col" aria-hidden="true">    <span className="skeleton skeleton-text max-w(160)"></span>    <span className="skeleton skeleton-text"></span>    <span className="skeleton skeleton-text max-w(240)"></span>  </div></article>
<article class="card max-w(320) mx-auto" aria-busy="true" aria-label="Loading project">  <span class="skeleton card-media" aria-hidden="true"></span>  <div class="flex flex-col" aria-hidden="true">    <span class="skeleton skeleton-text max-w(160)"></span>    <span class="skeleton skeleton-text"></span>    <span class="skeleton skeleton-text max-w(240)"></span>  </div></article>
<template>  <article class="card max-w(320) mx-auto" aria-busy="true" aria-label="Loading project">    <span class="skeleton card-media" aria-hidden="true"></span>    <div class="flex flex-col" aria-hidden="true">      <span class="skeleton skeleton-text max-w(160)"></span>      <span class="skeleton skeleton-text"></span>      <span class="skeleton skeleton-text max-w(240)"></span>    </div>  </article></template>

#アクセシビリティ

  • スケルトンはaria-hidden="true"で支援技術から隠し、その配置先の領域にはaria-busy="true"と、何を読み込んでいるかを示すラベルを指定します。
  • 動きを抑える設定が有効な場合、光の帯は動かず、形だけでコンテンツが読み込み中であることを示します。
  • スケルトンは、待ち時間に利用者が気づきそうな場合にだけ表示します。ごく短い待ち時間には何も表示せず、ボタンの処理中表示にはaria-busyとスピナーを使います。

#クラス

クラス説明
skeletonブロック状のプレースホルダーです。あとで表示する画像、グラフ、カードと同じ高さに設定します。
skeleton-textテキスト1行分のプレースホルダーです。文字と同じ高さにし、対応する行の中央に配置します。skeleton と併用します
skeleton-circleアバターやアイコン用の円です。サイズは幅で指定します。skeleton と併用します

#ソース

@master/ui/components/skeleton.css
/* * Skeleton: the shape of content that is on its way. * A chip-toned block that a soft band of light crosses; with reduced motion it rests. * Hide it from assistive technology and mark the loading region with aria-busy. */@layer components.ui {  .skeleton {    display: block;    min-height: .75rem;    border-radius: calc(var(--radius-chip) * var(--corner-scale));    corner-shape: var(--corner-shape);    background:      linear-gradient(100deg, transparent 35%, var(--color-sheen) 50%, transparent 65%) 150% 0 / 300% 100% no-repeat,      var(--color-surface-chip);    color: transparent;    user-select: none;    -webkit-user-select: none;    pointer-events: none;    animation: skeleton-sweep 1.8s var(--easing-smooth) infinite;    /* The band crosses the way the words it stands for are read: from the right where they run from the right. */    &:dir(rtl) {      animation-direction: reverse;    }    /* One line of text: the block is as tall as the letters, centered in the line it stands for. */    &.skeleton-text {      height: .75em;      min-height: 0;      margin-block: calc((1lh - .75em) / 2);      border-radius: calc((var(--radius-chip) - 2px) * var(--corner-scale));    }    &.skeleton-circle {      aspect-ratio: 1;      border-radius: 999px;      corner-shape: round;    }    /* Lines in one block start one after another, so the band of light runs down the block as a single pass. */    @supports (width: calc(sibling-index() * 1px)) {      animation-delay: calc((sibling-index() - 1) * 90ms);    }    @media (prefers-reduced-motion: reduce) {      animation: none;    }    @media (forced-colors: active) {      outline: 1px solid GrayText;      outline-offset: -1px;    }  }}@keyframes skeleton-sweep {  to {    background-position: -50% 0, 0 0;  }}