Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

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.

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

              
                <label class="pill pill--pristine">
	<input type="checkbox" name="pill1" value="on">
</label>
              
            
!

CSS

              
                * {
  border: 0;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body, input {
  font: 1em/1.5 sans-serif;
}

body {
  background: #e3e4e8;
  display: grid;
  height: 100vh;
  place-items: center;
}

.pill {
  cursor: pointer;
  width: 7.5em;
  height: 3.75em;
}
.pill, .pill input[type=checkbox], .pill input[type=checkbox]:before, .pill input[type=checkbox]:after {
  display: block;
}
.pill, .pill input[type=checkbox] {
  -webkit-tap-highlight-color: transparent;
}
.pill input[type=checkbox] {
  animation-name: pillOff;
  background-attachment: fixed;
  background-image: linear-gradient(90deg, #da0b0b 50%, #09aa09 50%);
  border-radius: 1.875em;
  cursor: pointer;
  position: relative;
  width: 3.75em;
  height: inherit;
  transition: box-shadow 0.15s linear;
  -webkit-appearance: none;
  appearance: none;
}
.pill input[type=checkbox], .pill input[type=checkbox]:after {
  animation-duration: 0.6s;
  animation-timing-function: ease-in-out;
  animation-fill-mode: forwards;
}
.pill input[type=checkbox]:before, .pill input[type=checkbox]:after {
  content: "";
  position: absolute;
}
.pill input[type=checkbox]:before {
  background-image: radial-gradient(0.9375em 0.825em at 1.875em 1.125em, rgba(255, 255, 255, 0.27) 40%, rgba(255, 255, 255, 0) 50%);
  border-radius: inherit;
  box-shadow: 0.05em -0.025em 0.25em 0.05em rgba(255, 255, 255, 0.4) inset, 0.125em -0.125em 0.15em 0.25em rgba(255, 255, 255, 0.07) inset, 0 -0.75em 0.175em 0 rgba(0, 0, 0, 0.07) inset, 0 -0.65em 0.05em 0.45em rgba(255, 255, 255, 0.07) inset, 0 -0.375em 0.05em 0.45em rgba(255, 255, 255, 0.1) inset, 0 0.75em 0.75em 0 rgba(0, 0, 0, 0.27);
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
.pill input[type=checkbox]:after {
  animation-name: pillOffAfter;
  background-color: rgba(255, 255, 255, 0.27);
  border-radius: 0.2em;
  box-shadow: 0 0 0.1em 0.1em rgba(255, 255, 255, 0.27);
  top: 1.2em;
  left: 2.5em;
  width: 0.4em;
  height: 0.4em;
}
.pill input[type=checkbox]:checked {
  animation-name: pillOn;
}
.pill input[type=checkbox]:checked:after {
  animation-name: pillOnAfter;
}
.pill input[type=checkbox]:focus {
  outline: none;
}
.pill input[type=checkbox]:focus-visible {
  box-shadow: 0 0 0.5em #255ff4;
}
.pill--pristine input[type=checkbox], .pill--pristine input[type=checkbox]:after {
  animation: none;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  body {
    background: #2e3138;
  }

  .pill input[type=checkbox]:before {
    box-shadow: 0.05em -0.025em 0.25em 0.05em rgba(46, 49, 56, 0.4) inset, 0.125em -0.125em 0.15em 0.25em rgba(46, 49, 56, 0.07) inset, 0 -0.75em 0.175em 0 rgba(0, 0, 0, 0.07) inset, 0 -0.65em 0.05em 0.45em rgba(46, 49, 56, 0.07) inset, 0 -0.375em 0.05em 0.45em rgba(46, 49, 56, 0.1) inset, 0 0.75em 0.75em 0 rgba(0, 0, 0, 0.27);
  }
  .pill input[type=checkbox]:focus-visible {
    box-shadow: 0 0 0.5em #5583f6;
  }
}
/* Animation */
@keyframes pillOn {
  from {
    left: 0;
    width: 3.75em;
  }
  50% {
    left: 0;
    width: 7.5em;
  }
  to {
    left: 3.75em;
    width: 3.75em;
  }
}
@keyframes pillOnAfter {
  from {
    width: 0.4em;
  }
  50% {
    width: 4.15em;
  }
  to {
    width: 0.4em;
  }
}
@keyframes pillOff {
  from {
    left: 3.75em;
    width: 3.75em;
  }
  50% {
    left: 0;
    width: 7.5em;
  }
  to {
    left: 0;
    width: 3.75em;
  }
}
@keyframes pillOffAfter {
  from {
    width: 0.4em;
  }
  50% {
    width: 4.15em;
  }
  to {
    width: 0.4em;
  }
}
              
            
!

JS

              
                //Forked by https://codepen.io/jkantner/pen/QWEQXRN
document.querySelector('input[type="checkbox"]').addEventListener("change",e => {
		e.target.parentElement.classList.remove("pill--pristine");
});

              
            
!
999px

Console