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 id="root"></div>

<button 
  class="btn btn-primary btn__first" 
  data-toggle="collapse"
  data-target=".collapse.first"
  data-text="Collapse"
  >
  Toggle First
</button>
<button 
  class="btn btn-primary btn__first" 
  data-toggle="collapse"
  data-target=".collapse.second"
  data-text="Collapse"
  >
  Toggle Second
</button>
<button 
  class="btn btn-primary btn__first" 
  data-toggle="collapse"
  data-target=".collapse"
  data-text="Collapse"
  >
  Toggle All
</button>

<div class="block collapse first">
  <div class="block__content">
    I'm the first content!
  </div>
</div>
<div class="block collapse second">
  <div class="block__content">
    I'm the second content!
  </div>
</div>

              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Encode+Sans+Expanded');

html,body {
  font-family: 'Encode Sans Expanded', sans-serif; 
  height: 100%;
  margin: 15px;
}

*, ::after, ::before {
    box-sizing: border-box;
}

.collapse {
  display: block;
  max-height: 0px;
  overflow: hidden;
  transition: max-height .5s cubic-bezier(0, 1, 0, 1);; 

  &.show {
    max-height: 99em;
    transition: max-height .5s ease-in-out;
  }
}

.block {
  margin-top: 10px;
  background: #f5f5f5;
  padding: 0;
  // height: 250px;
  
  &__content {
    border: 1px solid #ccc;
    padding: 1.5em;
    height: 100%;
  }
}
              
            
!

JS

              
                
// Handler that uses various data-* attributes to trigger
// specific actions, mimicing bootstraps attributes
const triggers = Array.from(document.querySelectorAll('[data-toggle="collapse"]'));

window.addEventListener('click', (ev) => {
  const elm = ev.target;
  if (triggers.includes(elm)) {
    const selector = elm.getAttribute('data-target');
    collapse(selector, 'toggle');
  }
}, false);


const fnmap = {
  'toggle': 'toggle',
  'show': 'add',
  'hide': 'remove'
};
const collapse = (selector, cmd) => {
  const targets = Array.from(document.querySelectorAll(selector));
  targets.forEach(target => {
    target.classList[fnmap[cmd]]('show');
  });
}
              
            
!
999px

Console