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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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

              
                <!--
Default styling for lists is not overwritten, you can do that if you wish

This is the required markup with .accordion-title being a direct higher sibling to .accordion-content

More robust markup is totally feasible, this is just for an example
-->

<ul>
  <li class="accordion-title" id="title-1">
    <a href="#title-1" class="accordion-button">Title / heading #1</a>
  </li>
  <li class="accordion-content">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam in nibh eget augue tincidunt elementum nec vel tellus. Fusce vestibulum dictum leo, ac varius nisi sagittis vel. Aenean sed est id arcu adipiscing semper eu vel mi. In bibendum est sit amet
    urna gravida vel hendrerit sapien pharetra. <a href="#title-2" class="accordion-button">Go to title 2</a>
  </li>
  <li class="accordion-title" id="title-2">
    <a href="#title-2" class="accordion-button">Title / heading #2</a>
  </li>
  <li class="accordion-content">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam in nibh eget augue tincidunt elementum nec vel tellus. Fusce vestibulum dictum leo, ac varius nisi sagittis vel. Aenean sed est id arcu adipiscing semper eu vel mi. In bibendum est sit amet
    urna gravida vel hendrerit sapien pharetra.
    <ul>
      <li class="accordion-title" id="title-2-sub-1">
        <a href="#title-2" class="accordion-button">Title / heading #2</a>
      </li>
      <li class="accordion-content">
        Aenean sed est id arcu adipiscing semper eu vel mi. In bibendum est sit amet
    urna gravida vel hendrerit sapien pharetra.
      </li>
    </ul>
  </li>
  </ul>
              
            
!

CSS

              
                .accordion-title.on { /* insert style for on state */ }
.accordion-content {display:none; overflow:hidden;} /* Hide on page load, overflow:hidden is to keep things from hopping around */
.accordion-content.open {display:block;} /* allows to set one open on page load */
              
            
!

JS

              
                $(document).ready(function() { 
  $('.accordion-button').on('click', function() {
    
    var id = $(this).attr('href');
    
    // Remove any .on classes if there are any (for styling)
    $(id).parent().children('.accordion-title').removeClass('on');
    // If it's already open, close it (optional)
    $(id).parent().children('.accordion-content').slideUp('fast', function() {
      $(this).removeClass('open');  // Class you can use for styling
    });
    
    // If it's not open, open it and add appropriate classes (for styling)
    if($(id).next().is(':hidden')) {
      $(id).addClass('on');
      $(id).next().slideDown('fast').addClass('open');
    }
    
  });
});
              
            
!
999px

Console