Bootstrap snippet and html example. Bootstrap 3 Toggle Switch buttons

This html snippet was created to help web designers, web developers, front-end and back-end developer save time. Use it for free in your project and build your app faster, You can also download the HTML, CSS, and JS code.
Tags: buttons

HTML code

This is the html code used to create this bootstrap snippet, You can copy and paste the following html code inside a page with bootstrap 3.1.0 included, to get the result that you can see in the preview selection


              	  
<div class="container bootstrap snippets bootdey">
  <h2>Bootstrap Switch Button</h2>
  <p class="page-header">Simple Toggle Buttons for Bootstrap 3</p>
  <h4>Large</h4>
  <div class="btn-group btn-toggle"> 
    <button class="btn btn-lg btn-default">ON</button>
    <button class="btn btn-lg btn-primary active">OFF</button>
  </div>
  <hr>
  
  <h4>Medium (default)</h4>
  <div class="btn-group btn-toggle"> 
    <button class="btn btn-default">ON</button>
    <button class="btn btn-primary active">OFF</button>
  </div>
  <hr>
  
  <h4>Small</h4>
  <div class="btn-group btn-toggle"> 
    <button class="btn btn-sm btn-default">ON</button>
    <button class="btn btn-sm btn-primary active">OFF</button>
  </div>
  <hr>
  
  <h4>Tiny</h4>
  <div class="btn-group btn-toggle"> 
    <button class="btn btn-xs btn-default">ON</button>
    <button class="btn btn-xs btn-primary active">OFF</button>
  </div>
  <hr>
  
  <h4>More Switch Examples</h4>
  <ul class="list-inline">
    <li>
      <div class="btn-group btn-toggle"> 
        <button class="btn btn-xs btn-default">ON</button>
    	<button class="btn btn-xs btn-success active">OFF</button>
    	</div>
    </li>
    <li>
      <div class="btn-group btn-toggle"> 
    	<button class="btn btn-xs btn-default">ON</button>
    	<button class="btn btn-xs btn-danger active">OFF</button>
    	</div>
    </li>
    <li>
      <div class="btn-group btn-toggle"> 
    	<button class="btn btn-xs btn-default">ON</button>
    	<button class="btn btn-xs btn-info active">OFF</button>
    	</div>
    </li>
    <li>
      <div class="btn-group btn-toggle"> 
    	<button class="btn btn-xs btn-success">Y</button>
    	<button class="btn btn-xs btn-danger active">N</button>
    	</div>
    </li>
    <li>
      <div class="btn-group btn-toggle"> 
    	<button class="btn btn-xs btn-default">1</button>
    	<button class="btn btn-xs btn-primary active">0</button>
    	</div>
    </li>
    <li>
      <div class="btn-group btn-toggle"> 
        <button class="btn btn-xs btn-primary active">Preview</button>
    	<button class="btn btn-xs btn-default">Source Code</button>
    	</div>
    </li>
    <li>
      <div class="btn-group btn-toggle"> 
    	<button class="btn btn-xs btn-info">Yes</button>
    	<button class="btn btn-xs btn-primary active">No</button>
    	</div>
    </li>
  </ul>
  <hr>
  
  <!-- collapse example -->
  <h4>Collapse (Show/Hide)</h4>
  <div class="btn-group btn-toggle"> 
    <button class="btn btn-default" data-toggle="collapse" data-target="#collapsible">Open</button>
    <button class="btn btn-primary active" data-toggle="collapse" data-target="#collapsible">Close</button>
  </div>
  <div class="well collapse" id="collapsible"> 
     Hello world. Here I am.
  </div>
  <hr>
  
  
  <!-- form radio buttons example -->
  <h4>Form Radio Buttons</h4>
  <form class="form">
  <div class="btn-group btn-toggle" data-toggle="buttons">
    <label class="btn btn-primary active">
      <input name="options" value="option1" type="radio"> Option 1
    </label>
    <label class="btn btn-default">
      <input name="options" value="option2" checked="" type="radio"> Option 2
    </label>
  </div>
  <button class="btn btn-default">Submit</button>
  </form>  
  
</div>
                

CSS code

This is the css code used to create this bootstrap snippet, You can copy and paste the following css code inside a page with bootstrap 3.1.0 included, to get the result that you can see in the preview selection


              	  

                
body{margin-top:20px;}                            

Javascript/Jquery code

This is the javascript code used to create this bootstrap snippet, You can copy and paste the following javascript code inside a page with bootstrap 3.1.0 included, to get the result that you can see in the preview selection


              	  
$('.btn-toggle').click(function() {
    $(this).find('.btn').toggleClass('active');  
    
    if ($(this).find('.btn-primary').size()>0) {
        $(this).find('.btn').toggleClass('btn-primary');
    }
    if ($(this).find('.btn-danger').size()>0) {
    	$(this).find('.btn').toggleClass('btn-danger');
    }
    if ($(this).find('.btn-success').size()>0) {
    	$(this).find('.btn').toggleClass('btn-success');
    }
    if ($(this).find('.btn-info').size()>0) {
    	$(this).find('.btn').toggleClass('btn-info');
    }
    
    $(this).find('.btn').toggleClass('btn-default');
       
});
               

Similar snippets

Bootstrap example and template. unify buttons

unify buttons

Bootstrap example and template. Angle buttons

Angle buttons

Bootstrap example and template. Social network login with buttons

Social network login with buttons

Bootstrap example and template. Designer buttons

Designer buttons

Bootstrap example and template. bs5 dark footer

bs5 dark footer

Bootstrap example and template. profile with data and skills

profile with data and skills

Bootstrap example and template. simple Jobs openning list

simple Jobs openning list

Bootstrap example and template. profile edit data and skills

profile edit data and skills

Bootstrap example and template. Bootstrap 3 Toggle Switch buttons

About this bootstrap example/template

We hope you will enjoy this awesome snippet and stay tuned for the latest updates, bootdey snippets are already used in thousands of blogs, websites and projects. We believe it will save your precious time and gives trendy look to your next web project.

We always try to offer the best beautiful and responsive source of Bootstrap code examples and components.

This code example currectly have 33.9K views, Using this bootstrap snippet you have the following benefits:

Bootstrap 3.1.0

<link rel='stylesheet' href='https://netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css'>

<script src='https://netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js'></script>

This code example is based on bootstrap 3.1.0 and the grid system of this framework

Responsive

Based on bootstrap framework makes all the layouts perfectly responsive for all devices

Crossbrowser compatibility

Tested on all major browsers, it works smoothly on all of them

Jquery plugins

Great built-in plugins with jquery framework, you can easy to change all declarations

semantic html 5

Built on html / css3 the code quality is really amazing

Simple Integration

This code example can be simply integrated on existing sites and new ones too, all you need to do is copy the code and start working