Skip to content

Radio Examples

The examples below assume that you have imported the component and set up the theme.

Basic

Group radios so one choice submits with a form. Radios with the same name form a group, and the checked one submits its value.

Shipping Standard Express Overnight
shipping=standard
<form class="radio-basic">
<fieldset role="radiogroup">
<legend>Shipping</legend>
<sv-radio checked name="shipping" value="standard">Standard</sv-radio>
<sv-radio name="shipping" value="express">Express</sv-radio>
<sv-radio name="shipping" value="overnight">Overnight</sv-radio>
</fieldset>
<output>shipping=standard</output>
</form>
<script type="application/x-typescript" module>
const form = document.querySelector<HTMLFormElement>(".radio-basic")!;
const output = form.querySelector("output")!;
form.addEventListener("submit", event => event.preventDefault());
form.addEventListener("change", () => {
output.textContent = `shipping=${new FormData(form).get("shipping")}`;
});
</script>
<style>
.radio-basic {
display: grid;
gap: 1em;
justify-items: center;
fieldset {
display: flex;
flex-direction: column;
gap: 0.6em;
border: none;
}
legend {
margin-block-end: 0.4em;
font-weight: 600;
}
output {
font-family: monospace;
font-size: 0.85em;
color: var(--sv-gray-3);
}
}
</style>

Checked and Disabled

Set the starting choice and disable an option. checked picks the starting radio, and disabled blocks a radio and skips it in keyboard navigation.

Free Pro Team
<div class="radio-states" aria-label="Plan" role="radiogroup">
<sv-radio checked name="plan" value="free">Free</sv-radio>
<sv-radio name="plan" value="pro">Pro</sv-radio>
<sv-radio disabled name="plan" value="team">Team</sv-radio>
</div>
<style>
.radio-states {
display: flex;
flex-wrap: wrap;
gap: 1.5em;
justify-content: center;
}
</style>

Custom Dot

Show your own check mark inside the ring. An SVG in the dot slot draws the mark, --sv-radio-active-bdr-sz thins the checked border that would draw the default dot, and :state(--checked) scales the mark in.

Monthly Yearly
<div class="radio-dot" aria-label="Billing" role="radiogroup">
<sv-radio checked name="billing" value="monthly">
<!-- Check -->
<svg aria-hidden="true" slot="dot" viewBox="0 0 24 24">
<path d="M5 12.5l4.5 4.5L19 7.5" />
</svg>
Monthly
</sv-radio>
<sv-radio name="billing" value="yearly">
<!-- Check -->
<svg aria-hidden="true" slot="dot" viewBox="0 0 24 24">
<path d="M5 12.5l4.5 4.5L19 7.5" />
</svg>
Yearly
</sv-radio>
</div>
<style>
.radio-dot {
display: flex;
gap: 1.5em;
justify-content: center;
sv-radio {
--sv-radio-sz: 1.4em;
--sv-radio-active-bdr-sz: 2px;
}
svg {
inline-size: 60%;
block-size: 60%;
fill: none;
stroke: var(--sv-accent, AccentColor);
stroke-width: 3;
stroke-linecap: round;
stroke-linejoin: round;
scale: 0;
transition: scale 200ms ease-out;
}
sv-radio:state(--checked) svg {
scale: 1;
}
@media (prefers-reduced-motion: reduce) {
svg {
transition-duration: 0s;
}
}
}
</style>