Radio Button
A single-choice group with a growing dot and arrow-key navigation.
AI prompt
Build a radio group "Delivery speed" with three option cards (Standard — free, Express — $9, Same day — $19), each a label wrapping a real input type="radio" name="speed" (visually hidden), a 22px ring with an inner dot, a title and a one-line description. Selecting a card highlights its border with the accent colour and scales the dot from 0 to 1 over 180ms with cubic-bezier(0.3,1.6,0.5,1). Standard is preselected. Keep native arrow-key behaviour and one tab stop for the group, wrap the group in a fieldset with a legend, show a 2px focus-visible ring on the card, and include a disabled option at 40% opacity. Print the selected value below the group. Disable the overshoot under prefers-reduced-motion.About this pattern
Definition
A group of options where exactly one can be selected. Selecting one automatically deselects the others. The selected option shows a dot that grows inside a ring.
Purpose & UX principles
- Use radio buttons when the choices are mutually exclusive and the list is short enough to scan at once (about 2 to 6 options).
- For longer lists use a dropdown instead.
- Always preselect the safest or most common option unless a deliberate choice is needed.
Interaction states
- Unselected, selected, hover, focus-visible, disabled.
- Native radios give arrow-key movement inside a group and a single tab stop for free; do not replace them with divs.
Motion specification
- Dot: scale from 0 to 1 in 180ms with a slight overshoot.
- Card border colour: 160ms.
- Reduced motion: dot appears instantly.
Responsive behaviour
- Stack the options vertically; each row is at least 44px tall and fully clickable.
- Option "cards" with a description work well on phones.
Code
<fieldset class="rg"><legend>Delivery speed</legend>
<label class="o"><input type="radio" name="s" value="standard" checked><i></i><span><b>Standard</b><small>3–5 days · Free</small></span></label>
<label class="o"><input type="radio" name="s" value="express"><i></i><span><b>Express</b><small>1–2 days · $9</small></span></label>
<label class="o"><input type="radio" name="s" value="same-day"><i></i><span><b>Same day</b><small>Today · $19</small></span></label>
<label class="o dis"><input type="radio" name="s" value="drone" disabled><i></i><span><b>Drone</b><small>Not in your area</small></span></label>
</fieldset>
<p class="out">Selected: <b id="v">standard</b></p>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
.rg{width:min(340px,100%);border:0;display:grid;gap:10px}
legend{margin-bottom:10px;color:var(--muted);font-size:12px;letter-spacing:.12em;text-transform:uppercase}
.o{position:relative;display:flex;gap:14px;align-items:center;min-height:64px;padding:12px 16px;border:1px solid var(--line);border-radius:14px;background:var(--surface);cursor:pointer;transition:border-color .16s,background .16s}
.o input{position:absolute;opacity:0}
.o i{flex:none;width:22px;height:22px;border-radius:50%;border:2px solid var(--muted);display:grid;place-items:center}
.o i::after{content:"";width:10px;height:10px;border-radius:50%;background:var(--accent);transform:scale(0);transition:transform .18s cubic-bezier(.3,1.6,.5,1)}
.o:has(input:checked){border-color:var(--accent);background:rgba(23,23,23,.04)}
.o input:checked+i{border-color:var(--accent)}
.o input:checked+i::after{transform:scale(1)}
.o:has(input:focus-visible){outline:2px solid var(--accent);outline-offset:2px}
.o b{display:block;font-size:15px}.o small{color:var(--muted);font-size:13px}
.dis{opacity:.4;cursor:not-allowed}
.out{margin-top:14px;color:var(--muted);font-size:14px;text-align:center}.out b{color:var(--accent)}
@media (prefers-reduced-motion:reduce){.o,.o i::after{transition:none}}const v=document.getElementById('v');
document.querySelectorAll('input[name=s]').forEach(r=>r.addEventListener('change',()=>{v.textContent=r.value;}));One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Radio Button — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
.rg{width:min(340px,100%);border:0;display:grid;gap:10px}
legend{margin-bottom:10px;color:var(--muted);font-size:12px;letter-spacing:.12em;text-transform:uppercase}
.o{position:relative;display:flex;gap:14px;align-items:center;min-height:64px;padding:12px 16px;border:1px solid var(--line);border-radius:14px;background:var(--surface);cursor:pointer;transition:border-color .16s,background .16s}
.o input{position:absolute;opacity:0}
.o i{flex:none;width:22px;height:22px;border-radius:50%;border:2px solid var(--muted);display:grid;place-items:center}
.o i::after{content:"";width:10px;height:10px;border-radius:50%;background:var(--accent);transform:scale(0);transition:transform .18s cubic-bezier(.3,1.6,.5,1)}
.o:has(input:checked){border-color:var(--accent);background:rgba(23,23,23,.04)}
.o input:checked+i{border-color:var(--accent)}
.o input:checked+i::after{transform:scale(1)}
.o:has(input:focus-visible){outline:2px solid var(--accent);outline-offset:2px}
.o b{display:block;font-size:15px}.o small{color:var(--muted);font-size:13px}
.dis{opacity:.4;cursor:not-allowed}
.out{margin-top:14px;color:var(--muted);font-size:14px;text-align:center}.out b{color:var(--accent)}
@media (prefers-reduced-motion:reduce){.o,.o i::after{transition:none}}
</style></head>
<body><div class="stage">
<fieldset class="rg"><legend>Delivery speed</legend>
<label class="o"><input type="radio" name="s" value="standard" checked><i></i><span><b>Standard</b><small>3–5 days · Free</small></span></label>
<label class="o"><input type="radio" name="s" value="express"><i></i><span><b>Express</b><small>1–2 days · $9</small></span></label>
<label class="o"><input type="radio" name="s" value="same-day"><i></i><span><b>Same day</b><small>Today · $19</small></span></label>
<label class="o dis"><input type="radio" name="s" value="drone" disabled><i></i><span><b>Drone</b><small>Not in your area</small></span></label>
</fieldset>
<p class="out">Selected: <b id="v">standard</b></p>
</div>
<script>
const v=document.getElementById('v');
document.querySelectorAll('input[name=s]').forEach(r=>r.addEventListener('change',()=>{v.textContent=r.value;}));
</script>
</body></html>