Skip to content
VinUIComponentsRadio Group

Radio Group

Pick exactly one option from a short list. Same markup and props in every style: switch the style in the header to see it change.

Basic

Native radios in a fieldset. The legend names the group, and ↑ ↓ move between options with no JavaScript. Uses the same label layout as Checkbox.

Email me
radio-group-basic.html
<fieldset class="vin-radio-group">
  <legend class="vin-radio-group__legend">Email me</legend>
  <div class="vin-choice">
    <input id="freq-instant" class="vin-radio" type="radio" name="frequency" value="instant">
    <div class="vin-choice__body"><label class="vin-choice__label" for="freq-instant">Instantly</label></div>
  </div>
  <div class="vin-choice">
    <input id="freq-daily" class="vin-radio" type="radio" name="frequency" value="daily" checked>
    <div class="vin-choice__body"><label class="vin-choice__label" for="freq-daily">Once a day</label></div>
  </div>
  <div class="vin-choice">
    <input id="freq-weekly" class="vin-radio" type="radio" name="frequency" value="weekly">
    <div class="vin-choice__body"><label class="vin-choice__label" for="freq-weekly">Once a week</label></div>
  </div>
  <div class="vin-choice">
    <input id="freq-never" class="vin-radio" type="radio" name="frequency" value="never">
    <div class="vin-choice__body"><label class="vin-choice__label" for="freq-never">Never</label></div>
  </div>
</fieldset>

Horizontal

Short options can sit in a row. A disabled option stays readable.

Size
radio-group-horizontal.html
<fieldset class="vin-radio-group vin-radio-group--horizontal">
  <legend class="vin-radio-group__legend">Size</legend>
  <div class="vin-choice">
    <input id="size-s" class="vin-radio" type="radio" name="size" value="s">
    <div class="vin-choice__body"><label class="vin-choice__label" for="size-s">S</label></div>
  </div>
  <div class="vin-choice">
    <input id="size-m" class="vin-radio" type="radio" name="size" value="m" checked>
    <div class="vin-choice__body"><label class="vin-choice__label" for="size-m">M</label></div>
  </div>
  <div class="vin-choice">
    <input id="size-l" class="vin-radio" type="radio" name="size" value="l">
    <div class="vin-choice__body"><label class="vin-choice__label" for="size-l">L</label></div>
  </div>
  <div class="vin-choice">
    <input id="size-xl" class="vin-radio" type="radio" name="size" value="xl" disabled>
    <div class="vin-choice__body"><label class="vin-choice__label" for="size-xl">XL (sold out)</label></div>
  </div>
</fieldset>

Cards

Bigger targets with a description each, for plans and other important choices. The whole card is clickable.

Plan

Free for personal projects.

For small teams, billed monthly.

Single sign-on and priority support.

radio-group-cards.html
<fieldset class="vin-radio-group vin-radio-group--cards" style="width: 100%; max-width: 360px">
  <legend class="vin-radio-group__legend">Plan</legend>
  <div class="vin-choice">
    <input id="plan-hobby" class="vin-radio" type="radio" name="plan" value="hobby" aria-describedby="plan-hobby-desc">
    <div class="vin-choice__body">
      <label class="vin-choice__label" for="plan-hobby">Hobby</label>
      <p class="vin-choice__desc" id="plan-hobby-desc">Free for personal projects.</p>
    </div>
  </div>
  <div class="vin-choice">
    <input id="plan-pro" class="vin-radio" type="radio" name="plan" value="pro" checked aria-describedby="plan-pro-desc">
    <div class="vin-choice__body">
      <label class="vin-choice__label" for="plan-pro">Pro</label>
      <p class="vin-choice__desc" id="plan-pro-desc">For small teams, billed monthly.</p>
    </div>
  </div>
  <div class="vin-choice">
    <input id="plan-enterprise" class="vin-radio" type="radio" name="plan" value="enterprise" aria-describedby="plan-enterprise-desc">
    <div class="vin-choice__body">
      <label class="vin-choice__label" for="plan-enterprise">Enterprise</label>
      <p class="vin-choice__desc" id="plan-enterprise-desc">Single sign-on and priority support.</p>
    </div>
  </div>
</fieldset>

Installation

React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:

Terminal
npx @vinish/ui add radio-group
React
import { RadioGroup } from "@/components/vin/radio-group";
Vue
import RadioGroup from "@/components/vin/radio-group.vue";
Svelte
import RadioGroup from "$lib/components/vin/radio-group.svelte";

The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.

Plain HTML: the classes come with the style's stylesheet. It needs no JavaScript.

API

From spec/radio-group.json, which every framework version is tested against.

PropValuesDefaultIn HTML
label
The group's name, shown as the legend.
ReactNode—<legend class="vin-radio-group__legend">
options
The choices.
(string | { value, label, description?, disabled? })[]—.vin-choice > input.vin-radio per option
value / defaultValue
The chosen value (controlled or not). Use onValueChange to hear about changes.
string—checked attribute
name
Form field name. Generated if you leave it out.
string—name attribute (the same on every radio)
orientationverticalhorizontalverticalvin-radio-group--horizontal
variantdefaultcardsdefaultvin-radio-group--cards
error
An error message. Also marks the radios invalid.
ReactNode—<p class="vin-error"> + aria-describedby on the fieldset
disabledbooleanfalsedisabled on the fieldset, or on one radio

Parts

React, Vue, SvelteHTML classes
<RadioGroup>.vin-radio-group.vin-radio-group--horizontal.vin-radio-group--cards.vin-radio-group__legend.vin-radio

Accessibility

  • Native <input type="radio"> with one shared name: arrow keys move and select, Tab enters and leaves the group.
  • A <fieldset> with a <legend> gives the group its name.
  • Every radio has a <label for>; descriptions are linked with aria-describedby.
  • In cards, the label covers the whole card, so the click target is large and still one labelled control.
  • Visible focus ring in every style and mode.