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

              
                <div class="widget-wrapper">
  <h2>Accordion Component</h2>
  <ul class="accordion">
    <li>
      <h3 class="accordion__header">
        <button aria-expanded="false" accordion-trigger>
          What is an accordion?
          <svg aria-hidden="true" focusable="false" viewBox="0 0 10 10">
            <rect class="vert" height="8" width="2" y="1" x="4"></rect>
            <rect height="2" width="8" y="4" x="1"></rect>
          </svg>
        </button>
      </h3>
      <div  hidden class="accordion__panel ">
        <p>An accordion is a useful component for hiding content when needed.
        </p>
      </div>
    </li>
    <li>
      <h3 class="accordion__header">
        <button aria-expanded="false" accordion-trigger>
          Can they be accessible?
          <svg aria-hidden="true" focusable="false" viewBox="0 0 10 10">
            <rect class="vert" height="8" width="2" y="1" x="4"></rect>
            <rect height="2" width="8" y="4" x="1"></rect>
          </svg>
        </button>
      </h3>
      <div hidden class="accordion__panel ">
        <p>Yes.
        </p>
      </div>
    </li>
    <li>
  <h3 class="accordion__header">
    <button aria-expanded="false" accordion-trigger>
      Checkout my post on A11y accordions.
      <svg aria-hidden="true" focusable="false" viewBox="0 0 10 10">
        <rect class="vert" height="8" width="2" y="1" x="4"></rect>
        <rect height="2" width="8" y="4" x="1"></rect>
      </svg>
    </button>
  </h3>
  <div hidden class="accordion__panel ">
    <p><a href="https://louiseclark.tech/postings/a11y-accordion?preview_id=928&preview_nonce=9cc04c1d02&preview=true&_thumbnail_id=984">Considering A11y with the Accordion Component</a>
    </p>
  </div>
</div>
</li>
  </ul> 
</div>
              
            
!

CSS

              
                body {
	background-color: dimgray;
	color: dimgray; 
	font-family: "NewsGothicBT-Roman", Helvetica, Arial, sans-serif;
	font-size: 1.5rem;  
  }

button svg {
	  height: 1em;
	  margin-left: 0.5em;
	  float: right;
  }

h2 {
	font-size: 3rem;
	text-align: center;
	margin: 0;
	padding: 1rem;
  }

  li {
	  list-style-type: none;
  }
  
  .widget-wrapper {
	background-color: #fff;
	padding: 2rem;
	margin: 0 auto;
	max-width: 1000px;
  }
  
  .accordion__header button {
	 all: inherit;
   width: 80%;  
	 margin: 0 auto;
	 padding: 1rem;
  }

  .accordion__header button:focus {
   outline: -webkit-focus-ring-color auto 5px;
  }

  .accordion__header button:hover, .accordion__header button:focus       {
    background: #f3fbfd;
   }

  .accordion__panel {
	  width: 80%;
	  margin: 0 auto;
  }
  
  [aria-expanded="true"] .vert {
   display: none;
  }
  
  [aria-expanded] rect {
   fill: currentColor;
  }
              
            
!

JS

              
                const accordionComponent = document.querySelector('.accordion');
accordionComponent.addEventListener('click', (event) => {
  accordion(event);
});

function accordion() {
  const btn = event.target.closest('[accordion-trigger]');
  const expanded = btn.getAttribute('aria-expanded') === 'true';
  const target = btn.parentNode.nextElementSibling;

  btn.setAttribute('aria-expanded', !expanded);
  target.hidden = expanded;
}
              
            
!
999px

Console