Vote
A score that a reader moves up or down by one, for an answer, a post or a comment.
On this page
A vote is a score that each reader may move up or down by one: the score of an answer, a post or a comment. The two arrows are native radios of one group, drawn as quiet square buttons, and the score between them is a CSS counter, so a press moves the number with no script.
Vote
<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>#The score
Set --votes on the group to the score without the reader's vote. The checked up arrow adds one and the checked down arrow takes one away, so a page that knows the reader's vote checks that arrow and gives the score of everyone else. Leave vote-score empty and the counter writes the score, with a true minus sign when it is below zero; write text inside it, such as 1.4k, for a score too large to count by one.
#In a row
vote-horizontal puts the arrows on either side of the score, for a row of actions under a comment. The score keeps the width of three figures, so the arrows do not move when it changes.
In a row
<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>#States
At rest an arrow is an outline in muted ink with no face of its own. Under the pointer it rises as a small sheet, under a press it sinks into a well, and chosen it fills with ink. Up and down are told apart by direction, not by hue. Disable the fieldset to show a score that cannot be voted on, such as one on the reader's own post: the arrows fade and the score stays.
States
<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>#Taking a vote back
A radio cannot be cleared by pressing it again, so without a script a reader can change a vote but not withdraw it. The vote behavior lets a second press on the chosen arrow, or Space on it, clear the vote, and the score returns to --votes.
Taking a vote back
<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>#Accessibility
- Name the group with
aria-labelor a<legend>, and each radio: "Upvote" and "Downvote". - Put the score in an
<output>. It is read where it stands, between the two arrows, and as a status it is announced when a vote changes it. - The arrows keep their focus ring: the glyph is drawn on a pseudo-element, so no mask cuts the ring. Arrow keys move the vote between the two radios, as in any radio group.
- Each arrow is 32px at every pointer; on a touch screen its target reaches 44px around it. In forced colors the glyphs take the button text color, and the chosen one the highlight color.
#Classes
| Class | Description |
|---|---|
vote | The group, on a fieldset named by aria-label or a legend: an up arrow, the score and a down arrow, stacked. Set --votes to the score without the reader's vote |
vote-horizontal | The arrows beside the score, for a row of actions under a comment; the score keeps the width of three figuresApply with vote |
vote-up | The up arrow, a radio named "Upvote": a quiet 32px square whose arrow fills with ink while checked |
vote-score | The score, written by the counter when the element is empty: --votes, one more or one less. On an output, it is announced when it changes. Text inside it, such as 1.2k, is shown instead |
vote-down | The down arrow, a radio of the same name as the up arrow, named "Downvote" |
#Custom properties
| Property | Default | Description |
|---|---|---|
--votes | 0 | The score without the reader's vote; the checked arrow adds or takes one |
--vote-size | 2rem | The side of each arrow's square; on a touch screen the target around it is 44px |