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">
  <div class="toggle-handle">
    <div class="crater crater-one"></div>
    <div class="crater crater-two"></div>
    <div class="crater crater-three"></div>
  </div>
  <img class="mini-cloud" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/480623/toggle_cloud.png">
  <div class="star star-medium star-one"></div>
  <div class="star star-large star-two"></div>
  <div class="star star-small star-three"></div>
  <div class="star star-small star-four"></div>
  <div class="star star-medium star-five"></div>
  <div class="star star-large star-six"></div>
  <div class="star star-medium star-seven"></div>
</div>
              
            
!

CSS

              
                $height: 140px;
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
body {
  background: #222;
  transition: background .5s ease 0s;
}
.toggle-container {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  margin: auto;
  width: $height * 2;
  height: $height;
  background: #3C4145;
  border-radius: $height/2;
  border: ($height * .07143) solid #1C1C1C;
  overflow: hidden;
  cursor: pointer;
  transition: border-color .5s ease 0s, background .5s ease 0s;
  .toggle-handle {
    position: absolute;
    height: $height * .7857;
    width: $height * .7857;
    left: $height * .042857;
    top: 0;
    bottom: 0;
    margin: auto;
    border-radius: 50%;
    background: #FFFFFF;
    border: ($height * .07143) solid #E4E9C8;
    box-shadow: 0px 0px 20px rgba(228, 233, 200, .5);
    z-index: 999;
    transition: left .5s ease 0s, background .5s ease 0s, border-color .5s ease 0s, transform .5s ease 0s;
    .crater {
      position: absolute;
      border: ($height * .07143) solid #E4E9C8;
      border-radius: 50%;
    }
    .crater-one {
      top: 10%;
      left: 3%;
      height: 40%;
      width: 40%;
    }
    .crater-two {
      right: 6%;
      top: 6%;
    }
    .crater-three {
      right: 24%;
      bottom: 10%;
      height: 30%;
      width: 30%;
    }
  }
  .mini-cloud {
    height: 40%;
    width: auto;
    position: absolute;
    left: 20%;
    top: 38%;
    opacity: 0;
    z-index: 999;
    transition: opacity .25s ease 0s, left .5s ease 0s;
  }
  .star {
    position: absolute;
    background: #FFFFFF;
    opacity: 1;
    border-radius: 50%;
    transform: scale(1);
    transition: transform .5s ease;
  }
  .star-small {
    $smallStar: 4%;
    height: $smallStar;
    width: $smallStar/2;
  }
  .star-medium {
    $mediumStar: 6%;
    height: $mediumStar;
    width: $mediumStar/2;
  }
  .star-large {
    $largeStar: 8%;
    height: $largeStar;
    width: $largeStar/2;
  }
  .star-one {
    top: 12%;
    left: 45%;
    transition-delay: .4s;
  }
  .star-two {
    top: 72%;
    left: 50%;
    transition-delay: .35s;
  }
  .star-three {
    top: 30%;
    left: 62%;
    transition-delay: .3s;
  }
  .star-four {
    top: 56%;
    left: 68%;
    transition-delay: .25s;
  }
  .star-five {
    top: 8%;
    left: 76%;
    transition-delay: .2s;
  }
  .star-six {
    top: 40%;
    left: 86%;
    transition-delay: .15s;
  }
  .star-seven {
    top: 70%;
    left: 82%;
    transition-delay: .1s;
  }
}
.toggle-handle-day {
    left: ($height * 2) * .516 !important;
    background: #FFE06E !important;
    border-color: #E2C448 !important;
    transform: rotate(90deg);
  }
.toggle-container-day {
    background: #9FE4FC;
    border-color: #86C4D8;
  }
.off {
  background: #FAFAFA !important;
  transition: background .5s ease 0s;
}
.star-day {
  opacity: 0 !important;
  transform: scale(0) !important;
}
.crater-day {
  width: 0% !important;
  height: 0% !important;
  border: 0px solid transparent !important;
  transition: height .5s ease 0s, width .5s ease 0s, border .5s ease 0s;
}
.cloud-day {
  opacity: 1 !important;
  left: 40% !important;
}
              
            
!

JS

              
                var darkSide = new Audio();
darkSide.src = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/480623/vadar_breathing.mp3";

var lightSide = new Audio();
lightSide.src = "https://s3-us-west-2.amazonaws.com/s.cdpn.io/480623/yoda_use_the_force.mp3";

var clickCount = 0;

$('.toggle-container').on('click', function(){
  $('.toggle-handle').toggleClass('toggle-handle-day');
  $('body').toggleClass('off');
  $('.toggle-container').toggleClass('toggle-container-day');
  $('.star').toggleClass('star-day');
  $('.crater').toggleClass('crater-day');
  $('.mini-cloud').toggleClass('cloud-day');
  if (clickCount === 0){
    clickCount++;
    darkSide.pause();
    lightSide.play();
    return darkSide.currentTime = 0;
  } else if (clickCount === 1){
    clickCount--;
    lightSide.pause();
    darkSide.play();
    return lightSide.currentTime = 0;
  }
});
              
            
!
999px

Console