OTTODesign System

ComponentsForm

Checkbox

The checkbox allows users to select one or multiple options from a set of options or a single yes/no option.

Configurator

LiveCheckbox: size, width, label position, texts and state
HTML
<oc-checkbox-v2><input type="checkbox" aria-label="oc-auto"><label slot="label">Ich möchte den OTTO-Newsletter erhalten.</label></oc-checkbox-v2>

Usage

Anatomy

1 2
  1. Checkbox
  2. Label
LiveAnatomy
HTML
<div class="anatomy" style="display:block;width:max-content;margin:28px auto">
<oc-checkbox-v2 width-behavior="fit"><input type="checkbox" aria-label="oc-auto"><label slot="label">Label</label></oc-checkbox-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">Checkbox</li><li data-n="2">Label</li></ol>

Variants

There are two variants of the checkbox. 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 akzeptiere die AGB.

Default, size 50

Error, size 50

Bitte akzeptiere die AGB.
LiveDefault and error, sizes 100 and 50
HTML
<p class="demo-label">Default, size 100</p>
<oc-checkbox-v2 width-behavior="fit"><input type="checkbox" aria-label="oc-auto"><label slot="label">Newsletter abonnieren</label></oc-checkbox-v2>
<p class="demo-label">Error, size 100</p>
<oc-checkbox-v2 width-behavior="fit"><input type="checkbox" aria-label="oc-auto"><label slot="label">AGB akzeptieren</label><span slot="error">Bitte akzeptiere die AGB.</span></oc-checkbox-v2>
<p class="demo-label">Default, size 50</p>
<oc-checkbox-v2 size="50" width-behavior="fit"><input type="checkbox" aria-label="oc-auto"><label slot="label">Newsletter abonnieren</label></oc-checkbox-v2>
<p class="demo-label">Error, size 50</p>
<oc-checkbox-v2 size="50" width-behavior="fit"><input type="checkbox" aria-label="oc-auto"><label slot="label">AGB akzeptieren</label><span slot="error">Bitte akzeptiere die AGB.</span></oc-checkbox-v2>

Behavior

States

Enabled (hover, press, focus it)

Error

Disabled

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

Interaction

Users can check a checkbox 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 it, it may be tapped again. There is also a disabled variant of the checkbox that cannot be clicked or tapped.

Indeterminate

An indeterminate state indicates that a checkbox's value is neither fully checked nor unchecked, typically used in nested lists to show that only some sub-items are selected. It serves as a visual "mixed" status, ensuring the parent element accurately reflects the partial selection of its children without implying a checked or default state.

In a nested list, there are three specific states possible: Indeterminate (only some sub-elements are selected), Checked (all sub-elements are selected), and Unchecked (no sub-elements are selected).

When

Fitting

The checkbox 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-checkbox-v2 width-behavior="fit"><input type="checkbox" aria-label="oc-auto"><label slot="label">Label</label></oc-checkbox-v2>
<p class="demo-label">fill (default)</p>
<oc-checkbox-v2><input type="checkbox" aria-label="oc-auto"><label slot="label">Label</label></oc-checkbox-v2>
<p class="demo-label">Long label wraps</p>
<oc-checkbox-v2><input type="checkbox" aria-label="oc-auto"><label slot="label">Ich möchte über Angebote und Neuheiten per E-Mail informiert werden.</label></oc-checkbox-v2>

Placement

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

Label right (default)

Label left

LiveLabel placement
HTML
<p class="demo-label">Label right (default)</p>
<oc-checkbox-v2 width-behavior="fit"><input type="checkbox" aria-label="oc-auto"><label slot="label">Label</label></oc-checkbox-v2>
<p class="demo-label">Label left</p>
<oc-checkbox-v2 width-behavior="fit" label-placement="left"><input type="checkbox" aria-label="oc-auto"><label slot="label">Label</label></oc-checkbox-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="Kategorie">
<oc-checkbox-v2><input type="checkbox" aria-label="oc-auto"><label slot="label">Label</label></oc-checkbox-v2>
<oc-checkbox-v2><input type="checkbox" aria-label="oc-auto"><label slot="label">Label</label></oc-checkbox-v2>
<oc-checkbox-v2><input type="checkbox" aria-label="oc-auto"><label slot="label">Label</label></oc-checkbox-v2>
</oc-form-group-v1>

Checkbox vs. radio button

Use the checkbox when multiple options can be selected (multiple selection) or a standalone option can be checked. When only one option can be selected from a list use radio buttons (single selection).

Checkbox: several choices

Radio button: one choice

LiveMultiple selection and single 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="cb-vs-rb" aria-label="oc-auto"><label slot="label">Standardversand</label></oc-radio-button-v2>
<oc-radio-button-v2><input type="radio" name="cb-vs-rb" checked aria-label="oc-auto"><label slot="label">Expressversand</label></oc-radio-button-v2>
<oc-radio-button-v2><input type="radio" name="cb-vs-rb" aria-label="oc-auto"><label slot="label">Abholung</label></oc-radio-button-v2>

Checkbox vs. switch

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.

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

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">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">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

CautionAvoid using horizontal Checkbox lists.

Even if they are placed far enough from each other, the associated label for a checkbox may be mixed up with a different one by users.

LiveCaution
HTML
<oc-checkbox-v2 width-behavior="fit"><input type="checkbox" aria-label="oc-auto"><label slot="label">Rot</label></oc-checkbox-v2>
<oc-checkbox-v2 width-behavior="fit"><input type="checkbox" aria-label="oc-auto"><label slot="label">Blau</label></oc-checkbox-v2>
<oc-checkbox-v2 width-behavior="fit"><input type="checkbox" aria-label="oc-auto"><label slot="label">Grün</label></oc-checkbox-v2>
CautionOnly nest checkboxes if you are using the indeterminate state.
DoUse the actual label of the checkbox.

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

LiveDo
HTML
<oc-checkbox-v2 width-behavior="fit"><input type="checkbox" aria-label="oc-auto"><label slot="label">Auch der Text ist klickbar</label></oc-checkbox-v2>
Newsletter
Don'tUse custom 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

Newsletter abonnieren

Neuheiten, Trends und Angebote, passend zu dem, was dich interessiert.

E-Mail-Adresse

Was interessiert dich?

Du kannst dich jederzeit wieder abmelden. Jetzt anmelden
LiveReal OTTO components, rendered by the OTTO component runtime
HTML
<div style="max-width:720px;margin:0 auto;display:grid;grid-template-columns:repeat(auto-fit,minmax(15rem,1fr));gap:32px;align-items:center">
<img src="/previews/imagery/samples/otto-colour-field/colour-field-parcel.webp" alt="" style="display:block;width:100%;aspect-ratio:4/5;object-fit:cover;border-radius:12px">
<div style="display:grid;gap:20px">
  <div style="display:grid;gap:4px">
    <p class="oc-headline-100">Newsletter abonnieren</p>
    <p class="oc-copy-100 oc-text-color-secondary">Neuheiten, Trends und Angebote, passend zu dem, was dich interessiert.</p>
  <oc-text-field-v1 type="email" autocomplete="email">E-Mail-Adresse</oc-text-field-v1>
  <div style="display:grid;gap:12px">
    <p class="oc-copy-100"><b>Was interessiert dich?</b></p>
    <oc-form-group-v1 orientation="vertical" gap="var(--oc-base-dimension-16)" oc-aria-label="Interessen">
      <oc-checkbox-v2><input type="checkbox" checked aria-label="oc-auto"><label slot="label">Mode</label></oc-checkbox-v2>
      <oc-checkbox-v2><input type="checkbox" checked aria-label="oc-auto"><label slot="label">Wohnen</label></oc-checkbox-v2>
      <oc-checkbox-v2><input type="checkbox" aria-label="oc-auto"><label slot="label">Technik</label></oc-checkbox-v2>
    </oc-form-group-v1>
  <oc-divider-v1></oc-divider-v1>
  <oc-checkbox-v2 size="50"><input type="checkbox" required aria-label="oc-auto"><label slot="label">Ja, ich möchte den OTTO-Newsletter per E-Mail erhalten.</label><span slot="hint">Du kannst dich jederzeit wieder abmelden.</span></oc-checkbox-v2>
  <oc-button-v1 variant="primary">Jetzt anmelden</oc-button-v1>

Code

Version Tag Status API
v2 <oc-checkbox-v2> Stable CheckboxV2
v1 <oc-checkbox-v1> Deprecated CheckboxV1

API

API: <oc-checkbox-v2> (CheckboxV2)

The Checkbox component allows users to select one or more options from a set. Provides attributes for state, styling, validation, 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 checkbox.
width-behavior "fill" | "fit" "fill" no Defines the width behavior of the checkbox 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 checkbox indicator.
Slots
Slot Required Description
default yes Requires the following interactive element: - <input type="checkbox"> for multi-selection

For more information on interactive components, refer to the interactive component slots documentation.
label no The text content of the checkbox label. Provides a brief description of the option represented by the checkbox.
hint no A hint text displayed below the checkbox. Provides additional information to help users understand the option.
error no An error message displayed below the checkbox. Informs users about validation errors or requirements.
Events
Event Detail type Description
oc-property-change OcCheckboxV2Events["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 checkbox 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-checkbox-v2>
<label slot="label">my label</label>
<input type="checkbox" aria-label="oc-auto" />
</oc-checkbox-v2>
Label placement: left

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

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

Displays an error state with a hint and error message.

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

The disabled state prevents user interaction.

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

Size 50 variant of the checkbox.

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

The demo filter showcases how to use Checkboxes for filtering.

HTML
<oc-form-group-v1 orientation="vertical">
<oc-checkbox-v2>
  <input type="checkbox" name="zielgruppe" value="Damen" aria-label="oc-auto" />
  <label slot="label" class="my-label"
    >Damen<span class="oc-text-color-secondary">374637</span></label
  >
</oc-checkbox-v2>
<oc-checkbox-v2>
  <input type="checkbox" name="zielgruppe" value="Herren" aria-label="oc-auto" />
  <label slot="label" class="my-label"
    >Herren<span class="oc-text-color-secondary">234324</span></label
  >
</oc-checkbox-v2>
<oc-checkbox-v2>
  <input type="checkbox" name="zielgruppe" value="Mädchen" aria-label="oc-auto" />
  <label slot="label" class="my-label"
    >Mädchen<span class="oc-text-color-secondary">2323</span></label
  >
</oc-checkbox-v2>
<oc-checkbox-v2>
  <input type="checkbox" name="zielgruppe" value="Jungen" aria-label="oc-auto" />
  <label slot="label" class="my-label"
    >Jungen<span class="oc-text-color-secondary">1224</span></label
  >
</oc-checkbox-v2>
</oc-form-group-v1>
<oc-form-group-v1 class="oc-mt-200" orientation="vertical">
<oc-checkbox-v2 label-placement="left">
  <input type="checkbox" name="zielgruppe" value="Damen" aria-label="oc-auto" />
  <label slot="label" class="my-label"
    >Damen<span class="oc-text-color-secondary">374637</span></label
  >
</oc-checkbox-v2>
<oc-checkbox-v2 label-placement="left">
  <input type="checkbox" name="zielgruppe" value="Herren" aria-label="oc-auto" />
  <label slot="label" class="my-label"
    >Herren<span class="oc-text-color-secondary">234324</span></label
  >
</oc-checkbox-v2>
<oc-checkbox-v2 label-placement="left">
  <input type="checkbox" name="zielgruppe" value="Mädchen" aria-label="oc-auto" />
  <label slot="label" class="my-label"
    >Mädchen<span class="oc-text-color-secondary">2323</span></label
  >
</oc-checkbox-v2>
<oc-checkbox-v2 label-placement="left">
  <input type="checkbox" name="zielgruppe" value="Jungen" aria-label="oc-auto" />
  <label slot="label" class="my-label"
    >Jungen<span class="oc-text-color-secondary">1224</span></label
  >
</oc-checkbox-v2>
</oc-form-group-v1>
<style>
.my-label {
  display: flex;
  justify-content: space-between;
}
</style>
Older versions

Migration to v2

Migration from checkbox v1 to v2

The oc-checkbox component has been updated from oc-checkbox-v1 to oc-checkbox-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="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:

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

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

HTML
<oc-checkbox-v2>
<input type="checkbox" name="option" aria-label="oc-auto" />
<label slot="label"> Option <span class="oc-text-color-secondary">(123)</span> </label>
</oc-checkbox-v2>
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="checkbox"> 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
required Set required on the <input> element Moved to native input
oc-aria-label Set aria-label on the <input> element Renamed to standard attribute
hint Use the hint slot Moved to slot
validation-message Use the error slot Moved to slot
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="checkbox"> element in the default slot instead of managing the checkbox state internally. This provides better accessibility, form integration, and native event support.

Migrate a basic checkbox
<!-- From: -->
<oc-checkbox-v1 name="terms" value="accepted" checked>Accept terms</oc-checkbox-v1>
<!-- To: -->
<oc-checkbox-v2>
  <input type="checkbox" name="terms" value="accepted" checked aria-label="oc-auto" />
  <label slot="label">Accept terms</label>
</oc-checkbox-v2>
Migrate a checkbox with hint and validation message
<!-- From: -->
<oc-checkbox-v1
  name="terms"
  hint="Please read the terms carefully"
  validation-message="You must accept the terms"
  variant="error"
>
  Accept terms
</oc-checkbox-v1>
<!-- To: -->
<oc-checkbox-v2>
  <input type="checkbox" name="terms" aria-label="oc-auto" />
  <label slot="label">Accept terms</label>
  <span slot="hint">Please read the terms carefully</span>
  <span slot="error">You must accept the terms</span>
</oc-checkbox-v2>
Migrate a checkbox with a disabled state
<!-- From: -->
<oc-checkbox-v1 disabled>Disabled checkbox</oc-checkbox-v1>
<!-- To: -->
<oc-checkbox-v2>
  <input type="checkbox" disabled aria-label="oc-auto" />
  <label slot="label">Disabled checkbox</label>
</oc-checkbox-v2>
Migrate a checkbox with width behavior
<!-- From: -->
<oc-checkbox-v1 fit-content>Fit content</oc-checkbox-v1>
<!-- To: -->
<oc-checkbox-v2 width-behavior="fit">
  <input type="checkbox" aria-label="oc-auto" />
  <label slot="label">Fit content</label>
</oc-checkbox-v2>

API v1

API: <oc-checkbox-v1> (CheckboxV1)

The Checkbox component allows users to select one or more options from a set, with properties for state, styling, and accessibility, and a slot for setting the Checkbox label text.

Attributes / properties
Attribute Type Default Required Description
variant "default" | "error" "default" no Sets the main styling variant of the checkbox. Can be one of: "default", "error".
value string "on" no Sets the initial value of a ticked checkbox to the provided value for form processing. If this attribute is not specified, the default value of value="on" is used as the submitted data.
hint string undefined no Provides additional information related to the checkbox below the element.
validation-message string undefined no Provides a validation message related to the checkbox below the element.

Implicitly sets the checkbox to the error state.
checked boolean false no Indicates whether the checkbox is checked. When enabled, the checkbox is initially ticked.

Accessible in CSS via the custom-state mixin.
disabled boolean false no Indicates whether the checkbox is disabled, preventing user interaction and input.
required boolean false no Indicates whether the input is required for screen readers. Doesn't prevent form submission on its own.
fit-content boolean no Sets the width behavior of the checkbox.
name string undefined no Sets the name tag to identify the checkbox when submitting a form. Mandatory if single-selection is set to true.
label-placement "left" | "right" "right" no Sets the placement direction of the label provided via the default slot relative to the checkbox.
oc-aria-label string undefined no Sets the ARIA label of the checkbox.
Slots
Slot Required Description
default yes Sets the text content for the checkbox label to provide a brief description of the input field.
Events
Event Detail type Description
oc-property-change OcCheckboxV1Events["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.