ナビゲーション

v2.1.0
フィードバック

フラッシュ

リンクの移動先を輪郭線で示し、その線が徐々に消えます。

このページの内容

フラッシュはリンクの移動先を示します。見出し、行、コメント、カードなど、idを持つ任意の要素にflashを付けます。そのidがURLのフラグメントと一致すると、要素の周囲に輪郭線が表示され、2秒かけて消えます。複数の項目があるページでも、どの項目へのリンクを開いたかがわかります。状態はURLで決まり、スクリプトは不要です。

フラッシュ

<div class="card max-w(480) mx-auto">  <p class="m(0) text-sm">    Jump to <a class="link" href="#comment-ada">Ada's comment</a> or <a class="link" href="#comment-grace">Grace's reply</a>.  </p>  <ol class="thread">    <li class="thread-item flash" id="comment-ada" style="--flash-offset: 1rem">      <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:12">2h</time>        </p>        <p class="thread-text">The focus ring is cut by the mask. Should it move to the group?</p>      </div>    </li>    <li class="thread-item flash" id="comment-grace" style="--flash-offset: 1rem">      <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-12T10:31">35m</time>        </p>        <p class="thread-text">I will make the change this afternoon.</p>      </div>    </li>  </ol></div>
<div className="card max-w(480) mx-auto">  <p className="m(0) text-sm">    Jump to <a className="link" href="#comment-ada">Ada's comment</a> or <a className="link" href="#comment-grace">Grace's reply</a>.  </p>  <ol className="thread">    <li className="thread-item flash" id="comment-ada" style={{ '--flash-offset': '1rem' } as React.CSSProperties}>      <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:12">2h</time>        </p>        <p className="thread-text">          The focus ring is cut by the mask. Should it move to the group?        </p>      </div>    </li>    <li className="thread-item flash" id="comment-grace" style={{ '--flash-offset': '1rem' } as React.CSSProperties}>      <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-12T10:31">35m</time>        </p>        <p className="thread-text">I will make the change this afternoon.</p>      </div>    </li>  </ol></div>
<div class="card max-w(480) mx-auto">  <p class="m(0) text-sm">    Jump to <a class="link" href="#comment-ada">Ada's comment</a> or <a class="link" href="#comment-grace">Grace's reply</a>.  </p>  <ol class="thread">    <li class="thread-item flash" id="comment-ada" style="--flash-offset: 1rem">      <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:12">2h</time>        </p>        <p class="thread-text">The focus ring is cut by the mask. Should it move to the group?</p>      </div>    </li>    <li class="thread-item flash" id="comment-grace" style="--flash-offset: 1rem">      <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-12T10:31">35m</time>        </p>        <p class="thread-text">I will make the change this afternoon.</p>      </div>    </li>  </ol></div>
<template>  <div class="card max-w(480) mx-auto">    <p class="m(0) text-sm">      Jump to <a class="link" href="#comment-ada">Ada's comment</a> or <a class="link" href="#comment-grace">Grace's reply</a>.    </p>    <ol class="thread">      <li class="thread-item flash" id="comment-ada" style="--flash-offset: 1rem">        <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:12">2h</time>          </p>          <p class="thread-text">The focus ring is cut by the mask. Should it move to the group?</p>        </div>      </li>      <li class="thread-item flash" id="comment-grace" style="--flash-offset: 1rem">        <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-12T10:31">35m</time>          </p>          <p class="thread-text">I will make the change this afternoon.</p>        </div>      </li>    </ol>  </div></template>
リンクを開くと、リンク先のコメントを囲む輪郭線が表示され、徐々に消えます。

#仕組み

ブラウザーは、idがURLのフラグメントに一致する要素をページの:targetとして扱います。flashはその要素を輪郭線で囲み、徐々に消します。状態はURLで決まるため、次のように動作します。

  • 別ページからリンクを開いても、同じページ内のリンクを開いても、URLを貼り付けて開いても、同じ要素が強調表示されます。
  • 別のフラグメントへのリンクを開くと強調表示が移ります。同じフラグメントへのリンクを再び開いても、アニメーションは再生されません。

輪郭線にはアウトラインを使います。レイアウト上の領域を取らず、要素自体の角に沿い、擬似要素も不要です。要素の表面、影、ホバー時の表示も保たれます。同じクラスをカード、表の行、見出し、コメントに使えます。

#ナビゲーションバーとの重なりを防ぐ

フラグメントリンクで移動すると、対象はビューポートの最上部までスクロールされます。sticky で上部に留まるナビゲーションバーがあると、対象がその背後に隠れます。flashは、ブラウザーがスクロールを止める位置をビューポートの上端からずらします。その距離は--flash-offsetで調整でき、既定値は5remです。ページ上部の固定要素の高さに、少し余白を足した値を指定します。

#動きの軽減

動きの軽減が有効な場合、フェードは起こりません。移動先である間は極細の輪郭線が残り、動きなしで対象を示します。

#フラッシュとマークの使い分け

フラッシュは移動先を一時的に示します。文章中の語句を常に強調するにはマークを使います。直前に起きたことを知らせるにはトーストを使います。

#アクセシビリティ

  • フラッシュは視覚的な手がかりです。移動先がリンクや操作コントロール以外の要素なら、tabindex="-1"を付けます。リンクで移動したときにその要素へフォーカスが移り、次にTabを押すとそこから移動できます。
  • 輪郭線は要素の4px外側にあり、内容を覆わないため、テキストのコントラストが保たれます。
  • 強制カラーモードでは、対象をシステムの強調色で囲み、フェードは起こりません。

#クラス

クラス説明
flashidを持つ要素がURLの参照先になると、要素の角の形状に沿ってリングが現れ、徐々に消える

#カスタムプロパティ

プロパティ既定値説明
--flash-offset5remブラウザーが要素をスクロールして配置する位置とビューポート上端との距離

#ソース

@master/ui/components/flash.css
/* * Flash: where a link has landed. * On anything with an id. When that id is the fragment of the address, the element is the page's :target: * a ring of ink stands around it and fades away in two seconds, so a reader who followed a link to one * heading, one row or one comment among many sees which. Nothing is added by script: the address is the state. * The ring is an outline. It takes no room, follows the element's own corner, needs no pseudo-element and * leaves the element's face, shadow and hover as they are, so it works on a card, a table row and a line of * text alike. * The element also keeps clear of what is fixed at the top of the page: --flash-offset is how far below the * top edge the browser scrolls it to, 5rem unless told otherwise. * With reduced motion the ring does not fade: a hairline stays around the target instead. */@layer components.ui {  .flash {    --flash-offset: 5rem;    --flash-color: color-mix(in oklab, var(--color-text-strong) 42%, transparent);    scroll-margin-top: var(--flash-offset);    &:target {      animation: flash-fade 2s var(--easing-glide) 200ms backwards;    }    @media (prefers-reduced-motion: reduce) {      &:target {        outline: 1px solid var(--color-line-mark);        outline-offset: .25rem;        animation: none;      }    }    @media (forced-colors: active) {      &:target {        outline: 2px solid Highlight;        outline-offset: .25rem;        animation: none;      }    }  }}@keyframes flash-fade {  0%, 30% {    outline: 2px solid var(--flash-color);    outline-offset: .25rem;  }  100% {    outline: 2px solid transparent;    outline-offset: .25rem;  }}