Skip to main content
Light Dark System

Radio Button

<sc-radio-button> | ScRadioButton
Since 2.0 stable

Radios buttons allow the user to select a single option from a group using a button-like control.

Radio buttons are designed to be used with radio groups. When a radio button has focus, the arrow keys can be used to change the selected option just like standard radio controls.

Option 1 Option 2 Option 3
<sc-radio-group label="Select an option" name="a" value="1">
  <sc-radio-button value="1">Option 1</sc-radio-button>
  <sc-radio-button value="2">Option 2</sc-radio-button>
  <sc-radio-button value="3">Option 3</sc-radio-button>
</sc-radio-group>
import ScRadioButton from '@styledc-dev/styledc/dist/react/radio-button';
import ScRadioGroup from '@styledc-dev/styledc/dist/react/radio-group';

const App = () => (
  <ScRadioGroup label="Select an option" name="a" value="1">
    <ScRadioButton value="1">Option 1</ScRadioButton>
    <ScRadioButton value="2">Option 2</ScRadioButton>
    <ScRadioButton value="3">Option 3</ScRadioButton>
  </ScRadioGroup>
);

Examples

Checked States

To set the initial value and checked state, use the value attribute on the containing radio group.

Option 1 Option 2 Option 3
<sc-radio-group label="Select an option" name="a" value="1">
  <sc-radio-button value="1">Option 1</sc-radio-button>
  <sc-radio-button value="2">Option 2</sc-radio-button>
  <sc-radio-button value="3">Option 3</sc-radio-button>
</sc-radio-group>
import ScRadioButton from '@styledc-dev/styledc/dist/react/radio-button';
import ScRadioGroup from '@styledc-dev/styledc/dist/react/radio-group';

const App = () => (
  <ScRadioGroup label="Select an option" name="a" value="1">
    <ScRadioButton value="1">Option 1</ScRadioButton>
    <ScRadioButton value="2">Option 2</ScRadioButton>
    <ScRadioButton value="3">Option 3</ScRadioButton>
  </ScRadioGroup>
);

Disabled

Use the disabled attribute to disable a radio button.

Option 1 Option 2 Option 3
<sc-radio-group label="Select an option" name="a" value="1">
  <sc-radio-button value="1">Option 1</sc-radio-button>
  <sc-radio-button value="2" disabled>Option 2</sc-radio-button>
  <sc-radio-button value="3">Option 3</sc-radio-button>
</sc-radio-group>
import ScRadioButton from '@styledc-dev/styledc/dist/react/radio-button';
import ScRadioGroup from '@styledc-dev/styledc/dist/react/radio-group';

const App = () => (
  <ScRadioGroup label="Select an option" name="a" value="1">
    <ScRadioButton value="1">Option 1</ScRadioButton>
    <ScRadioButton value="2" disabled>
      Option 2
    </ScRadioButton>
    <ScRadioButton value="3">Option 3</ScRadioButton>
  </ScRadioGroup>
);

Sizes

Use the size attribute to change a radio button’s size.

Option 1 Option 2 Option 3
Option 1 Option 2 Option 3
Option 1 Option 2 Option 3
<sc-radio-group size="small" label="Select an option" name="a" value="1">
  <sc-radio-button value="1">Option 1</sc-radio-button>
  <sc-radio-button value="2">Option 2</sc-radio-button>
  <sc-radio-button value="3">Option 3</sc-radio-button>
</sc-radio-group>

<br />

<sc-radio-group size="medium" label="Select an option" name="a" value="1">
  <sc-radio-button value="1">Option 1</sc-radio-button>
  <sc-radio-button value="2">Option 2</sc-radio-button>
  <sc-radio-button value="3">Option 3</sc-radio-button>
</sc-radio-group>

<br />

<sc-radio-group size="large" label="Select an option" name="a" value="1">
  <sc-radio-button value="1">Option 1</sc-radio-button>
  <sc-radio-button value="2">Option 2</sc-radio-button>
  <sc-radio-button value="3">Option 3</sc-radio-button>
</sc-radio-group>
import ScRadioButton from '@styledc-dev/styledc/dist/react/radio-button';
import ScRadioGroup from '@styledc-dev/styledc/dist/react/radio-group';

const App = () => (
  <ScRadioGroup size="small" label="Select an option" name="a" value="1">
    <ScRadioButton value="1">Option 1</ScRadioButton>
    <ScRadioButton value="2">Option 2</ScRadioButton>
    <ScRadioButton value="3">Option 3</ScRadioButton>
  </ScRadioGroup>

  <br />

  <ScRadioGroup size="medium" label="Select an option" name="a" value="1">
    <ScRadioButton value="1">Option 1</ScRadioButton>
    <ScRadioButton value="2">Option 2</ScRadioButton>
    <ScRadioButton value="3">Option 3</ScRadioButton>
  </ScRadioGroup>

  <br />

  <ScRadioGroup size="large" label="Select an option" name="a" value="1">
    <ScRadioButton value="1">Option 1</ScRadioButton>
    <ScRadioButton value="2">Option 2</ScRadioButton>
    <ScRadioButton value="3">Option 3</ScRadioButton>
  </ScRadioGroup>
);

Pill Buttons

Use the pill attribute to give radio buttons rounded edges.

Option 1 Option 2 Option 3
Option 1 Option 2 Option 3
Option 1 Option 2 Option 3
<sc-radio-group size="small" label="Select an option" name="a" value="1">
  <sc-radio-button pill value="1">Option 1</sc-radio-button>
  <sc-radio-button pill value="2">Option 2</sc-radio-button>
  <sc-radio-button pill value="3">Option 3</sc-radio-button>
</sc-radio-group>

<br />

<sc-radio-group size="medium" label="Select an option" name="a" value="1">
  <sc-radio-button pill value="1">Option 1</sc-radio-button>
  <sc-radio-button pill value="2">Option 2</sc-radio-button>
  <sc-radio-button pill value="3">Option 3</sc-radio-button>
</sc-radio-group>

<br />

<sc-radio-group size="large" label="Select an option" name="a" value="1">
  <sc-radio-button pill value="1">Option 1</sc-radio-button>
  <sc-radio-button pill value="2">Option 2</sc-radio-button>
  <sc-radio-button pill value="3">Option 3</sc-radio-button>
</sc-radio-group>
import ScRadioButton from '@styledc-dev/styledc/dist/react/radio-button';
import ScRadioGroup from '@styledc-dev/styledc/dist/react/radio-group';

const App = () => (
  <ScRadioGroup size="small" label="Select an option" name="a" value="1">
    <ScRadioButton pill value="1">Option 1</ScRadioButton>
    <ScRadioButton pill value="2">Option 2</ScRadioButton>
    <ScRadioButton pill value="3">Option 3</ScRadioButton>
  </ScRadioGroup>

  <br />

  <ScRadioGroup size="medium" label="Select an option" name="a" value="1">
    <ScRadioButton pill value="1">Option 1</ScRadioButton>
    <ScRadioButton pill value="2">Option 2</ScRadioButton>
    <ScRadioButton pill value="3">Option 3</ScRadioButton>
  </ScRadioGroup>

  <br />

  <ScRadioGroup size="large" label="Select an option" name="a" value="1">
    <ScRadioButton pill value="1">Option 1</ScRadioButton>
    <ScRadioButton pill value="2">Option 2</ScRadioButton>
    <ScRadioButton pill value="3">Option 3</ScRadioButton>
  </ScRadioGroup>
);

Prefix and Suffix Icons

Use the prefix and suffix slots to add icons.

Option 1 Option 2 Option 3
<sc-radio-group label="Select an option" name="a" value="1">
  <sc-radio-button value="1">
    <sc-icon slot="prefix" name="archive"></sc-icon>
    Option 1
  </sc-radio-button>

  <sc-radio-button value="2">
    <sc-icon slot="suffix" name="bag"></sc-icon>
    Option 2
  </sc-radio-button>

  <sc-radio-button value="3">
    <sc-icon slot="prefix" name="gift"></sc-icon>
    <sc-icon slot="suffix" name="cart"></sc-icon>
    Option 3
  </sc-radio-button>
</sc-radio-group>
import ScIcon from '@styledc-dev/styledc/dist/react/icon';
import ScRadioButton from '@styledc-dev/styledc/dist/react/radio-button';
import ScRadioGroup from '@styledc-dev/styledc/dist/react/radio-group';

const App = () => (
  <ScRadioGroup label="Select an option" name="a" value="1">
    <ScRadioButton value="1">
      <ScIcon slot="prefix" name="archive" />
      Option 1
    </ScRadioButton>

    <ScRadioButton value="2">
      <ScIcon slot="suffix" name="bag" />
      Option 2
    </ScRadioButton>

    <ScRadioButton value="3">
      <ScIcon slot="prefix" name="gift" />
      <ScIcon slot="suffix" name="cart" />
      Option 3
    </ScRadioButton>
  </ScRadioGroup>
);

Buttons with Icons

You can omit button labels and use icons instead. Make sure to set a label attribute on each icon so screen readers will announce each option correctly.

<sc-radio-group label="Select an option" name="a" value="neutral">
  <sc-radio-button value="angry">
    <sc-icon name="emoji-angry" label="Angry"></sc-icon>
  </sc-radio-button>

  <sc-radio-button value="sad">
    <sc-icon name="emoji-frown" label="Sad"></sc-icon>
  </sc-radio-button>

  <sc-radio-button value="neutral">
    <sc-icon name="emoji-neutral" label="Neutral"></sc-icon>
  </sc-radio-button>

  <sc-radio-button value="happy">
    <sc-icon name="emoji-smile" label="Happy"></sc-icon>
  </sc-radio-button>

  <sc-radio-button value="laughing">
    <sc-icon name="emoji-laughing" label="Laughing"></sc-icon>
  </sc-radio-button>
</sc-radio-group>
import ScIcon from '@styledc-dev/styledc/dist/react/icon';
import ScRadioButton from '@styledc-dev/styledc/dist/react/radio-button';
import ScRadioGroup from '@styledc-dev/styledc/dist/react/radio-group';

const App = () => (
  <ScRadioGroup label="Select an option" name="a" value="neutral">
    <ScRadioButton value="angry">
      <ScIcon name="emoji-angry" label="Angry" />
    </ScRadioButton>

    <ScRadioButton value="sad">
      <ScIcon name="emoji-frown" label="Sad" />
    </ScRadioButton>

    <ScRadioButton value="neutral">
      <ScIcon name="emoji-neutral" label="Neutral" />
    </ScRadioButton>

    <ScRadioButton value="happy">
      <ScIcon name="emoji-smile" label="Happy" />
    </ScRadioButton>

    <ScRadioButton value="laughing">
      <ScIcon name="emoji-laughing" label="Laughing" />
    </ScRadioButton>
  </ScRadioGroup>
);

Importing

If you’re using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.

Script Import Bundler React

To import this component from the CDN using a script tag:

<script type="module" src="https://cdn.jsdelivr.net/npm/@styledc-dev/styledc@1.0.0/cdn/components/radio-button/radio-button.js"></script>

To import this component from the CDN using a JavaScript import:

import 'https://cdn.jsdelivr.net/npm/@styledc-dev/styledc@1.0.0/cdn/components/radio-button/radio-button.js';

To import this component using a bundler:

import '@styledc-dev/styledc/dist/components/radio-button/radio-button.js';

To import this component as a React component:

import ScRadioButton from '@styledc-dev/styledc/dist/react/radio-button';

Slots

Name Description
(default) The radio button’s label.
prefix A presentational prefix icon or similar element.
suffix A presentational suffix icon or similar element.

Learn more about using slots.

Properties

Name Description Reflects Type Default
value The radio’s value. When selected, the radio group will receive this value. string -
disabled Disables the radio button. boolean false
size The radio button’s size. When used inside a radio group, the size will be determined by the radio group’s size so this attribute can typically be omitted. 'small' | 'medium' | 'large' 'medium'
pill Draws a pill-style radio button with rounded edges. boolean false
updateComplete A read-only promise that resolves when the component has finished updating.

Learn more about attributes and properties.

Events

Name React Event Description Event Detail
sc-blur onScBlur Emitted when the button loses focus. -
sc-focus onScFocus Emitted when the button gains focus. -

Learn more about events.

Methods

Name Description Arguments
focus() Sets focus on the radio button. options: FocusOptions
blur() Removes focus from the radio button. -

Learn more about methods.

Parts

Name Description
base The component’s base wrapper.
button The internal <button> element.
button--checked The internal button element when the radio button is checked.
prefix The container that wraps the prefix.
label The container that wraps the radio button’s label.
suffix The container that wraps the suffix.

Learn more about customizing CSS parts.