- Light
- Dark
- Darkest
- Medium
- Large
- LTR
- RTL
- Default
- Express
Radio
Component status | Contribution |
---|---|
Current version | @spectrum-css/radio@9.2.3 |
Released | August 29, 2024 |
S2-foundations | @spectrum-css/radio@10.0.0-s2-foundations.12 |
Released | August 2, 2024 |
Usage notes
- Radio buttons allow users to select a single option from a list of mutually exclusive options. All possible options are exposed up front for users to compare.
- Radio buttons should not be used on their own, they should always be used within a FieldGroup.
- Invalid radio buttons are signified by including HelpText in a FieldGroup. Sample usage for an invalid radio state is included in the FieldGroup documentation.
Variants
SizingContribution
S
M (default)
L
XL
Show markup
<div class="spectrum-Examples">
<div class="spectrum-Examples-item">
<h4 class="spectrum-Heading spectrum-Heading--sizeXS spectrum-Examples-itemHeading">S</h4>
<form>
<div class="spectrum-Radio spectrum-Radio--sizeS">
<input type="radio" name="pets" class="spectrum-Radio-input" id="radio-0">
<span class="spectrum-Radio-button spectrum-Radio-button--sizeS"></span>
<label class="spectrum-Radio-label spectrum-Radio-label--sizeS" for="radio-0">Kittens</label>
</div>
<br>
<div class="spectrum-Radio spectrum-Radio--sizeS">
<input type="radio" name="pets" class="spectrum-Radio-input" id="radio-1" checked>
<span class="spectrum-Radio-button spectrum-Radio-button--sizeS"></span>
<label class="spectrum-Radio-label spectrum-Radio-label--sizeS" for="radio-1">Puppies</label>
</div>
</form>
</div>
<div class="spectrum-Examples-item">
<h4 class="spectrum-Heading spectrum-Heading--sizeXS spectrum-Examples-itemHeading">M (default)</h4>
<form>
<div class="spectrum-Radio spectrum-Radio--sizeM">
<input type="radio" name="pets" class="spectrum-Radio-input" id="radio-2">
<span class="spectrum-Radio-button spectrum-Radio-button--sizeM"></span>
<label class="spectrum-Radio-label spectrum-Radio-label--sizeM" for="radio-0">Kittens</label>
</div>
<br>
<div class="spectrum-Radio spectrum-Radio--sizeM">
<input type="radio" name="pets" class="spectrum-Radio-input" id="radio-3" checked>
<span class="spectrum-Radio-button spectrum-Radio-button--sizeM"></span>
<label class="spectrum-Radio-label spectrum-Radio-label--sizeM" for="radio-1">Puppies</label>
</div>
</form>
</div>
<div class="spectrum-Examples-item">
<h4 class="spectrum-Heading spectrum-Heading--sizeXS spectrum-Examples-itemHeading">L</h4>
<form>
<div class="spectrum-Radio spectrum-Radio--sizeL">
<input type="radio" name="pets" class="spectrum-Radio-input" id="radio-4">
<span class="spectrum-Radio-button spectrum-Radio-button--sizeL"></span>
<label class="spectrum-Radio-label spectrum-Radio-label--sizeL" for="radio-0">Kittens</label>
</div>
<br>
<div class="spectrum-Radio spectrum-Radio--sizeL">
<input type="radio" name="pets" class="spectrum-Radio-input" id="radio-5" checked>
<span class="spectrum-Radio-button spectrum-Radio-button--sizeL"></span>
<label class="spectrum-Radio-label spectrum-Radio-label--sizeL" for="radio-1">Puppies</label>
</div>
</form>
</div>
<div class="spectrum-Examples-item">
<h4 class="spectrum-Heading spectrum-Heading--sizeXS spectrum-Examples-itemHeading">XL</h4>
<form>
<div class="spectrum-Radio spectrum-Radio--sizeXL">
<input type="radio" name="pets" class="spectrum-Radio-input" id="radio-6">
<span class="spectrum-Radio-button spectrum-Radio-button--sizeXL"></span>
<label class="spectrum-Radio-label spectrum-Radio-label--sizeXL" for="radio-0">Kittens</label>
</div>
<br>
<div class="spectrum-Radio spectrum-Radio--sizeXL">
<input type="radio" name="pets" class="spectrum-Radio-input" id="radio-7" checked>
<span class="spectrum-Radio-button spectrum-Radio-button--sizeXL"></span>
<label class="spectrum-Radio-label spectrum-Radio-label--sizeXL" for="radio-1">Puppies</label>
</div>
</form>
</div>
</div>
StandardContribution
Default
Disabled
Read-only
Show markup
<div class="spectrum-Examples">
<div class="spectrum-Examples-item">
<h4 class="spectrum-Heading spectrum-Heading--sizeXS spectrum-Examples-itemHeading">Default</h4>
<form>
<div class="spectrum-Radio">
<input type="radio" name="pets" class="spectrum-Radio-input" id="radio-8">
<span class="spectrum-Radio-button"></span>
<label class="spectrum-Radio-label" for="radio-0">Kittens</label>
</div>
<br>
<div class="spectrum-Radio">
<input type="radio" name="pets" class="spectrum-Radio-input" id="radio-9" checked>
<span class="spectrum-Radio-button"></span>
<label class="spectrum-Radio-label" for="radio-1">Puppies</label>
</div>
</form>
</div>
<div class="spectrum-Examples-item">
<h4 class="spectrum-Heading spectrum-Heading--sizeXS spectrum-Examples-itemHeading">Disabled</h4>
<form>
<div class="spectrum-Radio">
<input type="radio" name="pets" class="spectrum-Radio-input" id="radio-12-disabled" disabled>
<span class="spectrum-Radio-button"></span>
<label class="spectrum-Radio-label" for="radio-0">Kittens</label>
</div>
<br>
<div class="spectrum-Radio">
<input type="radio" name="pets" class="spectrum-Radio-input" id="radio-13-disabled" checked disabled>
<span class="spectrum-Radio-button"></span>
<label class="spectrum-Radio-label" for="radio-1">Puppies</label>
</div>
</form>
</div>
<div class="spectrum-Examples-item">
<h4 class="spectrum-Heading spectrum-Heading--sizeXS spectrum-Examples-itemHeading">Read-only</h4>
<form>
<div class="spectrum-Radio is-readOnly">
<input type="radio" name="pets" class="spectrum-Radio-input" id="radio-14" readonly="readonly" disabled>
<span class="spectrum-Radio-button"></span>
<label class="spectrum-Radio-label" for="radio-0">Kittens</label>
</div>
<br>
<div class="spectrum-Radio is-readOnly">
<input type="radio" name="pets" class="spectrum-Radio-input" id="radio-15" checked readonly="readonly" disabled>
<span class="spectrum-Radio-button"></span>
<label class="spectrum-Radio-label" for="radio-1">Puppies</label>
</div>
</form>
</div>
</div>
EmphasizedContribution
Default
Disabled
Read-only
Show markup
<div class="spectrum-Examples">
<div class="spectrum-Examples-item">
<h4 class="spectrum-Heading spectrum-Heading--sizeXS spectrum-Examples-itemHeading">Default</h4>
<form>
<div class="spectrum-Radio spectrum-Radio--sizeM spectrum-Radio--emphasized">
<input type="radio" name="pets" class="spectrum-Radio-input" id="radio-16">
<span class="spectrum-Radio-button"></span>
<label class="spectrum-Radio-label" for="radio-0">Kittens</label>
</div>
<br>
<div class="spectrum-Radio spectrum-Radio--sizeM spectrum-Radio--emphasized">
<input type="radio" name="pets" class="spectrum-Radio-input" id="radio-17" checked>
<span class="spectrum-Radio-button"></span>
<label class="spectrum-Radio-label" for="radio-1">Puppies</label>
</div>
</form>
</div>
<div class="spectrum-Examples-item">
<h4 class="spectrum-Heading spectrum-Heading--sizeXS spectrum-Examples-itemHeading">Disabled</h4>
<form>
<div class="spectrum-Radio spectrum-Radio--sizeM spectrum-Radio--emphasized">
<input type="radio" name="pets" class="spectrum-Radio-input" id="radio-20-disabled" disabled>
<span class="spectrum-Radio-button"></span>
<label class="spectrum-Radio-label" for="radio-0">Kittens</label>
</div>
<br>
<div class="spectrum-Radio spectrum-Radio--sizeM spectrum-Radio--emphasized">
<input type="radio" name="pets" class="spectrum-Radio-input" id="radio-21-disabled" checked disabled>
<span class="spectrum-Radio-button"></span>
<label class="spectrum-Radio-label" for="radio-1">Puppies</label>
</div>
</form>
</div>
<div class="spectrum-Examples-item">
<h4 class="spectrum-Heading spectrum-Heading--sizeXS spectrum-Examples-itemHeading">Read-only</h4>
<form>
<div class="spectrum-Radio spectrum-Radio--sizeM spectrum-Radio--emphasized is-readOnly">
<input type="radio" name="pets" class="spectrum-Radio-input" id="radio-22" readonly="readonly" disabled>
<span class="spectrum-Radio-button"></span>
<label class="spectrum-Radio-label" for="radio-0">Kittens</label>
</div>
<br>
<div class="spectrum-Radio spectrum-Radio--sizeM is-readOnly">
<input type="radio" name="pets" class="spectrum-Radio-input" id="radio-23" checked readonly="readonly" disabled>
<span class="spectrum-Radio-button"></span>
<label class="spectrum-Radio-label" for="radio-1">Puppies</label>
</div>
</form>
</div>
</div>
Wrapping behaviorContribution
Show markup
<div class="spectrum-Radio">
<input type="radio" name="longname" class="spectrum-Radio-input" id="radio-24">
<span class="spectrum-Radio-button"></span>
<label class="spectrum-Radio-label" for="radio-3">Radio with an extraordinarily long label please don't do this but if you did it should wrap text when it gets longer than the container which contains the radio which has an unacceptably long label</label>
</div>
Custom Properties API
This component can be modified via its --mod-*
prefixed custom properties. A list of those prefixed custom properties can be found here.
Migration Guide
T-shirt sizing
Radio Button now supports t-shirt sizing and requires that you specify the size by adding a .spectrum-RadioButton--size*
class. Default styling is medium.
Read-only
Radio Button now includes a read-only state in addition to the disabled state.
- Read-only radio buttons are disabled, but not all disabled radio buttons are read-only.
- Read-only radio buttons do not have a focus ring, but the button should be focusable.]
Invalid/Error State
- Invalid radio buttons are signified by including Help text in a Field group. The
.is-invalid
class has been removed. See Field group for an example with an invalid radio group.
Remove focus-ring class
We’ve migrated away from the focus-ring class in favor of the native :focus-visible
pseudo-class due to changes in browser support.