Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <main>
  <h2>Scalable CSS Switches</h2>
  <h5>Change the size of each switch by editing the "font-size" property of each hr.</h5>
  <ul>
    <li>
      <input id="c1" type="checkbox">
      <label for="c1">
        <hr>
        Slide switch
      </label>
      <p>based on <a href="https://dribbble.com/shots/755717-Switch">https://dribbble.com/shots/755717-Switch</a></p>
    </li>
    <li>
      <input id="c2" type="checkbox">
      <label for="c2">
        <hr>
        Rocker switch
      </label>
      <p>based on <a href="https://dribbble.com/shots/55163-Rocker-switch">https://dribbble.com/shots/55163-Rocker-switch</a></p>
    </li>
    <li>
      <input id="c3" type="checkbox">
      <label for="c3">
        <hr>
        Button switch
      </label>
      <p>based on <a href="https://dribbble.com/shots/691868-Simple-Switch">https://dribbble.com/shots/691868-Simple-Switch</a></p>
    </li>
  </ul>
	<p>
		An original pen by <a href="https://codepen.io/ejsado/">Eric</a>.
	</p>
</main>

              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Open+Sans:400,700);
@import url(http://weloveiconfonts.com/api/?family=fontawesome);

body {
  font-family: "Open Sans", "Arial";
  background: #F2F2F2;
}
main {
  width: 300px;
  margin: 50px auto;
}
ul {
  list-style-type: none;
  padding: 0;
  margin: 0;
  display: block;
}
ul > li {
  padding: 30px;
  margin-left: -30px;
  margin-bottom: 20px;
}
li:nth-child(2) {
  background: #2E2E2E;
  color: #EEE;
  border-radius: 3px;
}
li:nth-child(2) a {
  color: #278BC4;
}
li:nth-child(2) a:visited {
  color: #8C6CB7;
}
input {
  display: none;
}
label {
  display: inline-block;
  font-size: 14px;
  cursor: pointer;
}
p {
  font-size: 9px;
}
hr {
  display: inline-block;
  margin: 0 20px 0 0;
  padding: 0;
  vertical-align: middle;
}

/* FRIST SWITCH */

/* bg */
label[for="c1"] hr {
  width: 4em;
  height: 1.75em;
  font-size: 20px; /* use this value to scale the switch */
  background: #BDBDBD;
  border: none;
  border-radius: 0.2em;
  box-shadow: inset 0 0 0.5em rgba(0,0,0,0.3);
  position: relative;
  color: #FFF;
  text-shadow: 0 0 0.1em rgba(0,0,0,0.3);
  overflow: hidden;
  font-family: 'FontAwesome', sans-serif;
  transition: all 300ms;
}
/* square and check */
label[for="c1"] hr::before {
  content: "\f00c";
  display: block;
  position: absolute;
  background: linear-gradient(to bottom, #FFF 0%, #EEE 100%);
  box-shadow: 0 0 0.2em rgba(0,0,0,0.2);
  width: 1.8em;
  height: 1.35em;
  margin: 0.2em;
  border-radius: 0.15em;
  text-indent: -1.5em;
  line-height: 1.3em;
  transition: all 300ms;
}
/* circle and x */
label[for="c1"] hr::after {
  content: "\f00d";
  display: block;
  position: absolute;
  background: linear-gradient(to top, #FFF 0%, #EEE 100%);
  width: 0.8em;
  height: 0.8em;
  margin: 0.5em 0.7em;
  border-radius: 50%;
  text-indent: 1.9em;
  line-height: 0.75em;
  transition: all 300ms;
}
#c1:checked + label[for="c1"] hr::before, #c1:checked + label[for="c1"] hr::after {
  transform: translateX(1.85em);
}
#c1:checked + label[for="c1"] hr {
  background: #79D122;
}

/* SECOND SWITCH */

/* bg */
label[for="c2"] hr {
  width: 5.6em;
  height: 1.5em;
  font-size: 20px; /* use this value to scale the switch */
  background: #111;
  border: solid 0.25em #1A1A1A;
  border-radius: 0.3em;
  box-shadow: inset 0 1px 0 0 rgba(0  ,0  ,0  ,0.1),
                    0 1px 0 0 rgba(255,255,255,0.1);
  position: relative;
  font-family: 'FontAwesome', sans-serif;
  transition: all 300ms;
}
/* left side */
label[for="c2"] hr::before {
  content: "\f00d";
  display: block;
  position: absolute;
  background: linear-gradient(to bottom, #363636 0%, #282828 100%);
  border-top: 1px solid rgba(255,255,255,0.2);
  width: 2.8em;
  height: 1.45em;
  border-radius: 0.15em 0 0 0.15em;
  line-height: 1.3em;
  text-indent: 1em;
  transform-origin: right top;
  transform: none;
  box-shadow: none;
  color: #278BC4;
  text-shadow: 0 0 0.4em rgba(39,139,196,0.5);
  transition: all 100ms;
}
/* right side */
label[for="c2"] hr::after {
  content: "\f00c";
  display: block;
  position: absolute;
  background: linear-gradient(210deg, #444 0%, #222 100%);
  border-top: 1px solid rgba(255,255,255,0.25);
  width: 2.8em;
  height: 1.45em;
  border-radius: 0 0.15em 0.15em 0;
  margin-left: 2.8em;
  line-height: 1.3em;
  text-indent: 0.95em;
  transform-origin: left top;
  transform: skew(0,-5deg) scale(0.95,1);
  box-shadow: 0.1em 0      0 -0.05em #111,
              0.2em 0      0 -0.1em  #111,
              0.3em 0.05em 0 -0.15em #111;
  color: #000;
  text-shadow: none;
  transition: all 100ms;
}
#c2:checked + label[for="c2"] hr::before{
  background: linear-gradient(150deg, #444 0%, #222 100%);
  border-top: 1px solid rgba(255,255,255,0.25);
  transform: skew(0,5deg) scale(0.95,1);
  box-shadow: -0.1em 0      0 -0.05em #111,
              -0.2em 0      0 -0.1em  #111,
              -0.3em 0.05em 0 -0.15em #111;
  color: #000;
  text-shadow: none;
}
#c2:checked + label[for="c2"] hr::after {
  background: linear-gradient(to bottom, #363636 0%, #282828 100%);
  border-top: 1px solid rgba(255,255,255,0.2);
  transform: none;
  box-shadow: none;
  color: #278BC4;
  text-shadow: 0 0 0.4em rgba(39,139,196,0.5);
}

/* THIRD SWITCH */

/* bg */
label[for="c3"] hr {
  font-size: 20px; /* use this value to scale the switch */
  margin-bottom: 0.5em;
  width: 3.4em;
  height: 3.4em;
  background: radial-gradient(circle cover at 50% 90%, rgba(0,0,0,0.07) 0%, rgba(255,255,255,0.2) 80%, rgba(255,255,255,0.3) 100%);
  border-radius: 50%;
  border: 0.3em solid #777;
  box-shadow: inset 0 0 0 0.1em rgba(0,0,0,0.08);
  transition: all 50ms;
}
/* circle */
label[for="c3"] hr::before {
  content: "";
  display: block;
  position: absolute;
  width: 4em;
  height: 4em;
  margin: -0.3em;
  position: relative;
  border-radius: 50%;
  border: none;
  box-shadow:       0 -0.2em 0.3em 0.3em rgba(255,255,255,0.3 ),
                    0  0.2em 0.3em 0.3em rgba(0  ,0  ,0  ,0.05),
              inset 0  0     0.2em 0     rgba(0  ,0  ,0  ,0.3 );
}
#c3:checked + label[for="c3"] hr {
  border-color: #CAEE00;
  background: radial-gradient(circle cover at 50% 10%, rgba(0,0,0,0.07) 0%, rgba(255,255,255,0.2) 80%, rgba(255,255,255,0.3) 100%);
  box-shadow: inset 0 0 0 0.1em rgba(177,209,0,0.5);
}

              
            
!

JS

              
                
              
            
!
999px

Console