投票
回答、投稿、コメントのスコアを、ユーザーの投票で 1 ずつ増減できます。
このページの内容
投票では、ユーザーが回答、投稿、コメントなどのスコアを1増減できます。2つの矢印は、同じグループに属するネイティブのラジオボタンを、控えめな正方形のボタンとして表示したものです。間にあるスコアは CSS カウンターで表示するため、スクリプトなしで押した結果が数値に反映されます。
投票
<article class="sheet max-w(440) w-full flex items-start gap-sm p(12)"> <fieldset class="vote" aria-label="Vote on this answer" style="--votes: 41"> <input type="radio" class="vote-up" name="answer-vote" value="up" aria-label="Upvote"> <output class="vote-score"></output> <input type="radio" class="vote-down" name="answer-vote" value="down" aria-label="Downvote"> </fieldset> <div class="flex flex-col gap(4) pt(6) pr(8)"> <p class="m(0) text-sm font-medium fg-text-strong">Put the focus ring on the group</p> <p class="m(0) text-sm fg-text-body"> A mask cuts the element it is drawn on, ring and all. Draw the ring on the container while one of its inputs has focus. </p> </div></article><article className="sheet max-w(440) w-full flex items-start gap-sm p(12)"> <fieldset className="vote" aria-label="Vote on this answer" style={{ '--votes': '41' } as React.CSSProperties}> <input type="radio" className="vote-up" name="answer-vote" value="up" aria-label="Upvote" /> <output className="vote-score"></output> <input type="radio" className="vote-down" name="answer-vote" value="down" aria-label="Downvote" /> </fieldset> <div className="flex flex-col gap(4) pt(6) pr(8)"> <p className="m(0) text-sm font-medium fg-text-strong">Put the focus ring on the group</p> <p className="m(0) text-sm fg-text-body"> A mask cuts the element it is drawn on, ring and all. Draw the ring on the container while one of its inputs has focus. </p> </div></article><article class="sheet max-w(440) w-full flex items-start gap-sm p(12)"> <fieldset class="vote" aria-label="Vote on this answer" style="--votes: 41"> <input type="radio" class="vote-up" name="answer-vote" value="up" aria-label="Upvote"> <output class="vote-score"></output> <input type="radio" class="vote-down" name="answer-vote" value="down" aria-label="Downvote"> </fieldset> <div class="flex flex-col gap(4) pt(6) pr(8)"> <p class="m(0) text-sm font-medium fg-text-strong">Put the focus ring on the group</p> <p class="m(0) text-sm fg-text-body"> A mask cuts the element it is drawn on, ring and all. Draw the ring on the container while one of its inputs has focus. </p> </div></article><template> <article class="sheet max-w(440) w-full flex items-start gap-sm p(12)"> <fieldset class="vote" aria-label="Vote on this answer" style="--votes: 41"> <input type="radio" class="vote-up" name="answer-vote" value="up" aria-label="Upvote"> <output class="vote-score"></output> <input type="radio" class="vote-down" name="answer-vote" value="down" aria-label="Downvote"> </fieldset> <div class="flex flex-col gap(4) pt(6) pr(8)"> <p class="m(0) text-sm font-medium fg-text-strong">Put the focus ring on the group</p> <p class="m(0) text-sm fg-text-body"> A mask cuts the element it is drawn on, ring and all. Draw the ring on the container while one of its inputs has focus. </p> </div> </article></template>#スコア
グループの --votes には、ユーザー本人の票を除いたスコアを設定します。上矢印を選ぶと1増え、下矢印を選ぶと1減ります。ページ側で本人の投票を把握している場合は、対応する矢印を選択済みにし、ほかのユーザーの票だけを集計したスコアを設定します。vote-score を空にすると、カウンターがスコアを表示し、負の値にはマイナス記号(−)を使います。1票単位で表示するには大きすぎるスコアは、1.4k のようなテキストを中に記述します。
#横並び
vote-horizontal はスコアの左右に矢印を配置します。コメント下部の操作を横に並べる場合に使えます。スコアには数字3桁分の幅を確保するため、値が変わっても矢印の位置は変わりません。
横並び
<div class="card max-w(480) mx-auto"> <ol class="thread"> <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:54">12m</time> </p> <p class="thread-text"> The figures in the second table are right. The third needs another pass. </p> <div class="flex items-center gap(4) mt(6) ml(-8)"> <fieldset class="vote vote-horizontal" aria-label="Vote on this comment" style="--votes: 12"> <input type="radio" class="vote-up" name="comment-vote" value="up" aria-label="Upvote" checked> <output class="vote-score"></output> <input type="radio" class="vote-down" name="comment-vote" value="down" aria-label="Downvote"> </fieldset> <button type="button" class="btn btn-quiet btn-sm">Reply</button> </div> </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">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:54">12m</time> </p> <p className="thread-text"> The figures in the second table are right. The third needs another pass. </p> <div className="flex items-center gap(4) mt(6) ml(-8)"> <fieldset className="vote vote-horizontal" aria-label="Vote on this comment" style={{ '--votes': '12' } as React.CSSProperties}> <input type="radio" className="vote-up" name="comment-vote" value="up" aria-label="Upvote" defaultChecked /> <output className="vote-score"></output> <input type="radio" className="vote-down" name="comment-vote" value="down" aria-label="Downvote" /> </fieldset> <button type="button" className="btn btn-quiet btn-sm">Reply</button> </div> </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">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:54">12m</time> </p> <p class="thread-text"> The figures in the second table are right. The third needs another pass. </p> <div class="flex items-center gap(4) mt(6) ml(-8)"> <fieldset class="vote vote-horizontal" aria-label="Vote on this comment" style="--votes: 12"> <input type="radio" class="vote-up" name="comment-vote" value="up" aria-label="Upvote" checked> <output class="vote-score"></output> <input type="radio" class="vote-down" name="comment-vote" value="down" aria-label="Downvote"> </fieldset> <button type="button" class="btn btn-quiet btn-sm">Reply</button> </div> </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">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:54">12m</time> </p> <p class="thread-text"> The figures in the second table are right. The third needs another pass. </p> <div class="flex items-center gap(4) mt(6) ml(-8)"> <fieldset class="vote vote-horizontal" aria-label="Vote on this comment" style="--votes: 12"> <input type="radio" class="vote-up" name="comment-vote" value="up" aria-label="Upvote" checked> <output class="vote-score"></output> <input type="radio" class="vote-down" name="comment-vote" value="down" aria-label="Downvote"> </fieldset> <button type="button" class="btn btn-quiet btn-sm">Reply</button> </div> </div> </li> </ol> </div></template>#状態
通常時はボタンの背景がなく、矢印は控えめな色の輪郭で表示されます。ホバー時はボタンの面が浮き上がり、押している間はくぼんだ表示になり、選択すると矢印が塗りつぶされます。スコアを上げる票と下げる票には同じ色を使い、矢印の向きで区別します。ユーザー自身の投稿など、投票できないスコアを表示する場合は fieldset を無効にします。矢印は薄くなり、スコアは表示されたままになります。
状態
<fieldset class="vote" aria-label="Vote on this answer" style="--votes: 3"> <input type="radio" class="vote-up" name="vote-down-state" value="up" aria-label="Upvote"> <output class="vote-score"></output> <input type="radio" class="vote-down" name="vote-down-state" value="down" aria-label="Downvote" checked></fieldset><fieldset class="vote" aria-label="Vote on this answer" style="--votes: -2"> <input type="radio" class="vote-up" name="vote-negative" value="up" aria-label="Upvote"> <output class="vote-score"></output> <input type="radio" class="vote-down" name="vote-negative" value="down" aria-label="Downvote"></fieldset><fieldset class="vote" aria-label="Votes on your answer" disabled> <input type="radio" class="vote-up" name="vote-own" value="up" aria-label="Upvote"> <output class="vote-score">1.4k</output> <input type="radio" class="vote-down" name="vote-own" value="down" aria-label="Downvote"></fieldset><> <fieldset className="vote" aria-label="Vote on this answer" style={{ '--votes': '3' } as React.CSSProperties}> <input type="radio" className="vote-up" name="vote-down-state" value="up" aria-label="Upvote" /> <output className="vote-score"></output> <input type="radio" className="vote-down" name="vote-down-state" value="down" aria-label="Downvote" defaultChecked /> </fieldset> <fieldset className="vote" aria-label="Vote on this answer" style={{ '--votes': '-2' } as React.CSSProperties}> <input type="radio" className="vote-up" name="vote-negative" value="up" aria-label="Upvote" /> <output className="vote-score"></output> <input type="radio" className="vote-down" name="vote-negative" value="down" aria-label="Downvote" /> </fieldset> <fieldset className="vote" aria-label="Votes on your answer" disabled> <input type="radio" className="vote-up" name="vote-own" value="up" aria-label="Upvote" /> <output className="vote-score">1.4k</output> <input type="radio" className="vote-down" name="vote-own" value="down" aria-label="Downvote" /> </fieldset></><fieldset class="vote" aria-label="Vote on this answer" style="--votes: 3"> <input type="radio" class="vote-up" name="vote-down-state" value="up" aria-label="Upvote"> <output class="vote-score"></output> <input type="radio" class="vote-down" name="vote-down-state" value="down" aria-label="Downvote" checked></fieldset><fieldset class="vote" aria-label="Vote on this answer" style="--votes: -2"> <input type="radio" class="vote-up" name="vote-negative" value="up" aria-label="Upvote"> <output class="vote-score"></output> <input type="radio" class="vote-down" name="vote-negative" value="down" aria-label="Downvote"></fieldset><fieldset class="vote" aria-label="Votes on your answer" disabled> <input type="radio" class="vote-up" name="vote-own" value="up" aria-label="Upvote"> <output class="vote-score">1.4k</output> <input type="radio" class="vote-down" name="vote-own" value="down" aria-label="Downvote"></fieldset><template> <fieldset class="vote" aria-label="Vote on this answer" style="--votes: 3"> <input type="radio" class="vote-up" name="vote-down-state" value="up" aria-label="Upvote"> <output class="vote-score"></output> <input type="radio" class="vote-down" name="vote-down-state" value="down" aria-label="Downvote" checked> </fieldset> <fieldset class="vote" aria-label="Vote on this answer" style="--votes: -2"> <input type="radio" class="vote-up" name="vote-negative" value="up" aria-label="Upvote"> <output class="vote-score"></output> <input type="radio" class="vote-down" name="vote-negative" value="down" aria-label="Downvote"> </fieldset> <fieldset class="vote" aria-label="Votes on your answer" disabled> <input type="radio" class="vote-up" name="vote-own" value="up" aria-label="Upvote"> <output class="vote-score">1.4k</output> <input type="radio" class="vote-down" name="vote-own" value="down" aria-label="Downvote"> </fieldset></template>#投票の取り消し
ラジオボタンは再度押しても選択が解除されないため、スクリプトなしでできるのは投票の変更までです。vote のビヘイビアを使うと、選択済みの矢印をもう一度押すか、フォーカスを合わせて Space キーを押すと投票が取り消され、スコアが --votes に戻ります。
投票の取り消し
<fieldset class="vote" id="vote-clear" aria-label="Vote on this answer" style="--votes: 7"> <input type="radio" class="vote-up" name="vote-clear" value="up" aria-label="Upvote" checked> <output class="vote-score"></output> <input type="radio" class="vote-down" name="vote-clear" value="down" aria-label="Downvote"></fieldset><script type="module"> import { attach } from '@master/ui/behaviors' attach()</script>import { useEffect, useRef } from 'react'import { attach } from '@master/ui/behaviors'export function Example() { const root = useRef<HTMLFieldSetElement>(null) useEffect(() => attach(root.current!), []) return ( <fieldset ref={root} className="vote" id="vote-clear" aria-label="Vote on this answer" style={{ '--votes': '7' } as React.CSSProperties}> <input type="radio" className="vote-up" name="vote-clear" value="up" aria-label="Upvote" defaultChecked /> <output className="vote-score"></output> <input type="radio" className="vote-down" name="vote-clear" value="down" aria-label="Downvote" /> </fieldset> )}<script> import { attach } from '@master/ui/behaviors'</script><fieldset class="vote" id="vote-clear" aria-label="Vote on this answer" style="--votes: 7" {@attach attach}> <input type="radio" class="vote-up" name="vote-clear" value="up" aria-label="Upvote" checked> <output class="vote-score"></output> <input type="radio" class="vote-down" name="vote-clear" value="down" aria-label="Downvote"></fieldset><script setup>import { onMounted, onUnmounted, ref } from 'vue'import { attach } from '@master/ui/behaviors'const root = ref(null)let detachonMounted(() => { detach = attach(root.value) })onUnmounted(() => detach?.())</script><template> <fieldset ref="root" class="vote" id="vote-clear" aria-label="Vote on this answer" style="--votes: 7"> <input type="radio" class="vote-up" name="vote-clear" value="up" aria-label="Upvote" checked> <output class="vote-score"></output> <input type="radio" class="vote-down" name="vote-clear" value="down" aria-label="Downvote"> </fieldset></template>#アクセシビリティ
aria-labelまたは<legend>でグループに名前を付け、各ラジオボタンにも「賛成票を投じる」「反対票を投じる」と名前を付けます。- スコアは
<output>に入れます。スコアは2つの矢印の間で読み上げられ、投票で値が変わるとステータスとして通知されます。 - 矢印は疑似要素で描画するため、マスクでフォーカスリングが欠けることはありません。通常のラジオグループと同様に、矢印キーで2つのラジオボタンの選択を切り替えられます。
- 各矢印ボタンの表示サイズは、ポインターの種類にかかわらず 32px です。タッチスクリーンでは、ボタンを中心に操作領域が 44px になります。強制カラーモードでは矢印にボタンのテキスト色を使い、選択中の矢印には強調色を使います。
#クラス
| クラス | 説明 |
|---|---|
vote | グループは aria-label または legend で名前を付けた fieldset に適用します。上向き矢印、スコア、下向き矢印を縦に並べます。--votes には閲覧者自身の投票を含まないスコアを設定します。 |
vote-horizontal | コメント下のアクション行に置く、スコア横の矢印。スコアには数字 3 桁分の幅を確保します。vote と併用します |
vote-up | 上向き矢印のラジオボタンです。アクセシブルな名前は「Upvote」です。控えめな外観の32px四方のボタンで、選択中は矢印を前景色で塗りつぶします。 |
vote-score | 要素が空の場合にカウンターが表示するスコア。--votesをそのまま、または1増減して表示します。output 要素では、変更時に読み上げられます。1.2kなどのテキストが要素内にあれば、そのテキストが表示されます。 |
vote-down | 下向き矢印。上向き矢印と同じ name を持つラジオボタンで、アクセシブルな名前は「Downvote」。 |
#カスタムプロパティ
| プロパティ | 既定値 | 説明 |
|---|---|---|
--votes | 0 | 読み手自身の票を含まないスコア。選択した矢印に応じて1増減します。 |
--vote-size | 2rem | 各矢印の正方形領域の一辺。タッチ画面ではその周囲の操作領域が44pxになります |