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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <h1>With Vanilla JavaScript</h1>
<div class="toggle">
  <button>Toggle SlideIn</button>
</div>

<!-- Slide In box will be hidden until toggled open -->
<div class="slidein">
  <h1>Header</h1>
  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Incidunt cum, harum, quaerat porro, maiores facilis molestias illum impedit quo repellat enim provident perspiciatis molestiae in saepe id cupiditate eveniet asperiores.</p>
  <button class="close-btn"> X </button>
</div>
              
            
!

CSS

              
                /* Make slide in box hidden off screen with fixed positioning 100% to the right */
.slidein {
  max-width: 600px;
  padding: 2em 3em; 
  position: fixed; 
  z-index: 100;
  top: 0;
  right: -100%;
  background: #ddd;
  height: 100%;
  box-shadow: 1px 1px 10px rgba(0,0,0,.5);
  transition: all .5s ease-in-out; 
}

/* Set positioning back to 0 when toggled opened */
.open {
  right: 0; 
}

/* add a close button in case toggle button is hidden on smaller screens */
.close-btn {
  border: none; 
  font-weight: bold; 
  font-size: 2em; 
  background: transparent; 
  position: absolute; 
  top: 0;
  left: 0;
  padding: .5em;
}

/* General styles unrelated to slide in */
body {
  font-family: 'Mulish', sans-serif;
}

.toggle {
  margin: 1em;
}

button {
  padding: .5em 1em;
  border-radius: 3em;
  font-size: 1.1em;
}

h1 {
  font-weight: 200;
}
              
            
!

JS

              
                /* Code to toggle the slide in box state to open or closed. Opened state has 'open' class */

let btn = document.querySelector('button');
let slidein = document.querySelector('.slidein');
let closeBtn = document.querySelector('.close-btn');

btn.addEventListener('click', function() {
  slidein.classList.toggle('open');
});
closeBtn.addEventListener('click', function() {
  slidein.classList.toggle('open');
});
              
            
!
999px

Console