Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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="accordion-wrapper">
  <!-- first accordion -->
  <div class="accordion-card">
    <h3 class="accordion-card__header">
      Header 1
      <span class="icon"> + </span>
    </h3>
    <p class="accordion-card__content">
      Lorem ipsum, dolor sit amet consectetur adipiscing elit. Et neque, velit
      quasi quos quia nulla omnis! Similique dolorum, veniam facilis aliquam est
      fuga aperiam voluptatibus, sapiente atque vitae quia accusamus.
    </p>
  </div>

  <!-- second accordion -->
  <div class="accordion-card">
    <h3 class="accordion-card__header">
      Header 2
      <span class="icon"> + </span>
    </h3>
    <p class="accordion-card__content">
      Lorem ipsum, dolor sit amet consectetur adipiscing elit. Et neque, velit
      quasi quos quia nulla omnis! Similique dolorum, veniam facilis aliquam est
      fuga aperiam voluptatibus, sapiente atque vitae quia accusamus.
    </p>
  </div>

  <!-- third accordion -->
  <div class="accordion-card">
    <h3 class="accordion-card__header">
      Header 3
      <span class="icon"> + </span>
    </h3>
    <p class="accordion-card__content">
      Lorem ipsum, dolor sit amet consectetur adipiscing elit. Et neque, velit
      quasi quos quia nulla omnis! Similique dolorum, veniam facilis aliquam est
      fuga aperiam voluptatibus, sapiente atque vitae quia accusamus.
    </p>
  </div>
</div>
              
            
!

CSS

              
                /* ! project styles */
.accordion-examples__heading {
  text-align: center;
}

/* accordion wrapper */
.accordion-wrapper {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin-top: 50px;
}

/* accordion card */
.accordion-card {
  width: 280px;
  border: double goldenrod;
  background-color: white;
}

/* accordion header */
.accordion-card__header {
  color: #202020;
  position: relative;
  padding: 10px;
  margin: 0;
}

/* icon */
.icon {
  position: absolute;
  right: 10px;
  color: goldenrod;
  transform: rotate(0deg);
  transition: transform 300ms, color 300ms;
}

/* accordion content */
.accordion-card__content {
  border-top: solid 1px goldenrod;
  padding: 10px;
  color: #3d3b3b;
  display: none;
  margin: 0;
}

/* javascript css classes to be added and removed */
.toggleIcon {
  transform: rotate(45deg);
  color: hsl(0, 70%, 50%);
}

.active {
  display: block;
}

              
            
!

JS

              
                // variables
const accordionBtnToggle = document.querySelectorAll(".accordion-card__header");

// Adding event listener to the accordion toggle button
for (i of accordionBtnToggle) {
  i.addEventListener("click", accordionToggleFunction);
}

// function to open an accordion
// function to open an accordion while closing the others
function accordionToggleFunction() {
  for (i of accordionBtnToggle) {
    i.nextElementSibling.style.display = "none";
    i.children[0].classList.remove("toggleIcon");
  }
  if (this.nextElementSibling.style.display == "none") {
    this.nextElementSibling.style.display = "block";
    this.children[0].classList.add("toggleIcon");
  }
}

              
            
!
999px

Console