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

              
                .container
	h1 Accoridon 1
	ul.accordion
		li.accordion__item
			.accordion__header Accordion item 1
			.accordion__content 
				h2 Accordion item 1 content
				p Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias pariatur, culpa, accusamus quibusdam quaerat consequatur consequuntur quo, tempore nihil dolorem hic iure itaque repellat! Odit iste quos repudiandae, pariatur officia!

		li.accordion__item.accordion__item_active
			.accordion__header Accordion item 2
			.accordion__content
				h2 Accordion item 2 content
				p This accordion section open at page load by giving class .b-accordion__item_active
				p Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias pariatur, culpa, accusamus quibusdam quaerat consequatur consequuntur quo, tempore nihil dolorem hic iure itaque repellat! Odit iste quos repudiandae, pariatur officia!

		li.accordion__item
			.accordion__header Accordion item 3
			.accordion__content
				h2 Accordion item 3 content
				p Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias pariatur, culpa, accusamus quibusdam quaerat consequatur consequuntur quo, tempore nihil dolorem hic iure itaque repellat! Odit iste quos repudiandae, pariatur officia!

		li.accordion__item
			.accordion__header Accordion item 4
			.accordion__content
				h2 Accordion item 4 content
				p Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias pariatur, culpa, accusamus quibusdam quaerat consequatur consequuntur quo, tempore nihil dolorem hic iure itaque repellat! Odit iste quos repudiandae, pariatur officia!

		li.accordion__item
			.accordion__header Accordion item 5
			.accordion__content
				h2 Accordion item 5 content
				p Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias pariatur, culpa, accusamus quibusdam quaerat consequatur consequuntur quo, tempore nihil dolorem hic iure itaque repellat! Odit iste quos repudiandae, pariatur officia!
	
	h1 Accoridon 2
	ul.accordion
		li.accordion__item
			.accordion__header Accordion item 1
			.accordion__content 
				h2 Accordion item 1 content
				p Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias pariatur, culpa, accusamus quibusdam quaerat consequatur consequuntur quo, tempore nihil dolorem hic iure itaque repellat! Odit iste quos repudiandae, pariatur officia!

		li.accordion__item
			.accordion__header Accordion item 2
			.accordion__content
				h2 Accordion item 2 content
				p This accordion section open at page load by giving class .b-accordion__item_active
				p Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias pariatur, culpa, accusamus quibusdam quaerat consequatur consequuntur quo, tempore nihil dolorem hic iure itaque repellat! Odit iste quos repudiandae, pariatur officia!

		li.accordion__item
			.accordion__header Accordion item 3
			.accordion__content
				h2 Accordion item 3 content
				p Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias pariatur, culpa, accusamus quibusdam quaerat consequatur consequuntur quo, tempore nihil dolorem hic iure itaque repellat! Odit iste quos repudiandae, pariatur officia!

		li.accordion__item
			.accordion__header Accordion item 4
			.accordion__content
				h2 Accordion item 4 content
				p Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias pariatur, culpa, accusamus quibusdam quaerat consequatur consequuntur quo, tempore nihil dolorem hic iure itaque repellat! Odit iste quos repudiandae, pariatur officia!

		li.accordion__item
			.accordion__header Accordion item 5
			.accordion__content
				h2 Accordion item 5 content
				p Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias pariatur, culpa, accusamus quibusdam quaerat consequatur consequuntur quo, tempore nihil dolorem hic iure itaque repellat! Odit iste quos repudiandae, pariatur officia!
              
            
!

CSS

              
                body
	font-family 'Open Sans', sans-serif

.container
	max-width 800px
	margin auto

.accordion
	margin 1em 0
	padding 0
	&__item
		padding 0
		list-style none
		margin-bottom -1px

	&__header
		position relative
		color #3d3d3d
		font-size 18px
		line-height 20px
		padding 15px 50px 15px 20px
		background-color #fff
		border 1px solid #ccc
		cursor pointer
		transition 150ms all ease-in-out 0s
		&:hover
			box-shadow 0 1px 5px rgba(22, 20, 17, 0.16)

		&:after
			content ''
			transition 150ms all ease-in-out 0s
			position absolute
			right 20px
			top 19px
			color #535353
			width 6px
			height 6px
			border-style solid
			border-width 0 1px 1px 0
			border-color #535353
			transform rotate(45deg)
			transform-origin 70% 70%

	&__content
		display none
		overflow hidden

	&__item_active &__header
		box-shadow 0 1px 5px rgba(22, 20, 17, 0.16)

	&__item_active &__header:after
		transform rotate(225deg)
	
	&__item_active &__content
		display block
		padding 20px 10px
              
            
!

JS

              
                'use strict';

(function () {
	
	document.addEventListener('DOMContentLoaded', function () {
		var allAccordions = document.querySelectorAll('.accordion');
		var animationDuration = 200;
		
		function open (item) {
			var content = item.querySelector('.accordion__content');
			
			item.classList.add('accordion__item_active');
			Velocity(content, 'slideDown', { duration: animationDuration });
		};
		
		function close (item) {
			var content = item.querySelector('.accordion__content');
			
			item.classList.remove('accordion__item_active');
			Velocity(content, 'slideUp', { duration: animationDuration });
		};
		
		function getActive (allItems) {
			var active = false;
			
			for (var i = 0; i  < allItems.length; i++) {
				if (allItems[i].classList.contains('accordion__item_active')) {
					return allItems[i];
				}
			}
			return active;
		};
		
		// Every accordion on page
		for (var i = 0; i  < allAccordions.length; i++) {
			var accordion = allAccordions[i];
			var allItems = accordion.querySelectorAll('.accordion__item');
			var activeItem = getActive (allItems);
				
			accordion.addEventListener('click', function (e) {
				
				// click on header
				if (e.target.classList.contains('accordion__header')) {
					var header = e.target;
					var item = header.parentElement;

					if (item.classList.contains('accordion__item_active')) {
						close (item);
					}
					else {
						activeItem = getActive (allItems);

						if (typeof activeItem == "object") {
							close (activeItem);
						}
						open (item);
					}
				}
				
			});
			
		}
		
	});
	
}());
              
            
!
999px

Console