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

              
                <ul id="accordion" class="accordion">
  <li class="accordion__item">
    <span class="accordion__header">Question 1?</span>
    <div class="accordion__panel">
      <h3>Question 1?</h3>
      <ul class="accordion__body">
        <li>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris ligula elit, congue vel nulla ut, ullamcorper ullamcorper eros. Proin molestie viverra odio vitae euismod. In a diam quam. Pellentesque sit amet urna et libero sollicitudin interdum. Duis et tellus diam. Mauris tempus nec tortor maximus fringilla. Aenean ultricies quam id nunc posuere, ac iaculis dui tristique. Sed sit amet sem sed nulla sollicitudin vulputate tristique sit amet odio. Ut tempus, nulla eu tempor tempus, felis leo ultrices felis, vitae elementum ligula dui eu nisl. Aliquam dignissim mi orci, eu congue ipsum sollicitudin ut.
        </li>
      </ul>
    </div>
  </li>
  <li class="accordion__item">
    <span class="accordion__header">Question 2?</span>    
    <div class="accordion__panel">
      <h3>Question 2?</h3>
      <ul class="accordion__body">
        <li>Sed sed dolor accumsan, imperdiet elit in, egestas nisl. Curabitur faucibus purus felis, eu posuere libero rutrum vel. Phasellus eget mauris lacinia, commodo diam eu, fermentum nunc. Suspendisse potenti. Sed orci erat, tempor ac neque hendrerit, rhoncus sodales ante. Donec maximus iaculis vestibulum. In dictum consectetur ligula, in placerat sem varius in. Quisque ac justo felis. Aliquam semper rutrum auctor. Nunc a ipsum fermentum, molestie libero non, porta urna.
        </li>
      </ul>
    </div>
  </li>
  <li class="accordion__item">
    <span class="accordion__header">Question 3?</span>
    <div class="accordion__panel">
      <h3>Question 3?</h3>
      <ul class="accordion__body">
        <li>Nunc a urna libero. Morbi sit amet neque et purus viverra viverra vel sit amet nisl. Quisque eu orci nisl. Nunc varius dolor erat. Integer tellus eros, vestibulum in lobortis id, cursus feugiat ex. Suspendisse dapibus, metus at suscipit hendrerit, justo quam vestibulum est, vel tristique odio massa nec dui. Nunc convallis placerat laoreet. Maecenas nunc enim, pretium at elit eget, interdum fringilla purus. Pellentesque molestie libero vitae justo lacinia, at ornare lectus volutpat. Pellentesque ac posuere dui. Suspendisse aliquet lobortis viverra. In tincidunt vulputate nisl, et hendrerit dui fermentum non. Maecenas venenatis pellentesque arcu non maximus.
        </li>
      </ul>
    </div>
  </li>
</ul>
              
            
!

CSS

              
                .accordion {
  list-style: none;
  margin: 1rem;
  padding: 0;
  
  &__item {
    color: #6505cc;
    background: #eedbff;
    border: 1px solid;
    border-bottom: 0;
    
    &:last-child {
      border-bottom: 1px solid;
    }
  }
  
  &__header {
    display: block;
    position: relative;
    padding: 0.5rem 1rem;
    text-transform: uppercase;
    font-weight: bold;
    
    &::after {
      content: '';
      position: absolute;
      right: 1rem;
      width: 0px;
      height: 0px;
      border-left: 10px solid transparent;
      border-right: 10px solid transparent;
      border-top: 15px solid #6505cc;
    }
  }
  
  &__panel {
    padding: 1rem;
    border-top: 1px solid;
    
    h3 {
      margin-top: 0;
    }
  }
  
  &__body {
    list-style: none;
    padding: 0;
  }
}

.visually-hidden { 
    position: absolute !important;
    height: 1px; 
    width: 1px;
    overflow: hidden;
    clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
    clip: rect(1px, 1px, 1px, 1px);
    white-space: nowrap; /* added line */
}
              
            
!

JS

              
                const accordion = document.getElementById('accordion')

function toggleAccordion(e) {
  const pressButtonKeyCode = e.code === 'Enter' || e.code === 'Space' ? true: false;

  if (e.type === 'click' || pressButtonKeyCode) {
    this.nextElementSibling.classList.toggle('visually-hidden');  
  }
}

if (accordion) {
  const headers = document.querySelectorAll('.accordion__header')
  headers.forEach(header => {
    header.tabIndex = 0
    header.addEventListener('click', toggleAccordion)
    header.addEventListener('keypress', toggleAccordion)
  })
  
  const panels = document.querySelectorAll('.accordion__panel')
  panels.forEach(panel => panel.classList.add('visually-hidden'))
}
              
            
!
999px

Console