ナビゲーション

v2.1.0
メディア

図版

縁を整えた、キャプション付きの画像や動画。

このページの内容

画像、動画、イラストにキャプションを添えます。メディアの角にはサーフェスと同じ丸みを付け、縁のすぐ内側を極細の線で囲みます。淡い画像の境界がページに溶け込まず、暗い画像の縁も唐突に途切れて見えません。キャプションはメディアのすぐ下に控えめに表示します。読者が拡大して見たいと思うような画像はライトボックスで開けます。

図版

<figure class="figure max-w(360) mx-auto">  <img class="figure-media" src="/demo/moonstone.svg" alt="A pale stone with a band of light across it" style="--figure-ratio: 3 / 2">  <figcaption class="figure-caption">    Moonstone under a north light, the stone the light theme is named for.  </figcaption></figure>
<figure className="figure max-w(360) mx-auto">  <img className="figure-media" src="/demo/moonstone.svg" alt="A pale stone with a band of light across it" style={{ '--figure-ratio': '3 / 2' } as React.CSSProperties} />  <figcaption className="figure-caption">    Moonstone under a north light, the stone the light theme is named for.  </figcaption></figure>
<figure class="figure max-w(360) mx-auto">  <img class="figure-media" src="/demo/moonstone.svg" alt="A pale stone with a band of light across it" style="--figure-ratio: 3 / 2">  <figcaption class="figure-caption">    Moonstone under a north light, the stone the light theme is named for.  </figcaption></figure>
<template>  <figure class="figure max-w(360) mx-auto">    <img class="figure-media" src="/demo/moonstone.svg" alt="A pale stone with a band of light across it" style="--figure-ratio: 3 / 2">    <figcaption class="figure-caption">      Moonstone under a north light, the stone the light theme is named for.    </figcaption>  </figure></template>

メディアに--figure-ratioを指定すると、読み込み前からその縦横比で領域を確保し、読み込み後はメディアが領域全体を覆います。指定を省くと、メディア本来の縦横比を保ちます。どちらの場合も、ブラウザーが領域を確保できるよう、<img>にはwidthとheightを記述します。

#フレーム付き

figure-framedは、台紙に写真を収めるように、メディアをフレームの縁から4px内側に配置します。キャプションもフレーム内に移ります。フレームの角丸の半径はメディアの角丸の半径にその余白を足した値なので、角でも間隔が一定です。

フレーム付き

<figure class="figure figure-framed max-w(360) mx-auto">  <img class="figure-media" src="/demo/moonstone.svg" alt="A pale stone with a band of light across it" style="--figure-ratio: 16 / 9">  <figcaption class="figure-caption">Figure 2. The same stone, framed.</figcaption></figure>
<figure className="figure figure-framed max-w(360) mx-auto">  <img className="figure-media" src="/demo/moonstone.svg" alt="A pale stone with a band of light across it" style={{ '--figure-ratio': '16 / 9' } as React.CSSProperties} />  <figcaption className="figure-caption">Figure 2. The same stone, framed.</figcaption></figure>
<figure class="figure figure-framed max-w(360) mx-auto">  <img class="figure-media" src="/demo/moonstone.svg" alt="A pale stone with a band of light across it" style="--figure-ratio: 16 / 9">  <figcaption class="figure-caption">Figure 2. The same stone, framed.</figcaption></figure>
<template>  <figure class="figure figure-framed max-w(360) mx-auto">    <img class="figure-media" src="/demo/moonstone.svg" alt="A pale stone with a band of light across it" style="--figure-ratio: 16 / 9">    <figcaption class="figure-caption">Figure 2. The same stone, framed.</figcaption>  </figure></template>

#中央揃え

figure-centerは、本文の段に単独で置く図版向けに、キャプションを中央揃えにして各行の長さが均等になるよう折り返します。

中央揃え

<figure class="figure figure-center max-w(240) mx-auto">  <img class="figure-media" src="/demo/portrait-2.svg" alt="Alan Turing" style="--figure-ratio: 1">  <figcaption class="figure-caption">Alan Turing, drawn for the avatar examples.</figcaption></figure>
<figure className="figure figure-center max-w(240) mx-auto">  <img className="figure-media" src="/demo/portrait-2.svg" alt="Alan Turing" style={{ '--figure-ratio': '1' } as React.CSSProperties} />  <figcaption className="figure-caption">Alan Turing, drawn for the avatar examples.</figcaption></figure>
<figure class="figure figure-center max-w(240) mx-auto">  <img class="figure-media" src="/demo/portrait-2.svg" alt="Alan Turing" style="--figure-ratio: 1">  <figcaption class="figure-caption">Alan Turing, drawn for the avatar examples.</figcaption></figure>
<template>  <figure class="figure figure-center max-w(240) mx-auto">    <img class="figure-media" src="/demo/portrait-2.svg" alt="Alan Turing" style="--figure-ratio: 1">    <figcaption class="figure-caption">Alan Turing, drawn for the avatar examples.</figcaption>  </figure></template>

#アクセシビリティ

  • <figure>には<figcaption>を組み合わせます。キャプションが図版のアクセシブルな名前になります。
  • キャプションがあってもaltは必要です。代替テキストは画像に何が写っているかを伝え、キャプションはその画像を掲載する理由を伝えます。キャプションで必要な情報をすべて伝えている場合は、alt=""と指定して、同じ内容が二重に読み上げられるのを防ぎます。
  • メディアの縁の内側にある線は装飾で、配色設定に従います。強制カラーモードでは、フレーム付きの図版にシステムのアウトラインが適用されます。

#クラス

クラス説明
figureメディアの下にキャプションを置く図版。
figure-framedメディアはトレイの端から 4px 内側に収まり、キャプションは枠内に配置されます。figure と併用します
figure-center本文のカラムに単独で置く図版向けのキャプション。中央揃えにし、各行の長さのバランスを整えます。figure と併用します
figure-mediaimg、video、svg、または任意のブロックに、サーフェスの角丸と、縁の内側に沿った細い輪郭線を適用。
figure-captionメディアの下に置く、小さく控えめなキャプション

#カスタムプロパティ

プロパティ既定値説明
--figure-radiusvar(--radius-surface)メディアの角丸
--figure-ratioメディアのアスペクト比。読み込み前からその比率の領域を確保し、読み込み後はメディアが領域全体を覆います。未指定の場合はメディア本来の比率を保ちます。指定先:figure-media

#ソース

@master/ui/components/figure.css
/* * Figure: an image, a video or a drawing with its caption. * The media takes a surface's corner and a hairline ring inside its own edge, so a pale image does not * dissolve into the page and a dark one does not end in a hard cut. The caption sits close under it, quiet. */@layer components.ui {  .figure {    --figure-radius: var(--radius-surface);    display: grid;    gap: .625rem;    min-width: 0;    margin: 0;    /*     * Framed: the media rests in a tray, 4px in, like a print in a mat. The tray's corner is the media's     * corner plus that inset.     */    &.figure-framed {      --surface-color: var(--color-surface-tray);      padding: 4px;      border-radius: calc(var(--figure-radius) * var(--corner-scale) + 4px);      corner-shape: var(--corner-shape);      background: var(--color-surface-tray);      box-shadow: inset 0 0 0 .5px var(--color-line-hair), inset 0 1px 2px -1px var(--color-shade-2);      gap: 0;      .figure-media {        box-shadow: var(--shadow-raised);        outline: 0;      }      .figure-caption {        padding: .5rem .625rem .375rem;      }    }    /* Centered: for a figure that stands alone in a column of text. */    &.figure-center .figure-caption {      text-align: center;      text-wrap: balance;    }    @media (forced-colors: active) {      &.figure-framed {        outline: 1px solid CanvasText;        outline-offset: -1px;      }    }  }  /* Set --figure-ratio to hold a shape before the media loads; the media then covers that shape. */  .figure-media {    display: block;    width: 100%;    max-width: 100%;    height: auto;    aspect-ratio: var(--figure-ratio, auto);    border-radius: calc(var(--figure-radius) * var(--corner-scale));    corner-shape: var(--corner-shape);    background: var(--color-surface-inset);    object-fit: cover;    outline: .5px solid var(--color-line-image-strong);    outline-offset: -.5px;  }  .figure-caption {    margin: 0;    color: var(--color-text-muted);    font-size: .8125rem;    line-height: 1.5;    text-wrap: pretty;    overflow-wrap: anywhere;  }}