OTTODesign System

Components

Switch

The switch provides a toggle functionality for the users.

Configurator

LiveSwitch: size, width, label placement and state
HTML
<oc-switch-v3><input type="checkbox" aria-label="oc-auto"><label slot="label">Push-Benachrichtigungen</label></oc-switch-v3>

Usage

Anatomy

1 2 3 4
  1. Track (grey off, green on)
  2. Handle
  3. Check icon when checked
  4. Label
LiveAnatomy
HTML
<div class="anatomy">
  <oc-switch-v3><input type="checkbox" aria-label="oc-auto"><label slot="label">Label</label></oc-switch-v3>
  <oc-switch-v3><input type="checkbox" checked aria-label="oc-auto"><label slot="label">Label</label></oc-switch-v3>
<span class="anatomy-pin" style="left:-16px;top:25%">1</span>
<span class="anatomy-pin" style="left:11%;top:-14px">2</span>
<span class="anatomy-pin" style="left:26%;top:calc(100% + 14px)">3</span>
<span class="anatomy-pin" style="left:calc(100% + 16px);top:25%">4</span>
<ol class="anatomy-key"><li data-n="1">Track (grey off, green on)</li><li data-n="2">Handle</li><li data-n="3">Check icon when checked</li><li data-n="4">Label</li></ol>

Variants

The switch is available in sizes 50 and 100. There is also a loading variant for actions that take longer. When checked, the background color changes and the handle displays a check icon.

Size 50

Size 100

LiveSize 50 and 100
HTML
<p class="demo-label">Size 50</p>
<oc-switch-v3 size="50"><input type="checkbox" aria-label="oc-auto"><label slot="label">Label</label></oc-switch-v3>
<p class="demo-label">Size 100</p>
<oc-switch-v3><input type="checkbox" aria-label="oc-auto"><label slot="label">Label</label></oc-switch-v3>

Size 50

Size 100

LiveLoading variants
HTML
<p class="demo-label">Size 50</p>
<oc-switch-v3 loading size="50"><input type="checkbox" aria-label="oc-auto"><label slot="label">Label</label></oc-switch-v3>
<oc-switch-v3 loading size="50"><input type="checkbox" checked aria-label="oc-auto"><label slot="label">Label</label></oc-switch-v3>
<p class="demo-label">Size 100</p>
<oc-switch-v3 loading><input type="checkbox" aria-label="oc-auto"><label slot="label">Label</label></oc-switch-v3>
<oc-switch-v3 loading><input type="checkbox" checked aria-label="oc-auto"><label slot="label">Label</label></oc-switch-v3>

Unchecked

Checked

LiveUnchecked and checked variant
HTML
<p class="demo-label">Unchecked</p>
<oc-switch-v3><input type="checkbox" aria-label="oc-auto"><label slot="label">Label</label></oc-switch-v3>
<p class="demo-label">Checked</p>
<oc-switch-v3><input type="checkbox" checked aria-label="oc-auto"><label slot="label">Label</label></oc-switch-v3>

Behavior

States

Enabled (hover, press and focus it)

Disabled

LiveStates
HTML
<p class="demo-label">Enabled (hover, press and focus it)</p>
<oc-switch-v3><input type="checkbox" aria-label="oc-auto"><label slot="label">Label</label></oc-switch-v3>
<oc-switch-v3><input type="checkbox" checked aria-label="oc-auto"><label slot="label">Label</label></oc-switch-v3>
<p class="demo-label">Disabled</p>
<oc-switch-v3><input type="checkbox" disabled aria-label="oc-auto"><label slot="label">Label</label></oc-switch-v3>
<oc-switch-v3><input type="checkbox" checked disabled aria-label="oc-auto"><label slot="label">Label</label></oc-switch-v3>

Interaction

Users can check the switches by tapping anywhere on it. The label is also part of the hitbox and ensures proper support in assistive technologies, improving usability and accessibility. To uncheck the switch, it may be tapped again. There is also a disabled variant that cannot be clicked or tapped.

tap anywhere on the switch to check it
↓

tap anywhere on the switch to uncheck it
↓

LiveInteraction
HTML
<oc-switch-v3><input type="checkbox" aria-label="oc-auto"><label slot="label">Label</label></oc-switch-v3>
<oc-switch-v3><input type="checkbox" checked aria-label="oc-auto"><label slot="label">Label</label></oc-switch-v3>
<oc-switch-v3><input type="checkbox" aria-label="oc-auto"><label slot="label">Label</label></oc-switch-v3>

Fitting

The width of the switch is set to fit-content by default, but can be set to fill-parent. Note, that the whole line is interactive in this case. The height of the label is set to fit-content.

width-behavior fit

width-behavior fill

LiveFitting
HTML
<p class="demo-label">width-behavior fit</p>
<oc-switch-v3><input type="checkbox" aria-label="oc-auto"><label slot="label">Label</label></oc-switch-v3>
<p class="demo-label">width-behavior fill</p>
<oc-switch-v3 width-behavior="fill"><input type="checkbox" aria-label="oc-auto"><label slot="label">hier steht ein sehr, sehr, sehr, sehr langes Label</label></oc-switch-v3>

Placement

The switch has a mandatory label which can be placed left or right. Ideally, there should be a 24px gap between switches if they are placed vertically. When placing multiple switches vertically, make sure to align them properly.

LivePlacement
HTML
<oc-switch-v3><input type="checkbox" aria-label="oc-auto"><label slot="label">Label</label></oc-switch-v3>
<oc-switch-v3 style="max-width:7rem"><input type="checkbox" aria-label="oc-auto"><label slot="label">Long Label</label></oc-switch-v3>
<oc-switch-v3><input type="checkbox" aria-label="oc-auto"><label slot="label">Label</label></oc-switch-v3>

label-placement right (default)

label-placement left

LiveLeft and right label
HTML
<p class="demo-label">label-placement right (default)</p>
<oc-switch-v3><input type="checkbox" aria-label="oc-auto"><label slot="label">Label</label></oc-switch-v3>
<p class="demo-label">label-placement left</p>
<oc-switch-v3 label-placement="left"><input type="checkbox" aria-label="oc-auto"><label slot="label">Label</label></oc-switch-v3>

Switch vs. checkbox

Use the switch for immediate actions, such as toggling a setting on or off. The action happens the moment the user interacts with it.

Use the checkbox when a separate interaction is needed to confirm a choice, such as "Speichern" or "Bestätigen", or when multiple options can be selected simultaneously as part of a larger form.

Checkbox: confirmed with a button

Weiter

Switch: takes effect at once

LiveSingle selection on desktop and mobile
HTML
<p class="demo-label">Checkbox: confirmed with a button</p>
<oc-checkbox-v2><input type="checkbox" checked aria-label="oc-auto"><label slot="label">Ich möchte den OTTO-Newsletter erhalten.</label></oc-checkbox-v2>
<oc-button-v1 variant="primary">Weiter</oc-button-v1>
<p class="demo-label">Switch: takes effect at once</p>
<oc-switch-v3><input type="checkbox" checked aria-label="oc-auto"><label slot="label">OTTO-Newsletter erhalten</label></oc-switch-v3>

Do not use switches for lists consisting of multiple options. Instead, use checkboxes. Checkboxes imply that the items are related and take up less visual space than switches.

Do

Kategorie

LiveDo
HTML
<p class="demo-title" style="color:var(--oc-semantic-color-text-secondary,#6d6d6d)">Kategorie</p>
<oc-checkbox-v2><input type="checkbox" checked aria-label="oc-auto"><label slot="label">Fernseher</label></oc-checkbox-v2>
<oc-checkbox-v2><input type="checkbox" aria-label="oc-auto"><label slot="label">TV-Wandhalterung</label></oc-checkbox-v2>
<oc-checkbox-v2><input type="checkbox" aria-label="oc-auto"><label slot="label">TV-Wände</label></oc-checkbox-v2>

Don't

Kategorie

LiveDon't
HTML
<p class="demo-title" style="color:var(--oc-semantic-color-text-secondary,#6d6d6d)">Kategorie</p>
<oc-switch-v3><input type="checkbox" aria-label="oc-auto"><label slot="label">Fernseher</label></oc-switch-v3>
<oc-switch-v3><input type="checkbox" checked aria-label="oc-auto"><label slot="label">TV-Wandhalterung</label></oc-switch-v3>
<oc-switch-v3><input type="checkbox" aria-label="oc-auto"><label slot="label">TV-Wände</label></oc-switch-v3>

Best practices

DoUse Switches for on / off actions.
Benachrichtigungen aus
Don'tUse Switches for toggling between opposite options.
Don'tNest switches.

Content guidelines

DoUse short, precise labels to describe the options.
Don'tUse overly descriptive labels.
Don'tUse on or off for the label.
DoUse Sentence case (Großschreibung) for labels.

Accessibility

Implementation

Live demo

Benachrichtigungen

Lege fest, worüber wir dich per Push informieren. Deine Auswahl gilt sofort.

Versand, Zustelltermin und Rücksendungen

Wenn Artikel auf deinem Merkzettel günstiger werden

Persönliche Gutscheine und Sale-Starts

Wird gespeichert …

LiveReal OTTO components, rendered by the OTTO component runtime
HTML
<div style="max-width:440px;margin:0 auto;display:grid;gap:16px">
<div style="display:flex;align-items:center;gap:8px"><oc-icon-button-v3 icon="arrow-left" variant="transparent" oc-aria-label="Zurück"></oc-icon-button-v3><p class="oc-headline-100">Benachrichtigungen</p></div>
<p class="oc-copy-100 oc-text-color-secondary">Lege fest, worüber wir dich per Push informieren. Deine Auswahl gilt sofort.</p>
<div style="display:grid;gap:4px">
  <oc-switch-v3 width-behavior="fill" label-placement="left"><input type="checkbox" checked aria-label="oc-auto"><label slot="label">Bestellstatus und Lieferung</label></oc-switch-v3>
  <p class="oc-copy-75 oc-text-color-secondary">Versand, Zustelltermin und Rücksendungen</p>
<oc-divider-v1></oc-divider-v1>
<div style="display:grid;gap:4px">
  <oc-switch-v3 width-behavior="fill" label-placement="left"><input type="checkbox" checked aria-label="oc-auto"><label slot="label">Preisalarm</label></oc-switch-v3>
  <p class="oc-copy-75 oc-text-color-secondary">Wenn Artikel auf deinem Merkzettel günstiger werden</p>
<oc-divider-v1></oc-divider-v1>
<div style="display:grid;gap:4px">
  <oc-switch-v3 width-behavior="fill" label-placement="left"><input type="checkbox" aria-label="oc-auto"><label slot="label">Angebote und Aktionen</label></oc-switch-v3>
  <p class="oc-copy-75 oc-text-color-secondary">Persönliche Gutscheine und Sale-Starts</p>
<oc-divider-v1></oc-divider-v1>
<div style="display:grid;gap:4px">
  <oc-switch-v3 width-behavior="fill" label-placement="left" loading><input type="checkbox" aria-label="oc-auto"><label slot="label">Neuheiten deiner Lieblingsmarken</label></oc-switch-v3>
  <p class="oc-copy-75 oc-text-color-secondary">Wird gespeichert …</p>

Code

Version Tag Status API
v3 <oc-switch-v3> Stable SwitchV3
v2 <oc-switch-v2> Deprecated SwitchV2

API

API: <oc-switch-v3> (SwitchV3)

The Switch component allows users to toggle between two states (on and off). Provides configurable label placement, size, loading state, and slots for the label and input element.

Attributes / properties
Attribute Type Default Required Description
size "50" | "100" "100" no The size of the switch.
loading boolean false no Indicates whether the switch displays a loading state. When true, shows a loading animation. When false, displays the normal switch state.
width-behavior "fill" | "fit" "fit" no Defines the width behavior of the switch 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 switch indicator.
Slots
Slot Required Description
default yes Requires one of the following interactive elements: - <input type="checkbox"> for multi-selection - <input type="radio"> for single-selection

For more information on interactive components, refer to the interactive component slots documentation.
label no The label text of the switch element. The label location can be changed using the label-placement attribute. By default, the label appears on the right side of the switch.
Events
Event Detail type Description
oc-property-change OcSwitchV3Events["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 switch component as well as specific component variations for different use cases.

Default

The standard configuration with size 100 and no visible label. Uses the aria-label attribute on the input element to describe the switch purpose.

HTML
<oc-switch-v3><input type='checkbox' aria-label='Switch purpose' /></oc-switch-v3>
With label

Displays a visible label passed via the default slot. The label-placement attribute controls whether the label appears on the left or right side of the switch.

HTML
<oc-switch-v3>
<label slot="label">Switch label</label>
<input type='checkbox' aria-label='oc-auto'/>
</oc-switch-v3>
Disabled

The disabled state prevents user interaction.

HTML
<oc-switch-v3>
<label slot="label">Switch label</label>
<input type='checkbox' aria-label='oc-auto' disabled/>
</oc-switch-v3>
Older versions

Migration to v3

Migration from switch v2 to v3

The oc-switch component has been updated from oc-switch-v2 to oc-switch-v3. 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="checkbox"> 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 checkbox events are now available directly on the input element:

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

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

HTML
<oc-switch-v3>
<input type="checkbox" name="feature" aria-label="oc-auto" />
<label slot="label">
  Enable feature <span class="oc-text-color-secondary">(recommended)</span>
</label>
</oc-switch-v3>
API changes
Changed attributes
v2 Attribute v3 Attribute Notes
fit-content width-behavior="fit" Default changed from fill to "fit" in v3
label-placement label-placement No change
loading loading No change
size size No change
Changed slots
v2 Slot v3 Slot Notes
default (label text) label Label text now uses the label slot
— default Now contains the native <input type="checkbox"> element
Removed attributes

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

v2 Attribute v3 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
How to migrate

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

Migrate a basic switch
<!-- From: -->
<oc-switch-v2 name="notifications" value="on" checked>Enable notifications</oc-switch-v2>
<!-- To: -->
<oc-switch-v3>
  <input type="checkbox" name="notifications" value="on" checked aria-label="oc-auto" />
  <label slot="label">Enable notifications</label>
</oc-switch-v3>
Migrate a switch without a visible label
<!-- From: -->
<oc-switch-v2 oc-aria-label="Toggle dark mode"></oc-switch-v2>
<!-- To: -->
<oc-switch-v3>
  <input type="checkbox" aria-label="Toggle dark mode" />
</oc-switch-v3>
Migrate a switch with label placement
<!-- From: -->
<oc-switch-v2 label-placement="left">Switch label</oc-switch-v2>
<!-- To: -->
<oc-switch-v3 label-placement="left">
  <input type="checkbox" aria-label="oc-auto" />
  <label slot="label">Switch label</label>
</oc-switch-v3>
Migrate a switch with a disabled state
<!-- From: -->
<oc-switch-v2 disabled>Disabled switch</oc-switch-v2>
<!-- To: -->
<oc-switch-v3>
  <input type="checkbox" disabled aria-label="oc-auto" />
  <label slot="label">Disabled switch</label>
</oc-switch-v3>
Migrate a switch with width behavior
<!-- From: -->
<oc-switch-v2 fit-content>Fit content</oc-switch-v2>
<!-- To: -->
<oc-switch-v3 width-behavior="fit">
  <input type="checkbox" aria-label="oc-auto" />
  <label slot="label">Fit content</label>
</oc-switch-v3>

Note In v3, the default value for width-behavior is "fit" instead of "fill".

Migrate a switch with a loading state

The loading attribute remains on the component, not on the input element:

<!-- From: -->
<oc-switch-v2 loading>Processing...</oc-switch-v2>
<!-- To: -->
<oc-switch-v3 loading>
  <input type="checkbox" aria-label="oc-auto" />
  <label slot="label">Processing...</label>
</oc-switch-v3>

API v2

API: <oc-switch-v2> (SwitchV2)

The switch component provides a toggle functionality. It has attributes for setting the initial checked state, a disabled state, the value to submit if checked, the name of the input element, the label placement, and the size of the switch. The switch can be initialized as checked or unchecked, and it has a loading state that can be toggled on or off.

Attributes / properties
Attribute Type Default Required Description
size "50" | "100" "100" no Sets the size of the switch.
value string "on" no Sets the initial value of the switch to the provided value for form processing. This is also the reset value for a form reset. If omitted, the default value for the switch is on.
checked boolean false no Toggles the state of the switch between checked and unchecked. Set to true to enable the checked state.

Accessible in CSS via the custom-state mixin.
disabled boolean false no Disables the switch, preventing user interaction. Set to true to disable the switch.
loading boolean false no Toggles the state of the button between loading and not loading. Set to true to enable the loading state and display a loading animation.
fit-content boolean false no Sets the width of the switch to fit its content.
name string no Sets the name to identify the switch when submitting a form.
label-placement "left" | "right" "right" no Sets the placement direction of the label provided via the default slot relative to the switch.
oc-aria-label string undefined no Sets the ARIA label of the switch.
Slots
Slot Required Description
default no Sets the label of the switch element. Change the location of the label by setting the label-placement attribute. By default it will appear on the right side of the switch.
Events
Event Detail type Description
oc-property-change OcSwitchV2Events["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.