ナビゲーション

v2.1.0
本文

スレッド

コメントと返信を表示し、各返信を返信先のコメントと線で結びます。

このページの内容

スレッドは、ドキュメントやレビュー、Issue に寄せられたコメントと返信をまとめたものです。各コメントでは、アバターを配置する列を設け、その横に本文を表示します。返信は本文の下に並び、返信先のアバターから伸びる細い線が各返信へ折れ曲がります。インデントを見比べなくても、線をたどれば返信先がわかります。

スレッド

<div class="card max-w(480) mx-auto">  <ol class="thread">    <li class="thread-item">      <span class="thread-avatar"><span class="avatar">AL</span></span>      <div class="thread-body">        <p class="thread-header">          <span class="thread-author">Ada Lovelace</span>          <time class="thread-meta" datetime="2026-11-12T09:12Z">2h</time>        </p>        <p class="thread-text">The focus ring is cut by the mask. Should it move to the group?</p>      </div>      <ol class="thread-replies">        <li class="thread-item">          <span class="thread-avatar"><span class="avatar avatar-sm">AT</span></span>          <div class="thread-body">            <p class="thread-header">              <span class="thread-author">Alan Turing</span>              <time class="thread-meta" datetime="2026-11-12T10:05Z">1h</time>            </p>            <p class="thread-text">              Yes. The group already has the corner, so the ring follows it.            </p>          </div>        </li>        <li class="thread-item">          <span class="thread-avatar"><span class="avatar avatar-sm">GH</span></span>          <div class="thread-body">            <p class="thread-header">              <span class="thread-author">Grace Hopper</span>              <time class="thread-meta" datetime="2026-11-12T10:31Z">35m</time>            </p>            <p class="thread-text">I will make the change this afternoon.</p>          </div>        </li>      </ol>    </li>    <li class="thread-item">      <span class="thread-avatar"><span class="avatar">KJ</span></span>      <div class="thread-body">        <p class="thread-header">          <span class="thread-author">Katherine Johnson</span>          <time class="thread-meta" datetime="2026-11-12T10:54Z">12m</time>        </p>        <p class="thread-text">The figures in the second table are right.</p>      </div>    </li>  </ol></div>
<div className="card max-w(480) mx-auto">  <ol className="thread">    <li className="thread-item">      <span className="thread-avatar"><span className="avatar">AL</span></span>      <div className="thread-body">        <p className="thread-header">          <span className="thread-author">Ada Lovelace</span>          <time className="thread-meta" dateTime="2026-11-12T09:12Z">2h</time>        </p>        <p className="thread-text">          The focus ring is cut by the mask. Should it move to the group?        </p>      </div>      <ol className="thread-replies">        <li className="thread-item">          <span className="thread-avatar"><span className="avatar avatar-sm">AT</span></span>          <div className="thread-body">            <p className="thread-header">              <span className="thread-author">Alan Turing</span>              <time className="thread-meta" dateTime="2026-11-12T10:05Z">1h</time>            </p>            <p className="thread-text">              Yes. The group already has the corner, so the ring follows it.            </p>          </div>        </li>        <li className="thread-item">          <span className="thread-avatar"><span className="avatar avatar-sm">GH</span></span>          <div className="thread-body">            <p className="thread-header">              <span className="thread-author">Grace Hopper</span>              <time className="thread-meta" dateTime="2026-11-12T10:31Z">35m</time>            </p>            <p className="thread-text">I will make the change this afternoon.</p>          </div>        </li>      </ol>    </li>    <li className="thread-item">      <span className="thread-avatar"><span className="avatar">KJ</span></span>      <div className="thread-body">        <p className="thread-header">          <span className="thread-author">Katherine Johnson</span>          <time className="thread-meta" dateTime="2026-11-12T10:54Z">12m</time>        </p>        <p className="thread-text">The figures in the second table are right.</p>      </div>    </li>  </ol></div>
<div class="card max-w(480) mx-auto">  <ol class="thread">    <li class="thread-item">      <span class="thread-avatar"><span class="avatar">AL</span></span>      <div class="thread-body">        <p class="thread-header">          <span class="thread-author">Ada Lovelace</span>          <time class="thread-meta" datetime="2026-11-12T09:12Z">2h</time>        </p>        <p class="thread-text">The focus ring is cut by the mask. Should it move to the group?</p>      </div>      <ol class="thread-replies">        <li class="thread-item">          <span class="thread-avatar"><span class="avatar avatar-sm">AT</span></span>          <div class="thread-body">            <p class="thread-header">              <span class="thread-author">Alan Turing</span>              <time class="thread-meta" datetime="2026-11-12T10:05Z">1h</time>            </p>            <p class="thread-text">              Yes. The group already has the corner, so the ring follows it.            </p>          </div>        </li>        <li class="thread-item">          <span class="thread-avatar"><span class="avatar avatar-sm">GH</span></span>          <div class="thread-body">            <p class="thread-header">              <span class="thread-author">Grace Hopper</span>              <time class="thread-meta" datetime="2026-11-12T10:31Z">35m</time>            </p>            <p class="thread-text">I will make the change this afternoon.</p>          </div>        </li>      </ol>    </li>    <li class="thread-item">      <span class="thread-avatar"><span class="avatar">KJ</span></span>      <div class="thread-body">        <p class="thread-header">          <span class="thread-author">Katherine Johnson</span>          <time class="thread-meta" datetime="2026-11-12T10:54Z">12m</time>        </p>        <p class="thread-text">The figures in the second table are right.</p>      </div>    </li>  </ol></div>
<template>  <div class="card max-w(480) mx-auto">    <ol class="thread">      <li class="thread-item">        <span class="thread-avatar"><span class="avatar">AL</span></span>        <div class="thread-body">          <p class="thread-header">            <span class="thread-author">Ada Lovelace</span>            <time class="thread-meta" datetime="2026-11-12T09:12Z">2h</time>          </p>          <p class="thread-text">The focus ring is cut by the mask. Should it move to the group?</p>        </div>        <ol class="thread-replies">          <li class="thread-item">            <span class="thread-avatar"><span class="avatar avatar-sm">AT</span></span>            <div class="thread-body">              <p class="thread-header">                <span class="thread-author">Alan Turing</span>                <time class="thread-meta" datetime="2026-11-12T10:05Z">1h</time>              </p>              <p class="thread-text">                Yes. The group already has the corner, so the ring follows it.              </p>            </div>          </li>          <li class="thread-item">            <span class="thread-avatar"><span class="avatar avatar-sm">GH</span></span>            <div class="thread-body">              <p class="thread-header">                <span class="thread-author">Grace Hopper</span>                <time class="thread-meta" datetime="2026-11-12T10:31Z">35m</time>              </p>              <p class="thread-text">I will make the change this afternoon.</p>            </div>          </li>        </ol>      </li>      <li class="thread-item">        <span class="thread-avatar"><span class="avatar">KJ</span></span>        <div class="thread-body">          <p class="thread-header">            <span class="thread-author">Katherine Johnson</span>            <time class="thread-meta" datetime="2026-11-12T10:54Z">12m</time>          </p>          <p class="thread-text">The figures in the second table are right.</p>        </div>      </li>    </ol>  </div></template>

#構造

thread はリストです。各 thread-item は 1 件のコメントを表し、次の 3 つの子要素をこの順に持ちます。

  1. thread-avatar はアバターを囲みます。この列に沿って線が下へ伸びます。
  2. thread-body は本文です。thread-header に thread-author と、その名前に添える thread-meta を入れ、その後に段落ごとに thread-text を置きます。ページ側の段落スタイルにかかわらず、ヘッダーと各段落にマージンは付きません。続けて引用や控えめなスタイルのボタン列なども置けます。
  3. 返信がある場合、thread-replies はこのコメントへの返信を表す thread-item のリストになります。

コメントに返信があると線が自動で表示され、各返信に向かって折れ曲がり、アバターの手前で止まります。半透明の線は重なると濃く見えるため、線の各部分は重ならないように描画されます。

#入れ子

返信にも返信できます。返信の中に thread-replies を置くと、線が 1 階層内側に続きます。コメントには既定の 32px のアバターを使い、返信には深さにかかわらず 24px の avatar-sm を使います。

階層は 2〜3 段で十分です。1 段深くなるごとに幅が 36px 狭くなり、スマートフォンでは本文の表示幅が足りなくなります。それより深い返信は、冒頭に返信相手の名前を書き、同じ階層に置きます。

入れ子

<div class="card max-w(480) mx-auto">  <ol class="thread">    <li class="thread-item">      <span class="thread-avatar"><span class="avatar">GH</span></span>      <div class="thread-body">        <p class="thread-header">          <span class="thread-author">Grace Hopper</span>          <time class="thread-meta" datetime="2026-11-12T08:02Z">3h</time>        </p>        <p class="thread-text">Can we ship the contracts before the framework components?</p>      </div>      <ol class="thread-replies">        <li class="thread-item">          <span class="thread-avatar"><span class="avatar avatar-sm">AL</span></span>          <div class="thread-body">            <p class="thread-header">              <span class="thread-author">Ada Lovelace</span>              <time class="thread-meta" datetime="2026-11-12T08:40Z">2h</time>            </p>            <p class="thread-text">Yes, they do not depend on each other.</p>          </div>          <ol class="thread-replies">            <li class="thread-item">              <span class="thread-avatar"><span class="avatar avatar-sm">GH</span></span>              <div class="thread-body">                <p class="thread-header">                  <span class="thread-author">Grace Hopper</span>                  <time class="thread-meta" datetime="2026-11-12T08:44Z">2h</time>                </p>                <p class="thread-text">Then Tuesday.</p>              </div>            </li>          </ol>        </li>      </ol>    </li>  </ol></div>
<div className="card max-w(480) mx-auto">  <ol className="thread">    <li className="thread-item">      <span className="thread-avatar"><span className="avatar">GH</span></span>      <div className="thread-body">        <p className="thread-header">          <span className="thread-author">Grace Hopper</span>          <time className="thread-meta" dateTime="2026-11-12T08:02Z">3h</time>        </p>        <p className="thread-text">Can we ship the contracts before the framework components?</p>      </div>      <ol className="thread-replies">        <li className="thread-item">          <span className="thread-avatar"><span className="avatar avatar-sm">AL</span></span>          <div className="thread-body">            <p className="thread-header">              <span className="thread-author">Ada Lovelace</span>              <time className="thread-meta" dateTime="2026-11-12T08:40Z">2h</time>            </p>            <p className="thread-text">Yes, they do not depend on each other.</p>          </div>          <ol className="thread-replies">            <li className="thread-item">              <span className="thread-avatar"><span className="avatar avatar-sm">GH</span></span>              <div className="thread-body">                <p className="thread-header">                  <span className="thread-author">Grace Hopper</span>                  <time className="thread-meta" dateTime="2026-11-12T08:44Z">2h</time>                </p>                <p className="thread-text">Then Tuesday.</p>              </div>            </li>          </ol>        </li>      </ol>    </li>  </ol></div>
<div class="card max-w(480) mx-auto">  <ol class="thread">    <li class="thread-item">      <span class="thread-avatar"><span class="avatar">GH</span></span>      <div class="thread-body">        <p class="thread-header">          <span class="thread-author">Grace Hopper</span>          <time class="thread-meta" datetime="2026-11-12T08:02Z">3h</time>        </p>        <p class="thread-text">Can we ship the contracts before the framework components?</p>      </div>      <ol class="thread-replies">        <li class="thread-item">          <span class="thread-avatar"><span class="avatar avatar-sm">AL</span></span>          <div class="thread-body">            <p class="thread-header">              <span class="thread-author">Ada Lovelace</span>              <time class="thread-meta" datetime="2026-11-12T08:40Z">2h</time>            </p>            <p class="thread-text">Yes, they do not depend on each other.</p>          </div>          <ol class="thread-replies">            <li class="thread-item">              <span class="thread-avatar"><span class="avatar avatar-sm">GH</span></span>              <div class="thread-body">                <p class="thread-header">                  <span class="thread-author">Grace Hopper</span>                  <time class="thread-meta" datetime="2026-11-12T08:44Z">2h</time>                </p>                <p class="thread-text">Then Tuesday.</p>              </div>            </li>          </ol>        </li>      </ol>    </li>  </ol></div>
<template>  <div class="card max-w(480) mx-auto">    <ol class="thread">      <li class="thread-item">        <span class="thread-avatar"><span class="avatar">GH</span></span>        <div class="thread-body">          <p class="thread-header">            <span class="thread-author">Grace Hopper</span>            <time class="thread-meta" datetime="2026-11-12T08:02Z">3h</time>          </p>          <p class="thread-text">Can we ship the contracts before the framework components?</p>        </div>        <ol class="thread-replies">          <li class="thread-item">            <span class="thread-avatar"><span class="avatar avatar-sm">AL</span></span>            <div class="thread-body">              <p class="thread-header">                <span class="thread-author">Ada Lovelace</span>                <time class="thread-meta" datetime="2026-11-12T08:40Z">2h</time>              </p>              <p class="thread-text">Yes, they do not depend on each other.</p>            </div>            <ol class="thread-replies">              <li class="thread-item">                <span class="thread-avatar"><span class="avatar avatar-sm">GH</span></span>                <div class="thread-body">                  <p class="thread-header">                    <span class="thread-author">Grace Hopper</span>                    <time class="thread-meta" datetime="2026-11-12T08:44Z">2h</time>                  </p>                  <p class="thread-text">Then Tuesday.</p>                </div>              </li>            </ol>          </li>        </ol>      </li>    </ol>  </div></template>

#スレッドとメッセージの使い分け

スレッドは、ある話題についての議論です。コメントは対等に扱われ、どれにでも返信できます。メッセージは、二者間の会話での一つひとつの発言を、発言者を指す吹き出しで表示します。返信の対象にならないイベントにはタイムラインを使います。

#アクセシビリティ

  • スレッドには <ol> を使い、返信は <ol> を入れ子にして表します。スクリーンリーダーはこの構造から階層と返信数を読み上げます。画面上では、線がその関係を示します。
  • 「2h」のような短い時刻表記にも正確な値を持たせるため、各時刻に <time> を使い、datetime を指定します。
  • 線はスタイルシートで描画され、読み上げの対象外です。強制カラーモードではテキストと同じ色になります。
  • 投稿者名の横にイニシャルや写真を表示するアバターは、名前がテキストで示されているため、装飾として扱います。

#クラス

クラス説明
threadコメントのリスト。間隔は 20px
thread-itemコメント1件。アバター専用の列を設け、その隣に本文、本文の下に返信を配置
thread-avatarアバターを囲む列。返信が続く場合は、アバターの下から線が伸びます。
thread-bodythread-headerと、その下のthread-text。1行目はアバターの縦中央に揃える
thread-header本文の 1 行目。投稿者名と、その横に時刻を表示。
thread-textヘッダーの下に置く本文。複数の段落は8px間隔
thread-author投稿者名を強調用の前景色で表示します。
thread-meta日時やその他の補足情報を名前の横に控えめに表示
thread-repliesthread-item内で本文の後に置く返信リスト。各返信はthread-itemで、折れ曲がった線でコメントにつながります。

#カスタムプロパティ

プロパティ既定値説明
--thread-avatar2remコメントのアバターのサイズ。返信は1.5rem
--thread-gap.75remアバターとテキストの間隔
--thread-space1.25remコメント同士の間隔。返信同士の間隔は .875rem

#ソース

@master/ui/components/thread.css
/* * Thread: comments and their replies, each joined to the comment it answers. * A comment is an avatar on a column and its words beside it. Replies stand under the words, and a hairline * runs down from the comment's avatar and turns into each of them: a reader follows a line, not an indent, * to see what answers what. The line is drawn in pieces that never overlap, since its ink is translucent: * the stretch under the avatar, an elbow into each reply, and the stretch on to the next one. * Geometry: a 32px avatar for a comment and 24px for a reply (avatar-sm), 12px between an avatar and its * words, 20px between comments and 14px between replies. The name stands level with the middle of its avatar. */@layer components.ui {  .thread {    --thread-avatar: 2rem;    --thread-gap: .75rem;    --thread-space: 1.25rem;    display: grid;    gap: var(--thread-space);    min-width: 0;    margin: 0;    padding: 0;    color: var(--color-text-body);    font-size: .875rem;    line-height: 1.55;    list-style: none;  }  /* One comment: the avatar's column, the words, and under the words its replies. */  .thread-item {    /* Where this comment's line runs, for the replies that turn off it. */    --thread-rail: calc(var(--thread-avatar) / 2);    position: relative;    display: grid;    grid-template-columns: var(--thread-avatar) minmax(0, 1fr);    column-gap: var(--thread-gap);    min-width: 0;  }  /* The avatar's column. Under the avatar the line begins, when replies follow. */  .thread-avatar {    display: flex;    grid-area: 1 / 1;    flex-direction: column;    align-items: center;    min-width: 0;    /* The avatar fills the column: a comment's is --thread-avatar, a reply's the size smaller. A size class on it still wins. */    .avatar {      --avatar-size: var(--thread-avatar);    }    &:has(~ .thread-replies)::after {      content: '';      flex: 1 1 0;      width: 1px;      margin-block-start: .25rem;      background: var(--color-line-divider);    }    @media (forced-colors: active) {      &:has(~ .thread-replies)::after {        background: CanvasText;      }    }  }  /* The words: a line that says who and when, then what they wrote. The first line is level with the middle of the avatar. */  .thread-body {    display: grid;    grid-area: 1 / 2;    gap: .125rem;    min-width: 0;    padding-block-start: calc((var(--thread-avatar) - 1.25rem) / 2);    overflow-wrap: anywhere;  }  /* The line with the name on it, and what is said quietly beside the name. */  .thread-header {    display: flex;    flex-wrap: wrap;    align-items: baseline;    gap: 0 .5rem;    min-width: 0;    margin: 0;  }  /* What they wrote. Several paragraphs stand 8px apart. */  .thread-text {    min-width: 0;    margin: 0;    text-wrap: pretty;    & + & {      margin-block-start: .375rem;    }  }  /* Who wrote it. */  .thread-author {    color: var(--color-text-strong);    font-weight: var(--font-weight-control);    line-height: 1.25rem;  }  /* When, and anything else said quietly beside the name. */  .thread-meta {    color: var(--color-text-muted);    font-size: .78125rem;    font-variant-numeric: tabular-nums;    line-height: 1.25rem;  }  /* The replies, under the words. Their avatars are a size smaller. */  .thread-replies {    --thread-parent: var(--thread-rail);    --thread-avatar: 1.5rem;    --thread-space: .875rem;    display: grid;    grid-area: 2 / 2;    min-width: 0;    margin: 0;    padding: 0;    list-style: none;    .thread-item {      padding-block-start: var(--thread-space);      /* The elbow: down the comment's line, then round into this reply's avatar, stopping 4px short of it. */      &::before {        content: '';        position: absolute;        inset-block-start: 0;        inset-inline-start: calc(-1 * (var(--thread-gap) + var(--thread-parent)) - .5px);        width: calc(var(--thread-gap) + var(--thread-parent) - .25rem);        height: calc(var(--thread-space) + var(--thread-avatar) / 2);        border-block-end: 1px solid var(--color-line-divider);        border-inline-start: 1px solid var(--color-line-divider);        border-end-start-radius: .625rem;        pointer-events: none;      }      /* The line goes on to the next reply, from where the elbow leaves it. */      &:not(:last-child)::after {        content: '';        position: absolute;        inset-block: calc(var(--thread-space) + var(--thread-avatar) / 2 - .625rem) 0;        inset-inline-start: calc(-1 * (var(--thread-gap) + var(--thread-parent)) - .5px);        width: 1px;        background: var(--color-line-divider);        pointer-events: none;      }      @media (forced-colors: active) {        &::before {          border-color: CanvasText;        }        &:not(:last-child)::after {          background: CanvasText;        }      }    }  }}