New to Kendo UI for jQuery? Download free 30-day trial

Appearance

As of Kendo UI R1 2022, the jQuery Switch widget has new rendering and styling options. In this article, you will find information about the rendering of the Kendo UI Switch.

For additional information regarding the decision behind these changes, visit the Rendering Components article.

For a live example, visit the Appearance Demo of the Switch.

Options

The Kendo UI Switch supports the following styling options:

  • size—configures the overall size of the component.
  • trackRounded—configures the track's border radius.
  • thumbRounded—configures the thumb's border radius.

Size

The size option controls how big or small the switch looks. The structure of the class is k-switch-{size}.

The following values are available for the size option:

  • sm—small size
  • md—medium size
  • lg—large size

The default size value is medium and it is applied to the wrapping span element through the k-switch-md class.

The example below shows a basic Switch configuration and how to set the size option:

    <input id="switch" />
    <script>
        $("#switch").kendoSwitch({
            size:"large"
        })
    </script>

The option affects the span.k-switch element:

<span class="k-switch k-switch-on k-switch-lg">
</span>

TrackRounded

The trackRounded option controls how much border radius is applied to track of the widget. The structure of the class is k-rounded-{size}.

The following values are available for the trackRounded option:

  • sm—small border radius
  • md—medium border radius
  • lg—large border radius
  • full—ellipse-like border radius

The default value is full and it is applied to the wrapping span element that contains the On/Off labels through the k-rounded-full class.

The example below shows a basic Switch configuration and how to set the trackRounded option:

    <input id="switch" />
    <script>
        $("#switch").kendoSwitch({
            trackRounded:"large"
        })
    </script>

The option affects the span element that wraps the On/Off labels:

<span class="k-switch-track k-rounded-lg">
</span>

ThumbRounded

The thumbRounded option controls how much border radius is applied to thumb of the widget. The structure of the class is k-rounded-{size}.

The following values are available for the thumbRounded option:

  • sm—small border radius
  • md—medium border radius
  • lg—large border radius
  • full—ellipse-like border radius

The default value is full and it is applied to the span element for the thumb through the k-rounded-full class.

The example below shows a basic Switch configuration and how to set the thumbRounded option:

    <input id="switch" />
    <script>
        $("#switch").kendoSwitch({
            thumbRounded:"large"
        })
    </script>

The option affects the span element for the Switch handle:

<span class="k-switch-thumb k-rounded-md">
</span>

Old vs New Rendering

The old rendering of the component consisted of a span element with classes named k-switch k-widget k-switch-on. The span element contained the wrapper for the Switch's labels and handle both.

 <span class="k-switch k-widget k-switch-on">
    <span class="k-switch-container">
        <span class="k-switch-label-on">On</span>
        <span class="k-switch-label-off">Off</span>
        <span class="k-switch-handle"></span>
    </span>
</span>

The new rendering of the component includes separate wrapping span elements for the labels and the handle.

  • The labels are placed in a span element with classes k-switch-track k-rounded-full:
<span class="k-switch-track k-rounded-full">
    <span class="k-switch-label-on">On</span>
    <span class="k-switch-label-off">Off</span>
</span>
  • The handle is rendered in a span element with classes k-switch-thumb-wrap:
<span class="k-switch-thumb-wrap">
    <span class="k-switch-thumb k-rounded-full"></span>
</span>

The full rendering of the component has the following HTML structure:

<span class="k-switch k-switch-on k-switch-md k-rounded-full">
    <span class="k-switch-track k-rounded-full">
        <span class="k-switch-label-on">On</span>
        <span class="k-switch-label-off">Off</span>
    </span>
    <span class="k-switch-thumb-wrap">
        <span class="k-switch-thumb k-rounded-full"></span>
    </span>
</span>

Visual Backwards Compatibility

In order to achieve the same look and feel as the old rendering, the element references must be updated. Visit the CSS Classes Migration and JQuery Selectors Migration sections of the Styling Overview article for additional information.

The new styling and rendering supports only the default options you use a LESS theme.

See Also

In this article