2.24.0
Radio buttons afford a single selection from two or more options.
See Forms for guidance on composing full forms.
Use to afford a single selection from two or more options.
<!-- Unselected -->
<label class="mds-form__radio-button" for="peer-group--26509">
<input id="peer-group--26509" name="html-radio-example-default-un" value="peer-group" type="radio" class="mds-form__radio-button-input" />
<span class="mds-form__radio-button-visible-wrap">
<span class="mds-form__radio-button-visual"></span>
<span class="mds-form__radio-button-text ">
Peer Group
</span>
</span>
</label>
<!-- Unselected, Disabled -->
<label class="mds-form__radio-button mds-form__radio-button--disabled" for="peer-group--2285">
<input id="peer-group--2285" name="html-radio-example-disabled-un" value="peer-group" type="radio" class="mds-form__radio-button-input" disabled />
<span class="mds-form__radio-button-visible-wrap">
<span class="mds-form__radio-button-visual"></span>
<span class="mds-form__radio-button-text ">
Peer Group
</span>
</span>
</label>
<!-- Selected -->
<label class="mds-form__radio-button" for="peer-group--48064">
<input id="peer-group--48064" name="html-radio-example-default" value="peer-group" type="radio" class="mds-form__radio-button-input" checked />
<span class="mds-form__radio-button-visible-wrap">
<span class="mds-form__radio-button-visual"></span>
<span class="mds-form__radio-button-text ">
Peer Group
</span>
</span>
</label>
<!-- Selected, Disabled -->
<label class="mds-form__radio-button mds-form__radio-button--disabled" for="peer-group--53185">
<input id="peer-group--53185" name="html-radio-example-disabled" value="peer-group" type="radio" class="mds-form__radio-button-input" checked disabled />
<span class="mds-form__radio-button-visible-wrap">
<span class="mds-form__radio-button-visual"></span>
<span class="mds-form__radio-button-text ">
Peer Group
</span>
</span>
</label>
<!-- Unselected -->
<mds-radio-button name="mdswc-radio-example-default-un" value="peer-group">Peer Group</mds-radio-button>
<!-- Unselected, Disabled -->
<mds-radio-button name="mdswc-radio-example-disabled-un" value="peer-group" disabled>Peer Group</mds-radio-button>
<!-- Selected -->
<mds-radio-button name="mdswc-radio-example-default" value="peer-group" checked>Peer Group</mds-radio-button>
<!-- Selected, Disabled -->
<mds-radio-button name="mdswc-radio-example-disabled" value="peer-group" disabled checked>Peer Group</mds-radio-button>
<form class="mds-form mds-form--medium-layout" method="post" action="form/processor">
<div class="mds-form__field-group">
<fieldset class="mds-form__radio-button-group" role="radiogroup">
<legend class="mds-form__radio-button-group-label">
Rank Within
</legend>
<label class="mds-form__radio-button" for="id-33355-checked">
<input id="id-33355-checked" name="id-33355" value="your-list" type="radio" class="mds-form__radio-button-input" checked />
<span class="mds-form__radio-button-visible-wrap">
<span class="mds-form__radio-button-visual"></span>
<span class="mds-form__radio-button-text ">
Your List
</span>
</span>
</label>
<label class="mds-form__radio-button" for="id-33355">
<input id="id-33355" name="id-33355" value="peer-group" type="radio" class="mds-form__radio-button-input" />
<span class="mds-form__radio-button-visible-wrap">
<span class="mds-form__radio-button-visual"></span>
<span class="mds-form__radio-button-text ">
Peer Group
</span>
</span>
</label>
</fieldset>
</div>
</form>
<form class="mds-form mds-form--medium-layout" method="post" action="form/processor">
<mds-field-group>
<mds-radio-button-group label="Rank Within">
<mds-radio-button checked name="stacked-mdswc" value="your-list">Your List</mds-radio-button>
<mds-radio-button name="stacked-mdswc" value="peer-group">Peer Group</mds-radio-button>
</mds-radio-button-group>
</mds-field-group>
</form>
<form class="mds-form mds-form--medium-layout" method="post" action="form/processor">
<div class="mds-form__field-group mds-form__field-group--horizontal">
<fieldset class="mds-form__radio-button-group" role="radiogroup">
<legend class="mds-form__radio-button-group-label">
Rank Within
</legend>
<label class="mds-form__radio-button" for="id-50422-checked">
<input id="id-50422-checked" name="id-50422" value="your-list" type="radio" class="mds-form__radio-button-input" checked />
<span class="mds-form__radio-button-visible-wrap">
<span class="mds-form__radio-button-visual"></span>
<span class="mds-form__radio-button-text ">
Your List
</span>
</span>
</label>
<label class="mds-form__radio-button" for="id-50422">
<input id="id-50422" name="id-50422" value="peer-group" type="radio" class="mds-form__radio-button-input" />
<span class="mds-form__radio-button-visible-wrap">
<span class="mds-form__radio-button-visual"></span>
<span class="mds-form__radio-button-text ">
Peer Group
</span>
</span>
</label>
</fieldset>
</div>
</form>
<form class="mds-form mds-form--medium-layout" method="post" action="form/processor">
<mds-field-group horizontal>
<mds-radio-button-group label="Rank Within">
<mds-radio-button checked name="horizontal-mdswc" value="your-list">Your List</mds-radio-button>
<mds-radio-button name="horizontal-mdswc" value="peer-group">Peer Group</mds-radio-button>
</mds-radio-button-group>
</mds-field-group>
</form>
Sizing affects radio button size and text size. The default size is medium, and you can use modifier classes or props to make the radio button smaller or larger.
<label class="mds-form__radio-button mds-form__radio-button--small" for="radio-button-label--17423">
<input id="radio-button-label--17423" name="small-radio-button" value="small" type="radio" class="mds-form__radio-button-input" />
<span class="mds-form__radio-button-visible-wrap">
<span class="mds-form__radio-button-visual"></span>
<span class="mds-form__radio-button-text ">
Radio Button Label
</span>
</span>
</label>
<mds-radio-button size="small" name="small-radio-button-wc" value="small">Radio Button Label</mds-radio-button>
:hover
and :active
styles as the primary Button.name
attribute to each radio button within a group to ensures that a single selection is achieved.
Class
|
Applies to
|
Outcome
|
---|---|---|
|
|
Adjusts styling to render a small radio button. |
|
|
Adjusts styling to render a large radio button. |
|
|
Adjusts styling to render a touch radio button. |
|
|
Adjusts styling to render a small radio button group label. |
|
|
Adjusts styling to render a large radio button group label. |
|
|
Adjusts styling to render a touch radio button group label. |
Use this mixin to create media queries in your product styles to switch radio buttons to their touch variation.
@include mds-radio-button-touch-properties();
For example, switching to the touch variation on screens with a max-width
of 500px
:
// Your product SCSS
@media screen and (max-width: 500px) {
@include mds-radio-button-touch-properties();
}
max-width
, pointer: coarse
is another helpful method for targeting touch screen devices.@include mds-form-all-touch-properties();
mixin for efficiency.Radio buttons are comprised of two separate web components, each with a dedicated API:
<mds-radio-button>
elements to present them as a group.When setting props as attributes on a custom HTML element, use kebab-case
instead of camelCase
.
Prop
|
Type
|
Validation
|
Default
|
Description
|
---|---|---|---|---|
|
String |
— |
— |
A space-separated list of class names that will be appended to the default |
|
Boolean |
— |
|
Sets the checked value of the radio button. |
|
Boolean |
— |
|
If |
|
String |
Required |
— |
Sets the |
|
String |
One of: |
|
Alters the size of the radio button. |
|
String |
Required |
— |
The label text for the radio button. Can also be passed via the default slot. |
|
String |
— |
— |
Sets the |
Pass text in between the <mds-radio-button></mds-radio-button>
tags to set the radio button’s label text. This can be overridden with the text prop.
Setting size
, checked
, name
and value
via props. Using the default slot for text
content:
<mds-radio-button size="small" name="radio-example" value="yes" checked> Yes </mds-radio-button>
<mds-radio-button size="small" name="radio-example" value="no"> No </mds-radio-button>
When setting props as attributes on a custom HTML element, use kebab-case
instead of camelCase
.
Prop
|
Type
|
Validation
|
Default
|
Description
|
---|---|---|---|---|
|
String |
— |
— |
A space-separated list of class names that will be appended to the default |
|
String |
— |
— |
A space-separated list of element |
|
String |
— |
Please select an option. |
Sets the radio button group label’s required indicator |
|
String |
Required |
— |
Label for the radio button group. |
|
Boolean |
— |
|
If |
|
String |
— |
(Optional) |
Use to override the default optional indicator text. |
|
Boolean |
— |
|
If |
|
String |
One of: |
|
Alters the size of the radio button group label. |
Pass two or more <mds-radio-button>
elements between the <mds-radio-button-group></mds-radio-button-group>
tags to set the content of the radio button group.
Setting required
and label
via props. Using the default slot for the radio buttons in the group:
<mds-radio-button-group required label="Choose an option.">
<mds-radio-button name="radio-group-example" value="yes"> Yes </mds-radio-button>
<mds-radio-button name="radio-group-example" value="no"> No </mds-radio-button>
</mds-radio-button-group>
On touch screens, :hover
states “stick” after tapping an interactive element. To counter this behavior, MDS provides a mixin that resets component hover states to their default styles:
@include mds-sticky-hover-reset();
The mixin uses a media query based on hover: none
to target touch screen devices and includes resets for Buttons, Checkboxes, Inputs, List Groups, Radio Buttons, Search Fields, Selects, Switches, and Textareas. You can apply this mixin within your product’s media queries along with other MDS touch styles, for example:
// Your product SCSS
@media screen and (max-width: 500px) {
@include mds-sticky-hover-reset();
@include mds-componentName-touch-properties();
// The rest of your product’s responsive/touch styles...
}
fieldset
and legend
for radio button groups. See the form structure guidelines in the Forms composition section for more information.