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="container">
  <div class="toggle-container red">
    <input class="toggle-input" type="checkbox">
    <div class="toggle-track">
      <div class="toggle-thumb lego-plate">
        <div class="lego-plate-top">
          <svg class="lego-plate-top-logo" viewBox="0 0 21 10">
            <use href="#lego-logo" />
          </svg>
        </div>
      </div>
    </div>
  </div>
  
  <div class="toggle-container blue">
    <input class="toggle-input" type="checkbox">
    <div class="toggle-track">
      <div class="toggle-thumb lego-plate">
        <div class="lego-plate-top">
          <svg class="lego-plate-top-logo" viewBox="0 0 21 10">
            <use href="#lego-logo" />
          </svg>
        </div>
      </div>
    </div>
  </div>
  
  <div class="toggle-container yellow">
    <input class="toggle-input" type="checkbox">
    <div class="toggle-track">
      <div class="toggle-thumb lego-plate">
        <div class="lego-plate-top">
          <svg class="lego-plate-top-logo" viewBox="0 0 21 10">
            <use href="#lego-logo" />
          </svg>
        </div>
      </div>
    </div>
  </div>

  <div class="toggle-container red round">
    <input class="toggle-input" type="checkbox">
    <div class="toggle-track">
      <div class="toggle-thumb lego-plate">
        <div class="lego-plate-top">
          <svg class="lego-plate-top-logo" viewBox="0 0 21 10">
            <use href="#lego-logo" />
          </svg>
        </div>
      </div>
    </div>
  </div>
  
  <div class="toggle-container blue round">
    <input class="toggle-input" type="checkbox">
    <div class="toggle-track">
      <div class="toggle-thumb lego-plate">
        <div class="lego-plate-top">
          <svg class="lego-plate-top-logo" viewBox="0 0 21 10">
            <use href="#lego-logo" />
          </svg>
        </div>
      </div>
    </div>
  </div>
  
  <div class="toggle-container yellow round">
    <input class="toggle-input" type="checkbox">
    <div class="toggle-track">
      <div class="toggle-thumb lego-plate">
        <div class="lego-plate-top">
          <svg class="lego-plate-top-logo" viewBox="0 0 21 10">
            <use href="#lego-logo" />
          </svg>
        </div>
      </div>
    </div>
  </div>

  <div class="checkbox-container red">
    <input class="checkbox-input" type="checkbox">
    <div class="checkbox-icon lego-plate">
      <div class="lego-plate-top">
        <svg class="lego-plate-top-logo" viewBox="0 0 21 10">
          <use href="#lego-logo" />
        </svg>
      </div>
    </div>
  </div>
  
  <div class="checkbox-container blue">
    <input class="checkbox-input" type="checkbox">
    <div class="checkbox-icon lego-plate">
      <div class="lego-plate-top">
        <svg class="lego-plate-top-logo" viewBox="0 0 21 10">
          <use href="#lego-logo" />
        </svg>
      </div>
    </div>
  </div>
  
  <div class="checkbox-container yellow">
    <input class="checkbox-input" type="checkbox">
    <div class="checkbox-icon lego-plate">
      <div class="lego-plate-top">
        <svg class="lego-plate-top-logo" viewBox="0 0 21 10">
          <use href="#lego-logo" />
        </svg>
      </div>
    </div>
  </div>

  <div class="radio-container red">
    <input class="radio-input" type="radio" name="a">
    <div class="radio-dot lego-plate">
      <div class="lego-plate-top">
        <svg class="lego-plate-top-logo" viewBox="0 0 21 10">
          <use href="#lego-logo" />
        </svg>
      </div>
    </div>
  </div>
  
  <div class="radio-container blue">
    <input class="radio-input" type="radio" name="a">
    <div class="radio-dot lego-plate">
      <div class="lego-plate-top">
        <svg class="lego-plate-top-logo" viewBox="0 0 21 10">
          <use href="#lego-logo" />
        </svg>
      </div>
    </div>
  </div>
  
  <div class="radio-container yellow">
    <input class="radio-input" type="radio" name="a">
    <div class="radio-dot lego-plate">
      <div class="lego-plate-top">
        <svg class="lego-plate-top-logo" viewBox="0 0 21 10">
          <use href="#lego-logo" />
        </svg>
      </div>
    </div>
  </div>
</div>

<svg style="position: absolute; width: 0; height: 0;" aria-hidden="true">
  <defs>
    <symbol id="lego-logo">
      <path d="M12.624 1.894c.188-.549.75-.833 1.207-.787.216.022.36.111.439.231s.156.361.044.81a.55.55 0 1 0 1.067.267c.163-.654.103-1.239-.196-1.689S14.413.057 13.941.01c-.914-.092-1.999.448-2.364 1.546l-.004.011L9.94 7.295C9.555 8.651 10.57 10 11.976 10c.971 0 1.818-.663 2.053-1.607l.803-3.221a.55.55 0 0 0-.534-.685h-1.1a.551.551 0 1 0 0 1.103h.396l-.632 2.536c-.113.454-.52.772-.986.772a1.02 1.02 0 0 1-.977-1.299l1.626-5.704zM2.883.093a.55.55 0 0 1 .4.669L1.254 8.897H3.85a.551.551 0 0 1 0 1.103H.55a.55.55 0 0 1-.433-.212.55.55 0 0 1-.1-.473l2.2-8.821a.55.55 0 0 1 .667-.401zm4.283.401A.55.55 0 0 1 7.7.076h2.75a.55.55 0 0 1 .55.551.55.55 0 0 1-.55.551H8.13l-.825 3.308h.945a.551.551 0 1 1 0 1.103H7.03l-.825 3.308H8.25a.551.551 0 0 1 0 1.103H5.5a.55.55 0 0 1-.534-.685l2.2-8.821zm11.682.685a1.05 1.05 0 0 0-1.019.798L16.43 7.589c-.166.665.336 1.309 1.019 1.309a1.05 1.05 0 0 0 1.019-.798l1.4-5.612c.166-.665-.336-1.309-1.019-1.309zm-2.086.53A2.15 2.15 0 0 1 18.848.076c1.399 0 2.426 1.318 2.086 2.679l-1.399 5.612A2.15 2.15 0 0 1 17.449 10c-1.399 0-2.426-1.318-2.086-2.679l1.399-5.612z" />
    </symbol>
  </defs>
</svg>
              
            
!

CSS

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

body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

.container {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  grid-auto-flow: column;
  justify-items: center;
  align-content: center;
  gap: 1em 2em;
}

.toggle-container,
.checkbox-container,
.radio-container {
  --inactive-color: #a0a5a9;
  position: relative;

  &.toggle-container {
    width: em(50px);
  }

  &.radio-container {
    border-radius: 50%;
  }

  &.round {
    border-radius: em(50px);
  }

  &.red {
    --active-color: #c91a09;
  }

  &.blue {
    --active-color: #0055bf;
  }

  &.yellow {
    --active-color: #f2cd37;
  }
}

.toggle-input,
.checkbox-input,
.radio-input {
  position: absolute;
  z-index: 1;
  inset: 0;
  border-radius: inherit;
  cursor: pointer;
}

.toggle-track {
  --color: var(--inactive-color);
  border-radius: inherit;
  width: 100%;
  height: 100%;
  background-color: var(--color);
  box-shadow: inset 0 em(1px) em(2px) rgb(0 0 0 / .2);
  transition-property: background-color;
  transition-duration: .2s;
  transition-timing-function: linear;

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

.lego-plate {
  $size: em(25px);
  position: relative;
  width: $size;
  height: $size;
  background-color: var(--color);
  box-shadow: (
    inset em(1px) em(1px) rgba(255 255 255 / .3),
    inset em(-1px) em(-1px) rgba(0 0 0 / .3),
  );
  transition-property: background-color, transform;
  transition-duration: .2s, .4s;
  transition-timing-function: linear, ease-in-out;

  .toggle-container.round &,
  &.radio-dot {
    border-radius: 50%;
  }
    
  .toggle-input:checked + .toggle-track > &.toggle-thumb {
    transform: translateX(100%);
  }
  
  .checkbox-container &,
  .radio-container & {
    --color: var(--inactive-color);
  }
  
  .checkbox-input:checked + &,
  .radio-input:checked + & {
    --color: var(--active-color);
  }
}

.lego-plate-top {
  $size: em(15px);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  width: $size;
  height: $size;
  background-color: var(--color);
  box-shadow: (
    inset em(1px) em(1px) rgba(255 255 255 / .3),
    inset em(-1px) em(-1px) rgba(0 0 0 / .3),
  );
  transition-property: background-color;
  transition-duration: .2s;
  transition-timing-function: linear;
}

.lego-plate-top-logo {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: em(10px);
  fill: rgb(255 255 255 / .4);
}
              
            
!

JS

              
                
              
            
!
999px

Console