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

              
                <div class="toggle-container">
  <input class="toggle-input" type="checkbox">
  <svg class="toggle" viewBox="0 0 292 142" xmlns="http://www.w3.org/2000/svg">
    <path class="toggle-background" d="M71 142C31.7878 142 0 110.212 0 71C0 31.7878 31.7878 0 71 0C110.212 0 119 30 146 30C173 30 182 0 221 0C260 0 292 31.7878 292 71C292 110.212 260.212 142 221 142C181.788 142 173 112 146 112C119 112 110.212 142 71 142Z" />
    <rect class="toggle-icon on" x="64" y="39" width="12" height="64" rx="6" />
    <path class="toggle-icon off" fill-rule="evenodd" d="M221 91C232.046 91 241 82.0457 241 71C241 59.9543 232.046 51 221 51C209.954 51 201 59.9543 201 71C201 82.0457 209.954 91 221 91ZM221 103C238.673 103 253 88.6731 253 71C253 53.3269 238.673 39 221 39C203.327 39 189 53.3269 189 71C189 88.6731 203.327 103 221 103Z" />
    <g filter="url('#goo')">
      <rect class="toggle-circle-center" x="13" y="42" width="116" height="58" rx="29" fill="#fff"/>
      <rect class="toggle-circle left" x="14" y="14" width="114" height="114" rx="58" fill="#fff" />
      <rect class="toggle-circle right" x="164" y="14" width="114" height="114" rx="58" fill="#fff" />
    </g>
    <filter id="goo">
      <feGaussianBlur in="SourceGraphic" result="blur" stdDeviation="10" />
      <feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 18 -7" result="goo" />
    </filter>
  </svg>
</div>

<div class="toggle-container">
  <input class="toggle-input" type="checkbox" checked>
  <svg class="toggle" viewBox="0 0 292 142" xmlns="http://www.w3.org/2000/svg">
    <path class="toggle-background" d="M71 142C31.7878 142 0 110.212 0 71C0 31.7878 31.7878 0 71 0C110.212 0 119 30 146 30C173 30 182 0 221 0C260 0 292 31.7878 292 71C292 110.212 260.212 142 221 142C181.788 142 173 112 146 112C119 112 110.212 142 71 142Z" />
    <rect class="toggle-icon on" x="64" y="39" width="12" height="64" rx="6" />
    <path class="toggle-icon off" fill-rule="evenodd" d="M221 91C232.046 91 241 82.0457 241 71C241 59.9543 232.046 51 221 51C209.954 51 201 59.9543 201 71C201 82.0457 209.954 91 221 91ZM221 103C238.673 103 253 88.6731 253 71C253 53.3269 238.673 39 221 39C203.327 39 189 53.3269 189 71C189 88.6731 203.327 103 221 103Z" />
    <g filter="url('#goo')">
      <rect class="toggle-circle-center" x="13" y="42" width="116" height="58" rx="29" fill="#fff"/>
      <rect class="toggle-circle left" x="14" y="14" width="114" height="114" rx="58" fill="#fff" />
      <rect class="toggle-circle right" x="164" y="14" width="114" height="114" rx="58" fill="#fff" />
    </g>
    <filter id="goo">
      <feGaussianBlur in="SourceGraphic" result="blur" stdDeviation="10" />
      <feColorMatrix in="blur" mode="matrix" values="1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 18 -7" result="goo" />
    </filter>
  </svg>
</div>
              
            
!

CSS

              
                body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  font-size: 2em; // resize for demo
  gap: 1em;
}

@function em($pixels) {
  @if not (unit($pixels) == 'px') {
    @error 'Value #{$pixels} must have `px` unit.';
  }
  
  @return $pixels / 16px * 1em;
}

.toggle-container {
  --inactive-color: #d3d3d6;
  position: relative;
  aspect-ratio: 292 / 142;
  height: em(30px);
  
  &:nth-child(1) {
    --active-color: #35c759;
  }
  
  &:nth-child(2) {
    --active-color: #1868e3;
  }
}

.toggle-input {
  appearance: none;
  margin: 0;
  position: absolute;
  z-index: 1;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.toggle {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.toggle-background {
  fill: var(--inactive-color);
  transition: fill .4s;
  
  .toggle-input:checked + .toggle & {
    fill: var(--active-color);
  }
}

.toggle-circle-center {
  transform-origin: center;
  transition: transform .6s;

  .toggle-input:checked + .toggle & {
    transform: translateX(150px);
  }
}

.toggle-circle {
  transform-origin: center;
  backface-visibility: hidden;
  transition: transform .45s;
  
  &.left {
    transform: scale(1);
    
    .toggle-input:checked + .toggle & {
      transform: scale(0);
    }
  }
  
  &.right {
    transform: scale(0);
    
    .toggle-input:checked + .toggle & {
      transform: scale(1);
    }
  }
}

.toggle-icon {
  transition: fill .4s;

  &.on {
    fill: var(--inactive-color);

    .toggle-input:checked + .toggle & {
      fill: #fff;
    }
  }

  &.off {
    fill: #eaeaec;

    .toggle-input:checked + .toggle & {
      fill: var(--active-color);
    }
  }
}

// to do: absolute units for transform origins
              
            
!

JS

              
                
              
            
!
999px

Console