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

              
                <ul>
  <li>
    <a href="#" class="expand">click</a>
    <div class="content">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Placeat accusamus sequi eum commodi sint consequatur magni magnam non culpa laborum aperiam voluptatem velit dolore cupiditate tempore. Quibusdam unde voluptas eveniet. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Exercitationem laudantium laboriosam distinctio numquam corrupti eius eum inventore voluptas. Saepe temporibus nemo nobis deserunt ipsa id at mollitia magnam iusto eos?</p>  
    </div>
  </li>
  
    <li>
    <a href="#" class="expand">click</a>
    <div class="content">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Placeat accu</p>  
    </div>
  </li>
</ul>
              
            
!

CSS

              
                @import "compass/css3";

.content {
  width: 0;
  height: 0;
  overflow: hidden;
  transition: height ease 0.5s;
}

.is-visible + .content {
  width: auto;
}

ul {
 list-style: none;
  
  a {
   text-transform: uppercase;
   text-decoration: none;
  }
}
              
            
!

JS

              
                var expand = document.querySelectorAll( '.expand' ),
    expandCount = expand.length,
    content = null,
    parent = null,
    parentWidth = 0;

for (var i = 0; i < expandCount; i++) {
  expand[i].onclick = function(e) {
    e.preventDefault();
    
    parent = this.parentNode;
    parentWidth = parent.offsetWidth;

    content = parent.querySelectorAll( '.content' )[0];
    
    // Calculate width of element to animate height
    var newHeight = getHeight( content, parent );
   
    content.style.height = newHeight + "px";
    
    if( !hasClass(this, 'is-visible') ) {
      addClass( this, 'is-visible' );
    } else {
      removeClass( this, 'is-visible' );
      content.style.height = "0px";
    }
  };
} 

function removeClass(elem, className) {
    var newClass = ' ' + elem.className.replace( /[\t\r\n]/g, ' ') + ' ';
    if (hasClass(elem, className)) {
        while (newClass.indexOf(' ' + className + ' ') >= 0 ) {
            newClass = newClass.replace(' ' + className + ' ', ' ');
        }
        elem.className = newClass.replace(/^\s+|\s+$/g, '');
    }
}

function addClass(elem, className) {
    if (!hasClass(elem, className)) {
        elem.className += ' ' + className;
    }
}

function hasClass(elem, className) {
    return new RegExp(' ' + className + ' ').test(' ' + elem.className + ' ');
}

function getHeight( el, parent ) {
  var newEl = document.createElement('p'),
      height = 0;
  newEl.innerHTML = el.innerHTML;
  newEl.setAttribute('id', 'test-height');
  
  parent.appendChild( newEl );
  
  height = document.getElementById( 'test-height' ).offsetHeight;
  
  parent.removeChild( document.getElementById('test-height') );
  return height;
}
              
            
!
999px

Console