component
Radio
One choice out of a few, all on show. A 20px circle with a dot in the picked one, and the words beside it.
Try it
Every variant
Default · Not checkedDisabled · Not checkedDefault · CheckedDisabled · CheckedHover, press or tab to one to see the other 6 states.
import { Radio } from 'rost/components/radio/Radio'
<fieldset>
<legend>How often do you invoice?</legend>
<Radio name="often" value="month" defaultChecked>Every month</Radio>
<Radio name="often" value="quarter">Every quarter</Radio>
</fieldset> src/components/radio/Radio.tsx
import { useEffect, useRef, useState, type InputHTMLAttributes, type ReactNode } from 'react'
import './radio.css'
export interface RadioProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type' | 'children'> {
/** The words beside it. Without them, give it an `aria-label`. */
readonly children?: ReactNode
/** Called with the new value each time it changes. */
readonly onCheckedChange?: (checked: boolean) => void
}
const b = 'rost-radio'
/**
* One choice out of a few. A real `<input type="radio">`: give the radios of one
* question the same `name` and put them in a `<fieldset>` with a `<legend>`.
* It sits inside a `<label>`, so forms, Space and screen readers work as they always do.
* Built from contracts/radio.contract.yaml.
*/
export function Radio({ children, checked, defaultChecked = false, onChange, onCheckedChange, className, style, ...rest }: RadioProps) {
const [own, setOwn] = useState(defaultChecked)
const on = checked ?? own
const input = useRef<HTMLInputElement>(null)
// Picking another radio of the group unpicks this one without telling it,
// so on its own it listens for changes in its group.
useEffect(() => {
if (checked !== undefined) return
const sync = (e: Event) => {
const t = e.target as HTMLInputElement
if (t !== input.current && t.type === 'radio' && t.name && t.name === input.current?.name) setOwn(input.current.checked)
}
document.addEventListener('change', sync)
return () => document.removeEventListener('change', sync)
}, [checked])
return (
<label className={[b, on && `${b}--checked`, className].filter(Boolean).join(' ')} style={style}>
<input
ref={input}
type="radio"
className={`${b}__input`}
checked={on}
onChange={(e) => {
onChange?.(e)
if (checked === undefined) setOwn(e.target.checked)
onCheckedChange?.(e.target.checked)
}}
{...rest}
/>
<span className={`${b}__box`} aria-hidden="true">
<span className={`${b}__dot`} />
<span className={`${b}__focus-ring`} />
</span>
{children != null && <span className={`${b}__label`}>{children}</span>}
</label>
)
}
The source for everything on this page: contracts/radio.contract.yaml (opens in a new tab). The CSS, the docs and the checks in each app are built from it.
# yaml-language-server: $schema=../schema/component-contract.schema.json
schemaVersion: 2
id: radio
name: Radio
kind: component
status: review
summary: One choice out of a few, all on show. A 20px circle with a dot in the picked one, and the words beside it.
category: selection
related: [ checkbox, toggle-group, chips ]
source:
tool: figma
fileKey: 1Zy0wiWKXQAvsfDBX3KR0d
nodeId: "733:124"
url: https://www.figma.com/design/1Zy0wiWKXQAvsfDBX3KR0d/UI-Kit-v01?node-id=733-124
extractedAt: "2026-11-16"
extractedBy: hand
frozenAt: "2026-11-16"
props:
checked: { type: boolean, default: false, notes: "Picked or not. Radios with the same `name` are one group, and the browser keeps only one of them picked." }
children: { type: slot, notes: "The label, beside the circle. Leave it out only when something else names it (`aria-label`)." }
states: [ Default, Hover, Pressed, Focus, Disabled ]
stateSelectors:
Focus: ":has(> .rost-radio__input:focus-visible)"
Disabled: ":has(> .rost-radio__input:disabled)"
elements:
root:
notes: "A `<label>` around the input, the circle and the words, so a press anywhere on it counts. Hover and press come from the label."
styles:
display: { value: inline-flex, assert: false }
align-items: { value: center }
gap: { token: spacing/gap/small, value: 8px }
vertical-align: { value: middle, assert: false }
position: { value: relative, assert: false }
cursor: { value: pointer, assert: false }
input:
notes: "The real `<input type=\"radio\">`, there for the keyboard, forms and screen readers, and hidden from sight. The circle draws what it says."
styles:
position: { value: absolute, assert: false }
width: { value: 1px, assert: false }
height: { value: 1px, assert: false }
opacity: { value: "0", assert: false }
pointer-events: { value: none, assert: false }
box:
notes: "The 20px circle. Empty it's the page's colour inside a field's edge. Picked it's filled with the primary green."
styles:
position: { value: relative, assert: false }
flex-shrink: { value: "0", assert: false }
width: { token: spacing/size/xsmall, value: 20px }
height: { token: spacing/size/xsmall, value: 20px }
border-radius: { token: spacing/radius/full, value: 10000px }
outline-style: { value: solid, assert: false, notes: "Drawn inside the box, like Switch's track, so it can be seen against the page." }
outline-width: { token: spacing/outline/small, value: 1px }
outline-offset: { value: "calc(-1 * var(--spacing-outline-small))", untokenised: "Composed from a token: the edge sits inside the box." }
dot:
notes: "The 8px dot in the middle, in the colour of a primary button's label: 6px in from the edge."
styles:
position: { value: absolute }
inset: { token: spacing/gap/xsmall, value: 6px }
border-radius: { token: spacing/radius/full, value: 10000px }
pointer-events: { value: none, assert: false }
focus-ring:
notes: "Around the circle, keeping its shape."
styles:
display: { value: none, assert: false }
position: { value: absolute }
inset: { value: "calc(-1 * var(--spacing-gap-2xsmall))", untokenised: "Composed from a token: the ring sits spacing/gap/2xsmall outside the circle." }
border-style: { value: solid }
border-width: { token: spacing/outline/medium, value: 2px }
border-radius: { token: spacing/radius/full, value: 10000px }
pointer-events: { value: none, assert: false }
label:
notes: "The words. Paragraph type, in the colour SwitchField's label has. It doesn't change when it's picked: the circle says that."
styles:
font-family: { token: font-family/base, value: "'General Sans Variable'" }
font-weight: { token: typography/paragraph/font-weight/regular, value: "400" }
font-size: { token: typography/paragraph/font-size, value: 14px }
line-height: { token: typography/paragraph/line-height, value: 20px }
letter-spacing: { token: typography/paragraph/letter-spacing, value: 0px }
color: { token: radio/label, value: "#d3d9d5" }
variants:
- when: { checked: false }
elements:
dot:
display: { value: none, assert: false }
- when: { checked: true }
elements:
box:
outline-color: { token: radio/on/edge, value: "#00d669", notes: "The fill's own green in dark. In light it's a dark green, because the bright fill is 1.9:1 on white, the way Switch's track does it." }
dot:
display: { value: block, assert: false }
- when: { state: Focus }
elements:
focus-ring:
display: { value: block, assert: false }
- when: { state: Disabled }
elements:
root:
opacity: { token: opacity/gentle, value: "0.24" }
cursor: { value: default, assert: false }
- when: { state: Default, checked: false }
figmaNode: "733:73"
elements:
box:
background: { token: radio/off/default/box, value: "#060805" }
outline-color: { token: radio/off/default/edge, value: "#747573" }
- when: { state: Hover, checked: false }
figmaNode: "733:78"
elements:
box:
background: { token: radio/off/hover/box, value: "#171717" }
outline-color: { token: radio/off/hover/edge, value: "#999999" }
- when: { state: Pressed, checked: false }
figmaNode: "733:83"
elements:
box:
background: { token: radio/off/pressed/box, value: "#171717" }
outline-color: { token: radio/off/pressed/edge, value: "#999999" }
- when: { state: Focus, checked: false }
figmaNode: "733:88"
elements:
box:
background: { token: radio/off/focus/box, value: "#060805" }
outline-color: { token: radio/off/focus/edge, value: "#747573" }
focus-ring:
border-color: { token: radio/off/focus/focus-ring, value: "#999" }
- when: { state: Disabled, checked: false }
figmaNode: "733:93"
elements:
box:
background: { token: radio/off/disabled/box, value: "#060805" }
outline-color: { token: radio/off/disabled/edge, value: "#747573" }
- when: { state: Default, checked: true }
figmaNode: "733:98"
elements:
box:
background: { token: radio/on/default/box, value: "#00d669" }
dot:
background: { token: radio/on/default/dot, value: "#060805" }
- when: { state: Hover, checked: true }
figmaNode: "733:103"
elements:
box:
background: { token: radio/on/hover/box, value: "#00b450" }
dot:
background: { token: radio/on/hover/dot, value: "#060805" }
- when: { state: Pressed, checked: true }
figmaNode: "733:108"
elements:
box:
background: { token: radio/on/pressed/box, value: "#00913a" }
dot:
background: { token: radio/on/pressed/dot, value: "#060805" }
- when: { state: Focus, checked: true }
figmaNode: "733:113"
elements:
box:
background: { token: radio/on/focus/box, value: "#00d669" }
dot:
background: { token: radio/on/focus/dot, value: "#060805" }
focus-ring:
border-color: { token: radio/on/focus/focus-ring, value: "#b6ffda" }
- when: { state: Disabled, checked: true }
figmaNode: "733:118"
elements:
box:
background: { token: radio/on/disabled/box, value: "#00d669" }
dot:
background: { token: radio/on/disabled/dot, value: "#060805" }
guidance:
status: proposed
use:
- title: One out of a few
text: "Two to five choices where seeing them all helps you pick: how often to invoice, which currency."
show: state=Default, checked=True
avoid:
- title: Many choices
text: "More than five or six, or a list that changes. That's a select, and Rost doesn't have one yet."
- title: Switching a view
text: "Picking which view the screen shows. That's **ToggleGroup** or **Tabs**."
behaviour: |-
Put the radios of one question in a `<fieldset>` with a `<legend>` that asks it, and give them the same `name`. The browser does the rest: one picked at a time, and the arrow keys move between them. Empty is a field's edge around the page colour. Picked fills with the primary green, with a dark dot. Disabled fades the row.
accessibility:
element: "A real `<input type=\"radio\">` inside a `<label>`. The input is hidden from sight, not from screen readers."
name: "The words beside it. The `<legend>` names the group."
keyboard: "Tab reaches the group, on the picked one. The arrow keys move the pick."
focus: "`focus-ring` around the circle, on `:focus-visible`."
colour: "Picked isn't only green: the dot is there too. Picked, the edge is the fill's green in dark and a dark green in light, so the circle stands out at 3:1 or more on both."
content: "Short, parallel answers to the legend's question, in sentence case."
Install
npx github:Runceanu/rost add radio It lands in src/rost/radio/, with what it needs and its contract. Install has the rest.
When to use
One out of a few
Two to five choices where seeing them all helps you pick: how often to invoice, which currency.
When not to use
Many choices
More than five or six, or a list that changes. That's a select, and Rost doesn't have one yet.
Switching a view
Picking which view the screen shows. That's ToggleGroup or Tabs.
Behaviour
Put the radios of one question in a <fieldset> with a <legend> that asks it, and give them the same name. The browser does the rest: one picked at a time, and the arrow keys move between them. Empty is a field's edge around the page colour. Picked fills with the primary green, with a dark dot. Disabled fades the row.
Accessibility
- Element
A real
<input type="radio">inside a<label>. The input is hidden from sight, not from screen readers. - Name
The words beside it. The
<legend>names the group. - Keyboard
Tab reaches the group, on the picked one. The arrow keys move the pick.
- Focus
focus-ringaround the circle, on:focus-visible. - Colour
Picked isn't only green: the dot is there too. Picked, the edge is the fill's green in dark and a dark green in light, so the circle stands out at 3:1 or more on both.
Content
Short, parallel answers to the legend's question, in sentence case.
Props
| Prop | Type | Values | Default |
|---|---|---|---|
checked | boolean | | false |
children | slot | | |
States: Default, Hover, Pressed, Focus, Disabled.
Values
Straight from the contract. Each value sits next to its token, because six tokens here all come out as #3a3a3a and the colour alone can't tell you which one is right.
Never changes
root
-
gap8pxspacing/gap/small
displayinline-flex · align-itemscenter · vertical-alignmiddle · positionrelative · cursorpointer
input
positionabsolute · width1px · height1px · opacity0 · pointer-eventsnone
box
-
width20pxspacing/size/xsmall -
height20pxspacing/size/xsmall -
border-radius10000pxspacing/radius/full -
outline-width1pxspacing/outline/small -
outline-offsetcalc(-1 * var(--spacing-outline-small))on purpose: Composed from a token: the edge sits inside the box.
positionrelative · flex-shrink0 · outline-stylesolid
dot
-
inset6pxspacing/gap/xsmall -
border-radius10000pxspacing/radius/full
positionabsolute · pointer-eventsnone
focus-ring
-
border-stylesolidno token yet -
border-width2pxspacing/outline/medium -
border-radius10000pxspacing/radius/full
displaynone · positionabsolute · insetcalc(-1 * var(--spacing-gap-2xsmall)) · pointer-eventsnone
label
-
font-family'General Sans Variable'font-family/base -
font-weight400typography/paragraph/font-weight/regular -
font-size14pxtypography/paragraph/font-size -
line-height20pxtypography/paragraph/line-height -
letter-spacing0pxtypography/paragraph/letter-spacing -
color#d3d9d5radio/label
Changes by variant
10 variants. Each table is what one thing changes with: a column per state, a row per property. Where every row starts with the same token path, it's written once, under the property.
Follows state
Checked
| Property | Default | Hover | Pressed | Focus | Disabled |
|---|---|---|---|---|---|
dot.backgroundradio/on/… | default/dot #060805 | hover/dot #060805 | pressed/dot #060805 | focus/dot #060805 | disabled/dot #060805 |
Follows checked
| Property | Not checked | Checked |
|---|---|---|
dot.display | none | block |
Focus
| Property | Not checked | Checked |
|---|---|---|
focus-ring.border-colorradio/… | off/focus/focus-ring #999 | on/focus/focus-ring #b6ffda |
Follows state and checked
Not checked
| Property | Default | Hover | Pressed | Focus | Disabled |
|---|---|---|---|---|---|
box.backgroundradio/off/… | default/box #060805 | hover/box #171717 | pressed/box #171717 | focus/box #060805 | disabled/box #060805 |
box.outline-colorradio/off/… | default/edge #747573 | hover/edge #999999 | pressed/edge #999999 | focus/edge #747573 | disabled/edge #747573 |
Checked
| Property | Default | Hover | Pressed | Focus | Disabled |
|---|---|---|---|---|---|
box.backgroundradio/on/… | default/box #00d669 | hover/box #00b450 | pressed/box #00913a | focus/box #00d669 | disabled/box #00d669 |
box.outline-colorradio/on/… | edge #00d669 | edge #00d669 | edge #00d669 | edge #00d669 | edge #00d669 |
Only in some variants
These don't change: they're just set in some variants and not others.
Focus
-
focus-ring.displayblocklayout
Disabled
-
root.cursordefaultFigma frame size -
root.opacity0.24opacity/gentle