Docs

Switch Styling

Styling API reference for the Switch component.

Style Variants

The following style variants can be applied:

Variant Description Supported by

icon

Shows a checkmark inside the marker when on, and a cross when off, for a stronger at-a-glance affordance

Aura, Lumo

small

Renders a more compact switch

Aura

reverse

Places the label before the switch, reversing their order

Aura

Style Properties

The following style properties can be used in CSS stylesheets to customize the appearance of this component.

To apply values to these properties globally in your application UI, place them in a CSS block using the html {…​} selector. See Component Style Properties for more information on style properties.

Note
Input Field Components Shared Styles
Style properties whose names start with --vaadin-input-field are shared among all input field components. To apply them only to a specific type of component, use an element selector like vaadin-text-field {…​}

Switch Properties

Property Supported by

--vaadin-switch-background

Aura, Lumo

--vaadin-switch-border-color

Aura, Lumo

--vaadin-switch-border-radius

Aura, Lumo

--vaadin-switch-border-width

Aura, Lumo

--vaadin-switch-gap

Aura, Lumo

--vaadin-switch-height

Aura, Lumo

--vaadin-switch-width

Aura, Lumo

--vaadin-switch-icon-color

Aura, Lumo

--vaadin-switch-icon-size

Aura, Lumo

--vaadin-switch-label-color

Lumo

--vaadin-switch-label-font-size

Lumo

--vaadin-switch-label-font-weight

Lumo

--vaadin-switch-label-line-height

Lumo

--vaadin-switch-marker-border-color

Aura, Lumo

--vaadin-switch-marker-border-radius

Aura, Lumo

--vaadin-switch-marker-border-width

Aura, Lumo

--vaadin-switch-marker-color

Aura, Lumo

--vaadin-switch-marker-height

Aura, Lumo

--vaadin-switch-marker-scale

Aura, Lumo

--vaadin-switch-marker-width

Aura, Lumo

Label

Property Supported by

--vaadin-input-field-focused-label-color

Lumo

--vaadin-input-field-hovered-label-color

Lumo

--vaadin-input-field-label-color

Aura, Lumo

--vaadin-input-field-label-font-size

Aura, Lumo

--vaadin-input-field-label-font-weight

Aura, Lumo

--vaadin-input-field-label-line-height

Aura, Lumo

--vaadin-input-field-required-indicator-color

Aura, Lumo

--vaadin-input-field-required-indicator

Aura, Lumo

Helper

Property Supported by

--vaadin-input-field-helper-color

Aura, Lumo

--vaadin-input-field-helper-font-size

Aura, Lumo

--vaadin-input-field-helper-font-weight

Aura, Lumo

--vaadin-input-field-helper-line-height

Aura, Lumo

--vaadin-input-field-helper-spacing

Lumo

Error Message

Property Supported by

--vaadin-input-field-error-color

Aura, Lumo

--vaadin-input-field-error-font-size

Aura, Lumo

--vaadin-input-field-error-font-weight

Aura, Lumo

--vaadin-input-field-error-line-height

Aura, Lumo

CSS Selectors

The following CSS selectors can be used in stylesheets to target the various parts and states of the component. See the Styling documentation for more details on how to style components.

Important
Not for Shadow DOM
These selectors should be used in styles.css or another stylesheet loaded with the @StyleSheet annotation or the @import CSS rule. They do not work in the shadow DOM of Vaadin components, such as in stylesheets in the components sub-folder or loaded with the @CssImport annotation’s themeFor property.

Switch

Root element

vaadin-switch

Focused

vaadin-switch[focused]

Keyboard focused

vaadin-switch[focus-ring]

Disabled

vaadin-switch[disabled]

Read-only

vaadin-switch[readonly]

Pressed

vaadin-switch[active]

Checked (on)

vaadin-switch[checked]

Track

vaadin-switch::part(switch)

Marker

vaadin-switch::part(marker)

Label

vaadin-switch::part(label)

Label

Switch with label

vaadin-switch[has-label]

Label

vaadin-switch::part(label)

Label text

vaadin-switch > label

Required switch

vaadin-switch[required]

Required indicator

vaadin-switch::part(required-indicator)

Helper and Validation Error

Field with helper

vaadin-switch[has-helper]

Helper

vaadin-switch::part(helper-text)

Helper text

vaadin-switch > [slot="helper"]

Invalid field

vaadin-switch[invalid]

Field with error message

vaadin-switch[has-error-message]

Error message

vaadin-switch::part(error-message)

Error message text

vaadin-switch > [slot="error-message"]

Updated