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

              
                <div class="c-accordion js-accordion">
  <div class="c-accordion__header" data-active="js-accordion">My Accordion Component</div>
  <div class="c-accordion__content-wrapper">
    <div class="c-accordion__content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce laoreet ultricies risus, sit amet congue nulla mollis et. Suspendisse bibendum eros sed sem facilisis ornare. Donec sit amet erat vel dui semper pretium facilisis eget nisi. Fusce consectetur vehicula libero vitae faucibus. Nullam sed orci leo. Fusce dapibus est velit, at maximus turpis iaculis in. Pellentesque ultricies ultrices nisl, eu consequat est molestie sit amet. Phasellus laoreet magna felis, ut vulputate justo tempor eu. Nam commodo aliquam vulputate.
    </div>
  </div>
</div>
              
            
!

CSS

              
                body {
  font-family:sans-serif;
}

.c-accordion__header {
  background-color:#ccc;
  padding:10px;
  cursor:pointer;
}

.c-accordion__content-wrapper {
  padding:10px;
}

.c-accordion__content {
  max-height:0;
  overflow:hidden;
  transition:max-height .5s;
}

.c-accordion.is-active .c-accordion__header {
  background-color:darken(#ccc, 25%);
}

.c-accordion.is-active .c-accordion__content {
  max-height:500px;
}
              
            
!

JS

              
                // Grab all elements with data-active attribute
var elems = document.querySelectorAll("[data-active]");

// Loop through if any are found
for(var i = 0; i < elems.length; i++){
	// Add event listeners to each one
	elems[i].addEventListener("click", function(e){

		// Prevent default action of element
		e.preventDefault();

		// Grab linked elements
		var linkedElement = document.querySelectorAll("." + this.getAttribute('data-active'));

		// Toggle linked element if present
		for(var i = 0; i < linkedElement.length; i++) {
			linkedElement[i].classList.toggle("is-active");
		}
		
	});    
}
              
            
!
999px

Console