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 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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console