OTTODesign System

ComponentsForm

Radio button

The radio button allows users to select exactly one option from a set of options.

Configurator

LiveRadio button: size, width, label position, texts and state
HTML
<oc-radio-button-v2><input type="radio" name="rb-cfg" aria-label="oc-auto"><label slot="label">Expressversand</label></oc-radio-button-v2>

Usage

Anatomy

1 2
  1. Radio button
  2. Label
LiveAnatomy
HTML
<div class="anatomy" style="display:block;width:max-content;margin:28px auto">
<oc-radio-button-v2 width-behavior="fit"><input type="radio" name="rb-an" aria-label="oc-auto"><label slot="label">Label</label></oc-radio-button-v2>
<span class="anatomy-pin" style="left:-16px;top:50%">1</span>
<span class="anatomy-pin" style="left:calc(100% + 16px);top:50%">2</span>
<ol class="anatomy-key"><li data-n="1">Radio button</li><li data-n="2">Label</li></ol>

Variants

There are two variants of the Radio Button. Both come in size50 and size100.

  • Default
  • Error: The error variant is not only visualized by the error color but also by an error icon, which is due to accessibility.

Default, size 100

Error, size 100

Bitte wähle eine Versandart aus.

Default, size 50

Error, size 50

Bitte wähle eine Versandart aus.
LiveDefault and error in size 100 and 50
HTML
<p class="demo-label">Default, size 100</p>
<oc-radio-button-v2 width-behavior="fit"><input type="radio" name="rb-var-1" aria-label="oc-auto"><label slot="label">Standardversand</label></oc-radio-button-v2>
<p class="demo-label">Error, size 100</p>
<oc-radio-button-v2 width-behavior="fit"><input type="radio" name="rb-var-2" aria-label="oc-auto"><label slot="label">Expressversand</label><span slot="error">Bitte wähle eine Versandart aus.</span></oc-radio-button-v2>
<p class="demo-label">Default, size 50</p>
<oc-radio-button-v2 size="50" width-behavior="fit"><input type="radio" name="rb-var-3" aria-label="oc-auto"><label slot="label">Standardversand</label></oc-radio-button-v2>
<p class="demo-label">Error, size 50</p>
<oc-radio-button-v2 size="50" width-behavior="fit"><input type="radio" name="rb-var-4" aria-label="oc-auto"><label slot="label">Expressversand</label><span slot="error">Bitte wähle eine Versandart aus.</span></oc-radio-button-v2>

Behavior

States

Enabled (hover, press, focus it)

Error

Disabled

LiveStates
HTML
<p class="demo-label">Enabled (hover, press, focus it)</p>
<oc-radio-button-v2><input type="radio" name="rb-st-a" aria-label="oc-auto"><label slot="label">Label</label></oc-radio-button-v2>
<oc-radio-button-v2><input type="radio" name="rb-st-b" checked aria-label="oc-auto"><label slot="label">Label</label></oc-radio-button-v2>
<p class="demo-label">Error</p>
<oc-radio-button-v2><input type="radio" name="rb-st-c" aria-label="oc-auto"><label slot="label">Label</label><span slot="error"></span></oc-radio-button-v2>
<oc-radio-button-v2><input type="radio" name="rb-st-d" checked aria-label="oc-auto"><label slot="label">Label</label><span slot="error"></span></oc-radio-button-v2>
<p class="demo-label">Disabled</p>
<oc-radio-button-v2><input type="radio" name="rb-st-e" disabled aria-label="oc-auto"><label slot="label">Label</label></oc-radio-button-v2>
<oc-radio-button-v2><input type="radio" name="rb-st-f" checked disabled aria-label="oc-auto"><label slot="label">Label</label></oc-radio-button-v2>

Interaction

Users can check a radio button by tapping anywhere on it. The label is also part of the hitbox and ensures proper support in assistive technologies, improving usability and accessibility. Checking a radio button automatically unchecks other radio buttons in same group. There is also a disabled variant of the radio button that cannot be clicked or tapped.

Fitting

The radio button is 1.5rem high and 1.5rem wide. The label is set to fit-content by default, but it can be overwritten to fill-parent. Note, that the whole line is interactive in this case.

fit

fill (default)

Long label wraps

LiveFitting
HTML
<p class="demo-label">fit</p>
<oc-radio-button-v2 width-behavior="fit"><input type="radio" name="rb-fit-a" aria-label="oc-auto"><label slot="label">Label</label></oc-radio-button-v2>
<p class="demo-label">fill (default)</p>
<oc-radio-button-v2><input type="radio" name="rb-fit-b" aria-label="oc-auto"><label slot="label">Label</label></oc-radio-button-v2>
<p class="demo-label">Long label wraps</p>
<oc-radio-button-v2><input type="radio" name="rb-fit-c" aria-label="oc-auto"><label slot="label">Lieferung an eine abweichende Lieferadresse</label></oc-radio-button-v2>

Placement

The radio button has a mandatory label which can be placed left or right with a small gap to the radio button. Ideally, there should be a 24px gap between radio buttons if they are placed vertically.

Label right (default)

Label left

LiveLabel placement
HTML
<p class="demo-label">Label right (default)</p>
<oc-radio-button-v2 width-behavior="fit"><input type="radio" name="rb-pl-a" aria-label="oc-auto"><label slot="label">Label</label></oc-radio-button-v2>
<p class="demo-label">Label left</p>
<oc-radio-button-v2 width-behavior="fit" label-placement="left"><input type="radio" name="rb-pl-b" aria-label="oc-auto"><label slot="label">Label</label></oc-radio-button-v2>

Vertical list, 24px gap

LivePlacement
HTML
<p class="demo-label">Vertical list, 24px gap</p>
<oc-form-group-v1 orientation="vertical" gap="var(--oc-base-dimension-24)" oc-aria-label="Versandart">
<oc-radio-button-v2><input type="radio" name="rb-place" aria-label="oc-auto"><label slot="label">Label</label></oc-radio-button-v2>
<oc-radio-button-v2><input type="radio" name="rb-place" aria-label="oc-auto"><label slot="label">Label</label></oc-radio-button-v2>
<oc-radio-button-v2><input type="radio" name="rb-place" aria-label="oc-auto"><label slot="label">Label</label></oc-radio-button-v2>
</oc-form-group-v1>

Radio button vs. checkbox

Use radio buttons when only one option can be selected from a list (single selection). When multiple option can be selected you should use checkboxes (multiple selection).

Checkbox: several choices

Radio button: one choice

LiveSingle selection and multiple selection
HTML
<p class="demo-label">Checkbox: several choices</p>
<oc-checkbox-v2><input type="checkbox" checked aria-label="oc-auto"><label slot="label">Damen</label></oc-checkbox-v2>
<oc-checkbox-v2><input type="checkbox" checked aria-label="oc-auto"><label slot="label">Herren</label></oc-checkbox-v2>
<oc-checkbox-v2><input type="checkbox" aria-label="oc-auto"><label slot="label">Kinder</label></oc-checkbox-v2>
<p class="demo-label">Radio button: one choice</p>
<oc-radio-button-v2><input type="radio" name="rb-vs-cb" aria-label="oc-auto"><label slot="label">Standardversand</label></oc-radio-button-v2>
<oc-radio-button-v2><input type="radio" name="rb-vs-cb" checked aria-label="oc-auto"><label slot="label">Expressversand</label></oc-radio-button-v2>
<oc-radio-button-v2><input type="radio" name="rb-vs-cb" aria-label="oc-auto"><label slot="label">Abholung</label></oc-radio-button-v2>

Best Practices

CautionAvoid using horizontal Radio Button lists
Don'tNest Radio Buttons

Fünf oder weniger Optionen:

DoUse Radio Buttons when there are five or fewer options.

Mehr als fünf Optionen:

CautionIf there a more than 5 options consider using a drop-down menu instead of radio buttons.
DoUse the actual label of the radio button.

This is the only way to ensure consistent behavior and layout.

LiveDo
HTML
<oc-radio-button-v2 width-behavior="fit"><input type="radio" name="rb-click" aria-label="oc-auto"><label slot="label">Auch der Text ist klickbar</label></oc-radio-button-v2>
Expressversand
Don'tUse text as a label. The spacing may be off, and proper user interaction (i.e., a hitbox spanning the entire element and interactive states) cannot be ensured.

Content Guidelines

DoUse short, precise labels to describe the options.
Don'tUse overly descriptive labels to describe the options.

Accessibility

Implementation

Live demo

Schritt 2 von 3

Wie möchtest du deine Lieferung?

Lieferung Do., 02.10. bis Sa., 04.10. Bestellst du bis 12 Uhr, kommt dein Paket morgen. Du wählst den Tag, wir liefern.

Gesamtsumme

249,98 €

Weiter zur Zahlung
LiveReal OTTO components, rendered by the OTTO component runtime
HTML
<div style="max-width:480px;margin:0 auto;display:grid;gap:24px">
<div style="display:grid;gap:4px">
  <p class="oc-copy-75 oc-text-color-secondary">Schritt 2 von 3</p>
  <p class="oc-headline-100">Wie möchtest du deine Lieferung?</p>
<oc-form-group-v1 orientation="vertical" gap="var(--oc-base-dimension-24)" oc-aria-label="Versandart">
  <oc-radio-button-v2><input type="radio" name="rb-demo" checked aria-label="oc-auto"><label slot="label">Standardversand · kostenlos</label><span slot="hint">Lieferung Do., 02.10. bis Sa., 04.10.</span></oc-radio-button-v2>
  <oc-radio-button-v2><input type="radio" name="rb-demo" aria-label="oc-auto"><label slot="label">Expressversand · 9,95 €</label><span slot="hint">Bestellst du bis 12 Uhr, kommt dein Paket morgen.</span></oc-radio-button-v2>
  <oc-radio-button-v2><input type="radio" name="rb-demo" aria-label="oc-auto"><label slot="label">Wunschtermin · 4,95 €</label><span slot="hint">Du wählst den Tag, wir liefern.</span></oc-radio-button-v2>
</oc-form-group-v1>
<oc-divider-v1></oc-divider-v1>
  <p class="oc-copy-100"><b>Gesamtsumme</b></p>
  <p class="oc-copy-100"><b>249,98 €</b></p>
<oc-button-v1 variant="primary">Weiter zur Zahlung</oc-button-v1>

Code

Version Tag Status API
v2 <oc-radio-button-v2> Stable RadioButtonV2
v1 <oc-radio-button-v1> Deprecated RadioButtonV1

API

API: <oc-radio-button-v2> (RadioButtonV2)

The Radio Button component allows users to select exactly one option from a set. Provides attributes for state, styling, accessibility, and slots for the label, input element, hints, and errors.

Attributes / properties
Attribute Type Default Required Description
size "50" | "100" "100" no The size of the radio button.
width-behavior "fill" | "fit" "fill" no Defines the width behavior of the radio button component. - "fill": The component expands to fill the available width. - "fit": The component width fits its content.
label-placement "left" | "right" "right" no The placement direction of the label provided via the default slot relative to the radio button indicator.
Slots
Slot Required Description
default yes Requires the following interactive element: - <input type="radio"> for single-selection

For more information on interactive components, refer to the interactive component slots documentation.
label no The text content of the radio button label. Provides a brief description of the option represented by the radio button.
hint no A hint text displayed below the radio button. Provides additional information to help users understand the option.
error no An error message displayed below the radio button. Informs users about validation errors or requirements.
Events
Event Detail type Description
oc-property-change OcRadioButtonV2Events["oc-property-change"] Whenever a property value changes, this event triggers. Use this event to track all property changes within the component.

Refer to the Events documentation for more information.
oc-mount { component: string; } Fired when the component is mounted to the DOM. The event is fired when the onMount hook of the component is called by the runtime.
oc-unmount { component: string; } Fired when the component is unmounted from the DOM. The event is fired when the function returned by the onMount hook of the component is called by the runtime.

Examples

Listed below are the most common variations of the radio button component as well as specific component variations for different use cases.

Default

The standard configuration with the label placed on the right side.

HTML
<oc-radio-button-v2>
<label slot="label">my label</label>
<input type="radio" aria-label="oc-auto"/>
</oc-radio-button-v2>
Label placement: left

The standard configuration with the label placed on the left side.

HTML
<oc-radio-button-v2 label-placement="left">
<label slot="label">my label</label>
<input type="radio" aria-label="oc-auto"/>
</oc-radio-button-v2>
Error

Displays an error state with an error message.

`
This is an error message.
HTML
<oc-radio-button-v2>
<label slot="label">my label</label>
<span slot='error'>This is an error message.</span>
<input type="radio" aria-label="oc-auto" />
</oc-radio-button-v2>
Disabled

The disabled state prevents user interaction.

HTML
<oc-radio-button-v2>
<label slot="label">my label</label>
<input type="radio" aria-label="oc-auto" disabled />
</oc-radio-button-v2>
Size 50

A size 50 variant of the radio button.

HTML
<oc-radio-button-v2 size="50">
<label slot="label">my label</label>
<input type="radio" aria-label="oc-auto" />
</oc-radio-button-v2>
Demo: required

The demo showcases a required radiogroup with multiple radio button options.

HTML
<fieldset
role="radiogroup"
aria-required="true"
aria-label="radio options demo"
style="display: flex; flex-direction: column"
aria-invalid="true"
aria-description="Please select an option"
class="oc-gap-100"
>
<oc-radio-button-v2>
  <input type="radio" name="demo-required" value="option1" aria-label="oc-auto" />
  <label slot="label">Option 1</label>
</oc-radio-button-v2>
<oc-radio-button-v2>
  <input type="radio" name="demo-required" value="option2" aria-label="oc-auto" />
  <label slot="label">Option 2</label>
</oc-radio-button-v2>
<oc-radio-button-v2>
  <input type="radio" name="demo-required" value="option3" aria-label="oc-auto" />
  <label slot="label">Option 3</label>
</oc-radio-button-v2>
</fieldset>
Older versions

Migration to v2

Migration from radio button v1 to v2

The oc-radio-button component has been updated from oc-radio-button-v1 to oc-radio-button-v2. This migration guide provides step-by-step instructions to update your project to the latest version.

Skip to:

What's new
Native input element

The component now uses a native <input type="radio"> element, providing:

  • Better form integration and native form submission
  • Native validation support
  • Improved accessibility with screen readers
  • Support for standard input attributes like autofocus, form, formnovalidate
Events

All native radio button events are now available:

  • click
  • input
  • change
  • focus
  • blur
Flexible label content

The label slot allows for more flexible label content, including HTML elements:

HTML
<oc-radio-button-v2>
<input type="radio" name="option" value="damen" aria-label="oc-auto" />
<label slot="label"> Damen <span class="oc-text-color-secondary">374637</span> </label>
</oc-radio-button-v2>
Required radio groups

For required radio groups, use the aria-required attribute on the parent <fieldset> element:

HTML
<fieldset
role="radiogroup"
aria-required="true"
aria-label="Select an option"
aria-invalid="true"
aria-description="Please select an option"
>
<oc-radio-button-v2>
  <input type="radio" name="required-group" value="1" aria-label="oc-auto" />
  <label slot="label">Option 1</label>
</oc-radio-button-v2>
<oc-radio-button-v2>
  <input type="radio" name="required-group" value="2" aria-label="oc-auto" />
  <label slot="label">Option 2</label>
</oc-radio-button-v2>
</fieldset>
Design

No changes were applied to the design of the component.

API changes
Changed attributes
v1 Attribute v2 Attribute Notes
fit-content width-behavior="fit" Default is "fill"
label-placement label-placement No change
Changed slots
v1 Slot v2 Slot Notes
default (label text) label Label text now uses the label slot
— default Now contains the native <input type="radio"> element
— hint New slot for hint text
— error New slot for validation message
Removed attributes

The following attributes have been removed and should now be set on the native <input> element:

v1 Attribute v2 Equivalent Notes
checked Set checked on the <input> element Moved to native input
disabled Set disabled on the <input> element Moved to native input
name Set name on the <input> element Moved to native input
value Set value on the <input> element Moved to native input
oc-aria-label Set aria-label on the <input> element Renamed to standard attribute
oc-aria-required Set aria-required on the parent <fieldset> element Moved to parent fieldset
variant The error state is now automatically applied when the error slot has content Auto-applied based on slot
How to migrate

The main change is that v2 uses a native <input type="radio"> element in the default slot instead of managing the radio button state internally. This provides better accessibility, form integration, and native event support.

Migrate a basic radio button
<!-- From: -->
<oc-radio-button-v1 name="size" value="M" checked>Medium</oc-radio-button-v1>
<!-- To: -->
<oc-radio-button-v2>
  <input type="radio" name="size" value="M" checked aria-label="oc-auto" />
  <label slot="label">Medium</label>
</oc-radio-button-v2>
Migrate a radio button group
<!-- From: -->
<fieldset>
  <legend>Size</legend>
  <oc-radio-button-v1 name="size" value="S">Small</oc-radio-button-v1>
  <oc-radio-button-v1 name="size" value="M">Medium</oc-radio-button-v1>
  <oc-radio-button-v1 name="size" value="L">Large</oc-radio-button-v1>
</fieldset>
<!-- To: -->
<fieldset role="radiogroup" aria-label="Size">
  <oc-radio-button-v2>
    <input type="radio" name="size" value="S" aria-label="oc-auto" />
    <label slot="label">Small</label>
  </oc-radio-button-v2>
  <oc-radio-button-v2>
    <input type="radio" name="size" value="M" aria-label="oc-auto" />
    <label slot="label">Medium</label>
  </oc-radio-button-v2>
  <oc-radio-button-v2>
    <input type="radio" name="size" value="L" aria-label="oc-auto" />
    <label slot="label">Large</label>
  </oc-radio-button-v2>
</fieldset>
Migrate a radio button with hint and validation message
<!-- From: -->
<oc-radio-button-v1 name="option" value="1" variant="error"> Option 1 </oc-radio-button-v1>
<!-- To: -->
<oc-radio-button-v2>
  <input type="radio" name="option" value="1" aria-label="oc-auto" />
  <label slot="label">Option 1</label>
  <span slot="hint">Additional hint text</span>
  <span slot="error">Please select an option</span>
</oc-radio-button-v2>
Migrate a radio button with a disabled state
<!-- From: -->
<oc-radio-button-v1 disabled>Disabled option</oc-radio-button-v1>
<!-- To: -->
<oc-radio-button-v2>
  <input type="radio" disabled aria-label="oc-auto" />
  <label slot="label">Disabled option</label>
</oc-radio-button-v2>
Migrate a radio button with width behavior
<!-- From: -->
<oc-radio-button-v1 fit-content>Fit content</oc-radio-button-v1>
<!-- To: -->
<oc-radio-button-v2 width-behavior="fit">
  <input type="radio" aria-label="oc-auto" />
  <label slot="label">Fit content</label>
</oc-radio-button-v2>

API v1

API: <oc-radio-button-v1> (RadioButtonV1)

The Radio Button component allows users to select exactly one option from a set, with attributes for state, styling, accessibility, and a slot for setting the label text of the Radio Button .

Attributes / properties
Attribute Type Default Required Description
variant "default" | "error" "default" no Sets the main styling and behavior of the radio button.
value string "on" no Sets the initial value of the radio button to the provided value for form processing.
checked boolean false no Toggles the state of the radio button between checked and unchecked. When set to true, the radio button is initially checked.

Accessible in CSS via the custom-state mixin.
disabled boolean false no Disables the radio button, preventing user interaction and input.
fit-content boolean undefined no Sets the with behavior of the radio button. When set to true, the radio button will take the width of its content.
label-placement "left" | "right" "right" no Sets the placement direction of the label provided via the default slot relative to the radio button.
name string undefined no Sets the name tag to identify the radio button when submitting a form.
oc-aria-label string undefined no Sets the ARIA label of the radio button.
oc-aria-required boolean no Sets the ARIA required attribute of the radio button.
Slots
Slot Required Description
default yes Sets the text content of the radio button label to provide a brief description of the input field.
Events
Event Detail type Description
oc-property-change OcRadioButtonV1Events["oc-property-change"] Whenever a property value changes, this event triggers. Use this event to track all property changes within the component.

Refer to the Events documentation for more information.
oc-mount { component: string; } Fired when the component is mounted to the DOM. The event is fired when the onMount hook of the component is called by the runtime.
oc-unmount { component: string; } Fired when the component is unmounted from the DOM. The event is fired when the function returned by the onMount hook of the component is called by the runtime.