Fork me on GitHub

Bootstrap Switch 2.0.1

Turn checkboxes and radio buttons in toggle switches.




Mattia Larentis · Peter Stein · Emanuele Marchi




Change the size programmatically:




<input type="checkbox" checked data-size="large">
<input type="checkbox" checked>
<input type="checkbox" checked data-size="small">
<input type="checkbox" checked data-size="mini">
<input id="dimension-switch" type="checkbox" checked>
// Resets to the regular style
$('#dimension-switch').bootstrapSwitch('size', '');

// Sets a mini switch
$('#dimension-switch').bootstrapSwitch('size', 'mini');

// Sets a small switch
$('#dimension-switch').bootstrapSwitch('size', 'small');

// Sets a large switch
$('#dimension-switch').bootstrapSwitch('size', 'large');


Change the colors programmatically:

<input type="checkbox" checked data-on-color="primary" data-off-color="info">
<input type="checkbox" checked data-on-color="info" data-off-color="success">
<input type="checkbox" checked data-on-color="success" data-off-color="warning">
<input type="checkbox" checked data-on-color="warning" data-off-color="danger">
<input type="checkbox" checked data-on-color="danger" data-off-color="default">
<input type="checkbox" checked data-on-color="default" data-off-color="primary">
<input type="checkbox" id="change-color-switch" checked data-on-color="default" data-off-color="primary">
$('#change-color-switch').bootstrapSwitch('onColor', 'success');
$('#change-color-switch').bootstrapSwitch('offColor', 'danger');


<input type="checkbox" checked data-animate="false">
// Enables animation for the selected item
$('#animated-switch').bootstrapSwitch('animate', true);

// Disables animation for the selected item
$('#animated-switch').bootstrapSwitch('animate', false);
<input type="checkbox" checked disabled>
<input type="checkbox" checked readonly>


<input type="checkbox" checked data-on-text="SI" data-off-text="NO">
$('#label-switch').bootstrapSwitch('onText', 'I');
$('#label-switch').bootstrapSwitch('offText', 'O');
<input type="checkbox" checked data-label-text="TV">
Standard    Font Awesome    Flat UI
<input type="checkbox" checked data-size="large" data-label-text="<span class='glyphicon glyphicon-fullscreen'></span>" data-on-text="<span class='glyphicon glyphicon-ok'></span>" data-off-text="<span class='glyphicon glyphicon-remove'></span>">
<input type="checkbox" checked data-size="large" data-label-text="<span class='fa fa-youtube fa-lg'></span>" data-on-text="<span class='fa fa-thumbs-up fa-lg'></span>" data-off-text="<span class='fa fa-thumbs-down fa-lg'></span>">
<input type="checkbox" data-size="large" checked data-label-text="<span class='fui-video'></span>" data-on-text="<span class='fui-check'></span>" data-off-text="<span class='fui-cross'></span>">
$('#switch-change').on('switchChange', function (e, data) {
  var $element = $(data.el),
      value = data.value;

  console.log(e, $element, value);
});
<label id="label-toggle-switch">Click on this Text to change the switch state</label>
<input type="checkbox" checked>
$('#label-toggle-switch').on('click', function(e, data) {
    $('.label-toggle-switch').bootstrapSwitch('toggleState');
});
$('.label-toggle-switch').on('switch-change', function (e, data) {
    alert(data.value);
});


State!
On
Toggle
Off
$('#toggle-state-switch').bootstrapSwitch('state'); // true || false
$('#toggle-state-switch').bootstrapSwitch('toggleState');
$('#toggle-state-switch').bootstrapSwitch('state', false); // true || false


$('#destroy-switch').bootstrapSwitch('destroy');






$('#disable-switch').bootstrapSwitch('disabled');
$('#disable-switch').bootstrapSwitch('toggleDisabled');
$('#disable-switch').bootstrapSwitch('disabled', true);  // true || false

$('#readonly-switch').bootstrapSwitch('readonly');
$('#readonly-switch').bootstrapSwitch('toggleReadonly');
$('#readonly-switch').bootstrapSwitch('readonly', true);  // true || false
     
<div class="form-group">
  <label for="option1">Option 1</label>
  <input id="option1" type="radio" name="radio1" value="option1">
  <label for="option2">Option 2</label>
  <input id="option2" type="radio" name="radio1" value="option2">
  <label for="option3">Option 3</label>
  <input id="option3" type="radio" name="radio1" value="option3">
</div>
<div class="form-group">
  <label for="option11">Option 1</label>
  <input id="option11" type="radio" name="radio2" value="option1">
  <label for="option12">Option 2</label>
  <input id="option12" type="radio" name="radio2" value="option2" checked="checked">
  <label for="option13">Option 3</label>
  <input id="option13" type="radio" name="radio2" value="option3">
</div>
<form class="form-horizontal">
  <div class="form-group">
    <label class="control-label" for="inputEmail">Email</label>
    <input type="text" id="inputEmail" placeholder="Email">
  </div>
  <div class="form-group">
    <label class="control-label" for="notification1">Notification 1</label>
    <input id="notification1" type="checkbox">
  </div>
  <div class="form-group">
    <label class="control-label" for="notification2">Notification 2</label>
    <input id="notification2" type="checkbox">
  </div>
  <div class="form-actions">
    <button type="reset" class="btn btn-inverse">Reset</button>
  </div>
</form>
<a href="#myModal" role="button" class="btn btn-default" data-toggle="modal">Modal</a>

<div class="modal-body">
  <input type="checkbox" checked>
</div>