Bootstrap Switch

Turn checkboxes and radio buttons in toggle switches.

Download Bootstrap Switch 3 Release Candidate

Getting Started

Include the dependencies: jQuery, Bootstrap and Bootstrap Switch CSS + Javascript.

[...]
<link href="bootstrap.css" rel="stylesheet">
<link href="bootstrap-switch.css" rel="stylesheet">
<script src="jquery.js"></script>
<script src="bootstrap-switch.js"></script>
[...]

Options

NameTypeDescriptionValuesDefault
stateBooleanThe checkbox statetrue, false'checked' attribute or true
sizeString | NullThe checkbox statenull, 'mini', 'small', 'large'null
animateBooleanAnimate the switchtrue, falsetrue
disabledBooleanDisable statetrue, false'disabled' attribute or false
readonlyBooleanReadonly statetrue, false'readonly' attribute or false
onColorStringColor of the left side of the switch'primary', 'info', 'success', 'warning', 'danger', 'default''primary'
offColorStringColor of the right side of the switch'primary', 'info', 'success', 'warning', 'danger', 'default''default'
onTextStringText of the left side of the switchString'ON'
offTextStringText of the right side of the switchString'OFF'
labelTextStringText of the center handle of the switchString' '
onObjectCallback functions collection
on.initFunctionCallback function to execute on initializationFunctionfunction() {}
on.switchChangeFunctionCallback function to execute on switch state changeFunctionfunction() {}

Methods

In Bootstrap Switch, every option is also a method.

You can call a method in this way:

$('input[name="my-checkbox"]').bootstrapSwitch('state', true);

Additional Methods

NameDescription
toggleStateToggle the switch state
toggleDisabledToggle the disabled state
toggleReadonlyToggle the readonly state
destroyDestroy the instance of Bootstrap Switch

Examples