Skip to main content
Login

Sign in to access your account

Radio Button - National Design System

A radio button picks one option from a set of choices

Overview

A radio button is a native <input type="radio"> drawn as a round tile, inside a form field with a label and optional info text. The options of one choice share a name and sit in a group under a legend, so the user can pick only one. The forms script starts every group, so a radio needs no script of its own.

Pick another component when:

  • the user can pick more than one option: Checkbox
  • the choice is one setting that takes effect at once: Switch
  • the list of options is long: a select, in Forms

Markup

Preview
Select your plan
<fieldset class="nds-form-group nds-radio-group"> <legend class="nds-label">Select your plan</legend> <div class="nds-form-container nds-radio"> <div class="nds-form-header"> <label for="radio-1"> <span class="nds-label">Basic</span> <span class="nds-info">Core features for individuals</span> </label> </div> <div class="nds-form-control"> <input type="radio" id="radio-1" name="plan" value="basic" class="nds-radio-input" checked> </div> </div> <div class="nds-form-container nds-radio"> <div class="nds-form-header"> <label for="radio-2"> <span class="nds-label">Professional</span> <span class="nds-info">Advanced tools for teams</span> </label> </div> <div class="nds-form-control"> <input type="radio" id="radio-2" name="plan" value="pro" class="nds-radio-input"> </div> </div> <div class="nds-form-container nds-radio"> <div class="nds-form-header"> <label for="radio-3"> <span class="nds-label">Enterprise</span> <span class="nds-info">Full access with dedicated support</span> </label> </div> <div class="nds-form-control"> <input type="radio" id="radio-3" name="plan" value="enterprise" class="nds-radio-input"> </div> </div> </fieldset>

Behavior

Readonly

data-state~="readonly" on each option’s container shows the value and stops the change, by pointer or by keyboard. The fill keeps its color, so the choice stays readable.

Required Group

data-required on the group makes the user pick an option. The form checks it on submit, and once it shows an error, each change checks it again. Call NDS.Form.clearStatus(group) to clear it.

Built-in Features

  • Form Integration

    The forms script starts every radio. A container follows the disabled state of its input, in both directions. Required belongs to the group, not to one input.

  • Visual Feedback

    A ripple grows around the tile on hover. Three sizes (SM, MD and LG) scale the tile and its checked ring together.

  • Responsive Layout

    On a phone, the gaps between a radio, its label and the next option are smaller.

Best Practices

  • Put every group in a <fieldset class="nds-form-group nds-radio-group"> with a <legend> that names the choice. Screen readers read the legend with each option.
  • For many short options, such as times of day, put them in a <div class="nds-grid" style="--min-width: 6.5rem;"> inside the group, after the <legend>, so they line up in as many columns as fit. Do not put nds-grid on the <fieldset> itself: it stretches the legend.
  • Give every radio of a group the same name, so the browser treats them as one choice.
  • Offer at least two options. For one yes-or-no setting, use a Switch or a Checkbox.
  • Check one option by default when most users will want it. Leave all unchecked when the user must decide.
  • Put data-required on the group, not on one input, so the group is validated as a whole.
  • Use nds-neutral when the choice is not a brand action.
  • To lock a whole group, put data-state="readonly" on every option’s container.
  • Use the default size in dense forms and tables, nds-md in most forms, and nds-lg on touch-first screens.
  • For the label, info text, feedback and the required mark, see Forms. They work the same on every field.

API

Data Attributes

Attribute Element Effect
data-required .nds-radio-group The user must pick an option before the form submits. It also adds the required mark to the legend
data-error-message .nds-radio-group Replaces the default message, “Please select an option”
data-state~="disabled" .nds-radio-group Disables every input in the group, and turns off pointer events. The group’s title takes the disabled color
data-state~="readonly" .nds-radio The option cannot change. The tile outline takes the disabled color
data-feedback-target an element inside the group Receives the group’s feedback message. Without one, the message goes at the end of the group

CSS Custom Properties

Set these on .nds-radio. The size classes set the first one.

Property Default Controls
--nds-input-size 16px Tile size and label line height. nds-md and nds-lg set 20px and 24px
--radio-tile-bg var(--background-default) Tile background
--radio-tile-border var(--controls-border) Tile outline color

Tokens

Set a token at :root, or on a wrapper to reach every radio inside it. Give a token with a Dark mode value a dark override too: see Tokens.

Source: the radio group in _sass/tokens/_components.scss.

TokenPreviewValue
--radio-primary-checked
var(--controls-primary-checked)
Dark mode var(--colors-primary-500)
--radio-primary-hovered
var(--controls-primary-hovered)
Dark mode var(--colors-primary-400)
--radio-primary-pressed
var(--controls-primary-pressed)
Dark mode var(--colors-primary-600)
--radio-neutral-checked
var(--controls-neutral-checked)
Dark mode var(--colors-neutral-400)
--radio-neutral-hovered
var(--controls-neutral-hovered)
Dark mode var(--colors-neutral-300)
--radio-neutral-pressed
var(--controls-neutral-pressed)
Dark mode var(--colors-neutral-300)

It also reads these shared tokens. A change to one also changes other components.

Source: the var() reads in _sass/components/_radio.scss.

TokenPreviewValue
--background-default
Read by --radio-tile-bg, border

var(--colors-base-white)
Dark mode var(--colors-neutral-800)
--background-primaryvar(--colors-primary-600)
--border-disabled
Read by --radio-tile-border

var(--colors-neutral-300)
Dark mode var(--colors-neutral-600)
--focus-outline
Read by outline

var(--colors-base-black)
Dark mode var(--colors-base-white)
--controls-neutral-hovered
Read by --radio-tile-border

var(--colors-neutral-600)
Dark mode var(--colors-neutral-400)
--controls-neutral-pressed
Read by --radio-tile-border

var(--colors-neutral-600)
Dark mode var(--colors-neutral-400)
--controls-border
Read by --radio-tile-border

var(--colors-neutral-500)
Dark mode var(--colors-neutral-400)
--controls-disabled
Read by --radio-tile-bg

var(--colors-neutral-400)
Dark mode var(--colors-alpha-white-30)

JavaScript

Method Effect
NDS.Radio.getValue(el) Returns the value of the checked radio, or '' when none is checked or the group is not found. el is the .nds-form-group, a radio in it, its id or a selector
NDS.Radio.setValue(el, value) Checks the radio with that value as a user does, and returns true. It returns false, and changes nothing, when no radio has the value
NDS.Radio.clear(el) Unchecks the checked radio
NDS.Radio.validate(group, options) Checks the group and returns { valid, selected, message }: selected is true when an option is checked. Pass { showMessage: false } to check without a message
NDS.Form.refresh(input) Updates the field after you set .checked from code. It fires no event
NDS.Form.setStatus(group, status, { message }) Shows a status and a message on the group, such as an error from the server
NDS.Form.clearStatus(group) Removes the group’s feedback message
var group = document.querySelector('.nds-radio-group'); var result = NDS.Radio.validate(group); // { valid: false, selected: false, message: 'Please select an option' } var radio = document.querySelector('#radio-2'); radio.checked = true; NDS.Form.refresh(radio);

The full API is in the banner of _js/nds-radio.js.

Last Modified Date: 05/11/2026 - 12:02 PM
Was this page useful?
60% of users said Yes from 2843 Feedbacks