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

              
                <section class="content">
  <div class="c-accordion">
    <div class="c-accordion--item">
      <div class="c-accordion--header">
        <span class="header_label">Item 1</span>
                <span class="arrow">
          <svg style="width:24px;height:24px" viewBox="0 0 24 24">
    <path d="M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z" />
</svg>
        </span>
      </div>
      <div class="c-accordion--content">
        <div class="content-area">
        <p>
      Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. </p>
        <p>
      Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. </p>
          </div>
      </div>
    </div>
    <div class="c-accordion--item">
      <div class="c-accordion--header">
        <span class="header_label">Item 2</span>
                <span class="arrow">
          <svg style="width:24px;height:24px" viewBox="0 0 24 24">
    <path d="M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z" />
</svg>
        </span>
      </div>
           <div class="c-accordion--content">
             <div class="content-area">
      <p>
      Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. </p>
             <p>
      Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. </p>
             <p>
      Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. </p>
             </div>
      </div>
    </div>
    <div class="c-accordion--item">
      <div class="c-accordion--header">
        <span class="header_label">Item 3</span>
        <span class="arrow">
          <svg style="width:24px;height:24px" viewBox="0 0 24 24">
    <path d="M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z" />
</svg>
        </span>
      </div>
           <div class="c-accordion--content">
             <div class="content-area">
      <p>
      Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. </p>
             <p>
      Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. </p>
             <p>
      Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. </p>
             </div>
      </div>
    </div>
    <div class="c-accordion--item disabled">
      <div class="c-accordion--header">
        <span class="header_label">Item 4</span>
        <span class="arrow">
          <svg style="width:24px;height:24px" viewBox="0 0 24 24">
    <path d="M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z" />
</svg>
        </span>
      </div>
           <div class="c-accordion--content">
             <div class="content-area">
      <p>
      Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. </p>
             <p>
      Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. </p>
             <p>
      Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. </p>
             </div>
      </div>
    </div>
  </div>
  
</section>


              
            
!

CSS

              
                // will figure out if text needs to be white or black based on your passed in color assignment
@function is-color-light($color) {
    @if (lightness($color) > 60) {
        @return true;
    }
    @else {
        @return false;
    }
}

// used in order to determine a hover color by mixing white with your color selection....see panel header hover
@function tint($color, $percent) {
    @return mix(white, $color, $percent);
}

// used in order to determine a hover color by mixing black with your color selection....change tint below to shade to see the difference
@function shade($color, $percent) {
    @return mix(black, $color, $percent);
}

$panel-color: #fff;
$panel-border-color: #f4f4f4;
$panel-disabled-color: #fafafa;


*{
  box-sizing: border-box;
}

html, body{
  background: whitesmoke;
  min-height: 100%;
  margin-top: 45px;
}

.content{
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 0 10px;
  margin-bottom: 45px;
}

.c-accordion{
  width: 100%; 
  margin: 5px 0;
 
  
  &--item{
    width: 100%;
    min-height: 42px;
    color:#3d3d3d;
    max-height: 10000px;
    transition: .5s ease;
    
    
    &:last-child{
      border-bottom: 1px solid $panel-border-color;
    }
    
     &.active{
    transition: 0.3s ease;
    border-bottom: 1px solid rgb(234, 234, 234);
       .c-accordion--header{
         background: $panel-color;
          @if is-color-light($panel-color) {
            color: #3d3d3d;
          }
          @else {
            color: white;
          }
         
         .arrow{
           transform: rotate(180deg);
           transition: .3s ease;
         }
         
       }
       
       .c-accordion--content{
         transition: .5s ease;
         max-height: 10000px;
         height: 100%;
       }

    }
    
      &.popout{
      box-shadow: rgba(0, 0, 0, 0.180392) 0px 5px 11px 0px, rgba(0, 0, 0, 0.14902) 0px 4px 15px 0px;
    transition: 0.3s ease;
    margin: 20px 0px;
    border-bottom: 1px solid rgb(234, 234, 234);
       .c-accordion--header{
         background: $panel-color;
          @if is-color-light($panel-color) {
            color: #3d3d3d;
          }
          @else {
            color: white;
          }
         
         .arrow{
           transform: rotate(180deg);
           transition: .3s ease;
         }
         
       }
       
       .c-accordion--content{
         transition: .5s ease;
         max-height: 10000px;
         height: 100%;
       }

    }
    
    &.disabled {
            border-left: 1px solid tint($panel-disabled-color, 20%);
            border-right: 1px solid tint($panel-disabled-color, 20%);
            border-top: 1px solid tint($panel-disabled-color, 20%);
            &:hover {
                cursor: not-allowed;
            }
            &:last-child {
                border-bottom: 1px solid tint($panel-disabled-color, 20%);
            }
            .c-accordion--header {
                background: $panel-disabled-color;
                border-bottom-color: $panel-disabled-color;
                pointer-events: none;
                font-style: italic;
              
                @if is-color-light($panel-disabled-color) {
                    color: #999999;
                }
                @else {
                    color: #bdbdbd;
                }
                .arrow {
                    svg {
                        @if is-color-light($panel-disabled-color) {
                            fill: #999999;
                        }
                        @else {
                            fill: #bdbdbd;
                        }
                    }
                }
            }
        }
  }
  
  &--header{
    min-height: 42px;
    padding: 1em;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    border-bottom: 1px solid $panel-border-color;
    font-weight: 600;
    background-color: $panel-color;
    @if is-color-light($panel-color) {
      color: #3d3d3d;
    }
    @else {
      color: #fff;
    }
    
    .arrow{ 
      transition: .1s ease;
        svg{
          @if is-color-light($panel-color) {
            fill: #3d3d3d;
          }
          @else {
            fill: #fff;
          }
        }
    }
    
    &:hover{
      background-color: tint($panel-color, 25%);
    }
  }
  
  &--content{
    max-height: 0;
    overflow: hidden;
    transition: .2s ease;
    padding: 0;
    font-size: 14px;
    background-color:#fff;
    
    .content-area{
      padding: 1em;
    }
  }

  
}



              
            
!

JS

              
                
function activatePanels(){
 
 var defaultOptions = {
   popout: true, // defaults the accordion to the popout styles instead of flat panels
   multiOpen: true // allows for multiple panels to be opened at a time instead of just one.
 };


var accordions = document.querySelectorAll('.c-accordion'), z;
  for (z = 0; z < accordions.length; z++) {

    var accordionItems = accordions[z].querySelectorAll('.c-accordion--item');
    var size = accordionItems.length, i;

    for (i = 0; i < size; i++) {
      var accordionItem = accordionItems[i];
      var trigger = accordionItem.firstElementChild;
      trigger.onclick = function () {
       
                // grabs the header items parent to add the active or popout class to the accordion item.
                var item = this.parentElement;

                if (defaultOptions.multiOpen == true) {

                    // checks to make sure the accordion item isnt disabled
                    if (!item.classList.contains('disabled')) {

                        // checks to see if the accordion is a popout or just a flat accordion with panels
                        if (defaultOptions.popout == true) {
                            item.classList.toggle("popout");
                        } else {
                            item.classList.toggle("active");
                        }

                    }

                } else {

                    // finds all accordions on the page
                    let accordions = document.querySelectorAll('.zc-accordion');
                    let x = 0;

                    // finds all items inside the acoordion
                    for (x; x < accordions.length; x++) {
                        accordionItems = accordions[x].querySelectorAll('.zc-accordion--item');
                        let size = accordionItems.length,
                            y;

                        // for loop through each item and remove the popout or active class before applying it to the new panel
                        for (y = 0; y < size; y++) {
                            accordionItem = accordionItems[y];
                            if (defaultOptions.popout == true) {
                                accordionItem.classList.remove("popout");
                            } else {
                                accordionItem.classList.remove("active");
                            }
                        }
                    }
                    // checks to make sure the accordion item isnt disabled
                    if (!item.classList.contains('disabled')) {

                        // checks to see if the accordion is a popout or just a flat accordion with panels
                        if (defaultOptions.popout == true) {
                            item.classList.toggle("popout");
                        } else {
                            item.classList.toggle("active");
                        }

                    }
                }
      }
    }
  }
}

activatePanels();
              
            
!
999px

Console