cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <section class="section section-switch">
  <div class="container switch-container">
    <div class="switch-list">
      <h2 class="title">Normal Switch with Text</h2>
      <label class="switch">
        <input type="checkbox" class="switch-input">
        <span class="switch-label" data-on="On" data-off="Off"></span>
        <span class="switch-handle"></span>
      </label>
      <label class="switch">
        <input type="checkbox" class="switch-input" checked>
        <span class="switch-label" data-on="On" data-off="Off"></span>
        <span class="switch-handle"></span>
      </label>
    </div>
    <div class="switch-list material">
      <h2 class="title">Material Switch</h2>
      <label class="switch-material">
        <input type="checkbox" id="unchecked" class="switch-material-input is-hidden"/>
        <label for="unchecked" class="switch-material-label"></label>
      </label>
    </div>
    <div class="switch-list mixin-checkbox">
      <h2 class="title">Toggle from mixin</h2>  
      <div class="switch-toggle">
        <input id="checkbox" type="checkbox">
        <label for="checkbox">
      <div>
    </div>
    </label>
  </div>
  </div>
</section>
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Josefin+Sans:300,400,400i,600,700');
//Color-palette
$black: #66615B;
$grey: #ccc;
$white: #fff;
$yellow: #ff0;
$green: #8bc34a;
$blue: #29d2e4;
$orange: #f87d09;
$dark-pink: #e91e63;
$purple: #9c27b0;
$light-purple: #efedff;
//Body
$main-background: $light-purple;
*,
:after,
:before {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font: normal 16px/1.2 'Josefin Sans', sans-serif;
  background: $main-background;
}

.title {
  font-weight: normal;
  margin: 0;
}

.section-switch {
  padding: 50px 0;
}

.switch-container {
  max-width: 300px;
  margin: 0 auto;
  .switch-list {
    margin: 50px 0;
    text-align: center;
    > .switch {
      display: block;
      margin: 20px auto;
    }
    .switch-material,
    .switch-toggle{
      display: inline-block;
      margin-top: 30px;
    }
  }
}

//Normal-Switch
.switch {
  position: relative;
  display: inline-block;
  vertical-align: middle;
  width: 70px;
  height: 25px;
  padding: 3px;
  border-radius: 18px;
  cursor: pointer;
}

.switch-input {
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
}

.switch-label {
  position: relative;
  display: block;
  height: inherit;
  font-size: 12px;
  text-transform: uppercase;
  background: #C81D25;
  border-radius: inherit;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.12), inset 0 0 2px rgba(0, 0, 0, 0.15);
  transition: 0.15s ease-out;
  transition-property: opacity background;
  &:before,
  &:after {
    position: absolute;
    top: 50%;
    margin-top: -.5em;
    line-height: 1.2;
    transition: inherit;
    color: #fff;
  }
  &:before {
    content: attr(data-off);
    right: 11px;
  }
  &:after {
    content: attr(data-on);
    left: 11px;
    opacity: 0;
  }
}

.switch-input {
  &:checked {
    ~ .switch-label {
      background: #4fb845;
      box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15), inset 0 0 3px rgba(0, 0, 0, 0.2);
      &:before {
        opacity: 0;
      }
      &:after {
        opacity: 1;
      }
    }
    ~ .switch-handle {
      left: 45px;
      box-shadow: -1px 1px 5px rgba(0, 0, 0, 0.2);
    }
  }
}

.switch-handle {
  position: absolute;
  top: 4px;
  left: 1px;
  width: 23px;
  height: 23px;
  background: white;
  border-radius: 50%;
  box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.2);
  background-image: linear-gradient(to bottom, white 40%, #f0f0f0);
  transition: left 0.15s ease-out;
  &:before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    margin: -6px 0 0 -6px;
    width: 12px;
    height: 12px;
    background: #f9f9f9;
    border-radius: 6px;
    box-shadow: inset 0 1px rgba(0, 0, 0, 0.02);
    background-image: linear-gradient(to bottom, #eeeeee, white);
  }
}

//Material-Switch
.switch-material-label {
  position: relative;
  display: inline-block;
  height: 20px;
  width: 44px;
  background: #898989;
  border-radius: 100px;
  cursor: pointer;
  transition: all 0.3s ease;
  &:after {
    position: absolute;
    left: -2px;
    top: -3px;
    display: block;
    width: 26px;
    height: 26px;
    border-radius: 100px;
    background: #fff;
    box-shadow: 0px 3px 3px rgba(0, 0, 0, 0.05);
    content: '';
    transition: all 0.3s ease;
  }
  &:active {
    &:after {
      transform: scale(1.15, 0.85);
    }
  }
}

.switch-material-input {
  &:checked {
    ~ label {
      background: #6fbeb5;
      &:after {
        left: 20px;
        background: #179588;
      }
    }
  }
  &:disabled {
    ~ label {
      background: #d5d5d5;
      pointer-events: none;
      &:after {
        background: #bcbdbc;
      }
    }
  }
  &.is-hidden {
    display: none;
  }
}

//Switch-Mixin
$switch-on: #8FDC5A; // #DC3522 Orange, #8FDC5A Green, #427CDC Blue
$switch-bg: #D9CB9E;
$switch-off: #DC3522;

@mixin switch-toggle($height,$switch-on,$switch-off) {
  margin: 0;
  padding: 0;
  input[type="checkbox"] {
    display: none;
    &:checked + label {
      border-color: $switch-on;
      background: $switch-on;
      box-shadow: inset 0 0 0 #{$height / 2} $switch-on;
    }
  }
  label {
    transition: all .2s ease-in-out;
    display: inline-block;
    position: relative;
    background: $switch-off;
    box-shadow: inset 0 0 0 0 $switch-on;
    div {
      transition: all .2s ease-in-out;
      background: white;
      width: $height;
      height: $height;
      border-radius: $height / 2;
    }
    &:hover,
    & > div:hover {
      cursor: pointer;
    }
  }
  @if $height >=15px {
    input[type="checkbox"]:checked + label > div {
      margin-left: $height - 4;
    }
    label {
      border: 2px solid $switch-off;
      border-radius: $height + 2;
      height: $height + 4;
      width: $height * 2;
    }
  }
  @else if $height < 15px {
    input[type="checkbox"]:checked + label > div {
      margin-left: $height - 2;
    }
    label {
      border: 1px solid $switch-off;
      border-radius: $height + 1;
      height: $height + 2;
      width: $height * 2;
    }
  }
}

.switch-toggle {
  @include switch-toggle(25px,$switch-on,$switch-off);
}
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console