cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div class="example-container">

  <div class="accordion">
    <h3 class="accordion__heading">
      <span class="accordion__heading__trigger">
        Accordion Heading
      </span>
    </h3>

    <div id="accordion_0" class="accordion__panel">
      <p>
        Spread kitty litter all over house flop over, or put toy mouse in food bowl run out of litter box at full speed chase ball of string. Lounge in doorway knock dish off table head butt cant eat out of my own dish lick sellotape throwup on your pillow sit in window and stare ooo, a bird! yum but meowwww. Purr when being pet stretch, for chase mice. This wonderful text provided by <a href="http://www.catipsum.com/">Cat Ipsum</a>.
      </p>
    </div>

    <h3 class="accordion__heading">
      <span class="accordion__heading__trigger">
        Accordion Heading 2
      </span>
    </h3>

    <div id="accordion_1" class="accordion__panel">
      <p>
        Spread kitty litter all over house flop over, or put toy mouse in food bowl run out of litter box at full speed chase ball of string. Lounge in doorway knock dish off table head butt cant eat out of my own dish lick sellotape throwup on your pillow sit in window and stare ooo, a bird! yum but meowwww. Purr when being pet stretch, for chase mice. This wonderful text provided by <a href="http://www.catipsum.com/">Cat Ipsum</a>
      </p>
    </div>
  </div>
  
</div> <!-- /.example-container -->
            
          
!
            
              /*
  demo styles
*/
*,
*:before,
*:after {
 box-sizing: border-box; 
}
body {
  font-family: arial;
  font-size: 1.05em;
  line-height: 1.4;
}
.example-container {
  margin: auto;
  max-width: 600px;
}

/*
  Accordion component styles
*/
.accordion {
  
  &__heading {
    border-bottom: 1px solid #333;
    margin: 0;
    
    &__trigger {
      cursor: pointer;
      display: block;
      font-size: 1.3em;
      font-weight: normal;
      padding: .25em 1.5em .25em .25em;
      position: relative;
      width: 100%;
      
      &:before,
      &:after {
        background: #000;
        bottom: 0;
        content: '';
        margin: auto;
        position: absolute;
        top: 0;
      }
      
      &:before {
        height: 20px;
        right: calc(.25em + 9px);
        transition: height .2s ease-in-out;
        width: 3px;
      }
      
      &:after {
        height: 3px;
        width: 21px;
        right: .25em;
      }
      
      &:hover,
      &:focus {
        background: darkBlue;
        color: #fff;
        
        &:before,
        &:after {
          background: #fff;
        }
      }
      
      &[aria-expanded="true"] {
        background: #000;
        color: #fff;
        
        &:before,
        &:after {
          background: #fff;
        }
        &:before {
          height: 0px;
        }
      }
    }
  }
  
  /*
    this panel should be visible to users if JavaScript were disabled for any reason, so as to keep the panel content from being inaccessible in said no-js situation.
  */
  .js &__panel {
    border-bottom: 1px solid;
    overflow: hidden;
    padding: 0 1em;
    max-height: 0px;
    transition:
      max-height .2s ease-in-out,
      visibility .2s ease-in-out;
    visibility: hidden;
    
    &.is-active { 
      max-height: 100vh;
      visibility: visible;
    }
   
  }
}
            
          
!
            
              var doc = document;
var trigger = doc.querySelectorAll('.accordion__heading__trigger');
var self;
var target;
var i;

// add 'js' class to <body> so the panels will only be hidden if JavaScript is enabled.
doc.getElementsByTagName('body')[0].classList.add('js');

// loop through accordion triggers
for ( i = 0; i < trigger.length; i++ ) {
  self = trigger[i];
  
  /*
    To simplify this example, instead of creating <button> elements and injecting them into the existing headings, we'll just convert the <span>s into ARIA buttons with the appropriate default attributes.
  */
  // revise role to be announced as a button
  self.setAttribute('role', 'button');  
  // panels are collapsed by default
  self.setAttribute('aria-expanded', 'false'); 
  // make the 'button' accessible to keyboard navigation
  self.tabIndex = 0; 
  // associate what panel the 'button' controls 
  // even though aria-controls is currently 'poop'
  // http://www.heydonworks.com/article/aria-controls-is-poop
  self.setAttribute('aria-controls', 'accordion_' + i); 
  
  
  /*
    when an accordion trigger is interacted with, update the aria-expanded value to articulate the panel's state.
    Also toggle the 'is-active' class on the panel itself, as that class is used to show/hide the panel.
  */
  self.addEventListener('click', function ( e ) {
    target = this.getAttribute('aria-controls');
    
    this.setAttribute('aria-expanded', e.target.getAttribute('aria-expanded') === 'true' ? 'false' : 'true');
    doc.getElementById(target).classList.toggle('is-active');
  });
  
  
  /*
    Since we're not using an actual button element for the triggers, the expected keyboard functionality needs to be remapped to the spans that are mascarading as buttons.
  */
  self.addEventListener('keydown', function ( e ) {
    var keyCode = e.keyCode || e.which;
    
    switch ( keyCode ) {
      case 32:
      case 13:
        e.preventDefault();
        e.target.click();
        
      default: 
        break;
    }
  });
}
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console