Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <div id="expandy-bit" class="z-depth-2">
  <a href="" class="expandy-control">
    <span>Click me to Expand/Close! </span> 
    <span class="fa fa-chevron-right expand-arrow"></span></a>
  <div id="content">
    <div class="actions">
      <button class="btn add-stuff"><span class="fa fa-plus"></span> Add Stuff</button>
      <button class="btn remove-stuff"><span class="fa fa-minus"></span> Remove Stuff</button>
    <div class="stuff">
        <!-- This is where the new elements will be added -->
              body {
  margin-top: 50px;

#expandy-bit {
  width: 350px;
  margin: auto;
  padding: 1rem;

.expandy-control {
  display: flex;
  justify-content: space-between;
  padding: 1rem 2rem;

.expand-arrow {
  text-align: right;

.stuff {
  padding-top: 2rem;

.actions {
  display: flex;
  justify-content: space-around;

#content {
  height: 0px;
  overflow: hidden;
  transition: height 300ms;

.thing {
  padding: 2rem;
  border: 1px solid lightgrey;
  margin-bottom: 1rem;

              const content = document.getElementById('content')
const expander = document.getElementsByClassName('expandy-control')[0]
const expandArrow = document.getElementsByClassName('expand-arrow')[0]
const addBtn = document.getElementsByClassName('add-stuff')[0]
const removeBtn = document.getElementsByClassName('remove-stuff')[0]
const stuffContainer = document.getElementsByClassName('stuff')[0]

//state of the expandable bit
let expandedState = false
//holds the dynamically added elements
const stuff = []
//store the height of the stuff container
let stuffContainerHeight = 66

expander.addEventListener('click', evt => {

  expandedState = !expandedState;
  if(expandedState) {
    content.style.height = stuffContainerHeight + 'px'
    expandArrow.classList.replace('fa-chevron-right', 'fa-chevron-down')
    //change the height to 'auto' after the transition is complete
    setTimeout(() => content.style.height = 'auto', 301)
  } else {
    //change height back to specific before collapsing so transition will work
    content.style.height = stuffContainerHeight + 'px'
    expandArrow.classList.replace('fa-chevron-down', 'fa-chevron-right')
    //set height back to 0 after sleight delay to allow for the above specific height change to be implemented
    setTimeout(() => content.style.height = '0', 10)

//dynamically add a new thing
addBtn.addEventListener('click', evt => {
  const newStuff = document.createElement('div')
  newStuff.className = 'thing'
  newStuff.appendChild(document.createTextNode("New Stuff"))
  //add the new element to the stuff array so we can remove it easily
  //store the new container height
  stuffContainerHeight = stuffContainer.offsetHeight

removeBtn.addEventListener('click', () => {
  //remove the last thing
  if(stuff.length > 0) {
  // store the new height
  stuffContainerHeight = stuffContainer.offsetHeight

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.