Bootstrap Switch 1

Webkit only switch as it restyles a checkbox. Very simple HTML but not cross-browser at all. (Based on http://forr.st/~vqz)

by r1ch0

HTML

<input type="checkbox" checked class="switch" />
<input type="checkbox" checked class="switch switch-warning" data-label-on="ON" data-label-off="OFF" />
<input type="checkbox" checked class="switch switch-danger" data-label-on="FIRE" />
<input type="checkbox" checked class="switch switch-success" data-label-on="COOL" data-label-off="FAIL" />
<input type="checkbox" checked class="switch switch-info" data-label-on="YES" data-label-off="NO" />
<input type="checkbox" checked class="switch switch-inverse" data-label-on="I" data-label-off="O" />
<input type="checkbox" class="switch" />

CSS

/* Generated from LESS using BS mixins */
input[type="checkbox"].switch {
  outline: none;
  width: 77px;
  height: 28px;
  cursor: pointer;
  position: relative;
  -webkit-border-radius: 15px;
  -moz-border-radius: 15px;
  border-radius: 15px;
  -webkit-background-clip: padding-box;
  -moz-background-clip: padding-box;
  background-clip: padding-box;
  border: 0;
  -webkit-transition: all 1s linear;
  -moz-transition: all 1s linear;
  -ms-transition: all 1s linear;
  -o-transition: all 1s linear;
  transition: all 1s linear;
}
input[type="checkbox"].switch:before,
input[type="checkbox"].switch:after {
  font-size: 14px;
  font-weight: bold;
  line-height: 24px;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  cursor: pointer;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
  text-align: center;
  position: absolute;
  z-index: 1;
  width: 26px;
  height: 24px;
  top: 1px;
  border: 0;
}
input[type="checkbox"].switch:after {
  content: "ON";
  left: 1px;
  -webkit-border-radius: 15px 0 0 15px;
  -moz-border-radius: 15px 0 0 15px;
  border-radius: 15px 0 0 15px;
}
input[type="checkbox"].switch:before {
  content: "OFF";
  right: 1px;
  -webkit-border-radius: 0 15px 15px 0;
  -moz-border-radius: 0 15px 15px 0;
  border-radius: 0 15px 15px 0;
}
input[type="checkbox"].switch[data-label-on]:after {
  content: attr(data-label-on);
}
input[type="checkbox"].switch[data-label-off]:before {
  content: attr(data-label-off);
}
input[type="checkbox"].switch:before,
input[type="checkbox"].switch:checked:after {
  text-indent: 0;
  background-color: #f0f0f0;
  background-image: -moz-linear-gradient(top, #e6e6e6, #ffffff);
  background-image: -ms-linear-gradient(top, #e6e6e6, #ffffff);
  background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#e6e6e6), to(#ffffff));
  background-image: -webkit-linear-gradient(top, #e6e6e6, #ffffff);
  background-image: -o-linear-gradient(top, #e6e6e6, #ffffff);
  background-image: linear-gradient(top, #e6e6e6, #ffffff);
 ...