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="flex justify-center items-center vh-100">
   <div class="element flex flex-wrap items-center">
      <div class="checkbox-wrap ">
         <input type="checkbox" class="toggle-switch">
      </div>
      <div class="opts">
         <div class="opt-1"><p>light mode</p></div>
         <div class="opt-2"><p>dark mode</p></div>
      </div>
   </div>
</div>
              
            
!

CSS

              
                $poppins: 'Poppins', sans-serif;
$background: #FAFAFC;
$shadow: 0 4px 12px -2px rgba(#6B75A1, .16);
$c-darkGray: #4a4a4e;
$ease: all 300ms cubic-bezier(0.68, -0.55, 0.265, 1.55);

body {
   font-family: $poppins;
   background: $background;
   color: $c-darkGray;
   transition: .2s all;
}
.dark {
   background: #181818;
}


.element {
   position: relative;
}

 input[type=checkbox].toggle-switch {
    transform: rotate(90deg);
    
    appearance: none;
    -moz-appearance: none;
    -webkit-appearance: none;
    outline: 0;
    cursor: pointer;
    
    // Since this is rotated 90deg 
    // height and width are reversed
    
    /* width of the track */
    width: 4em;
    /* height of the track */
    height: 1.5em;
    border-radius: 3em;
    background-color: #ebebeb;
    
    transition: background-color 0.09s ease-in-out;
    position: relative;
    
    &:active::after {
       background-color: #f2f2f2;
       padding-right: .8em;
   }
    
   &::after {
      content: '';
      /* toggle shape -- 
     height should equal width 
     to maintain circle */
      width: 2em; 
      height: 2em;
      background-color: white;
      border-radius: 3em;
      position: absolute;
      left: -5px;
      top: 50%;
      transform: translateY(-50%);
      transition: left .3s cubic-bezier(
          0.175, 0.885, 0.320, 1.275
        ),
        padding .3s ease, margin .3s ease;
      box-shadow: 2px 0px 5px 0 rgba(0,0,0,0.15);
   }
}

input[type=checkbox].toggle-switch:checked {
   background-color: #333;
   &:active::after {
      margin-left: -.8em;
   }
   &::after {
      // Location of toggle handle when checked
      // should equal ~ .5 of the width of
      // input[type=checkbox].toggle-switch
      left: 2em;
      background-color: #242424;
   }
}

.opts {
   color: gray;
}

.opt-1 {
   color: black;
}

.opt-1,
.opt-2 {
   transition: .2s all;
}

.active {
   .opt-1{
      color: gray;
   }
   .opt-2 {
      color: white;
   }
}

.checkbox-wrap {

}


              
            
!

JS

              
                $(document).ready(function() {
 
  $(".toggle-switch").on("click", function(event){
     $("body").toggleClass("dark");
     $("body").toggleClass("active");   
 });
});
              
            
!
999px

Console