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="wrapper">
  <section>
    <h2>Accordion with HTML/CSS</h2>
    <div class="accordion">
      <details>
        <summary>Section 1</summary>
        <p>This is the content for section 1.</p>
      </details>
      <details>
        <summary>Section 2</summary>
        <p>This is the content for section 2.</p>
      </details>
      <details>
        <summary>Section 3</summary>
        <p>This is the content for section 3.</p>
      </details>
    </div>
  </section>

  <section>
    <h2>Accordion with Javascript</h2>
    <div class="accordion">
      <div class="accordion-item">
        <div class="accordion-header">Section 1</div>
        <div class="accordion-content">
          <p>This is the content for section 1.</p>
        </div>
      </div>
      <div class="accordion-item">
        <div class="accordion-header">Section 2</div>
        <div class="accordion-content">
          <p>This is the content for section 2.</p>
        </div>
      </div>
      <div class="accordion-item">
        <div class="accordion-header">Section 3</div>
        <div class="accordion-content">
          <p>This is the content for section 3.</p>
        </div>
      </div>
    </div>
  </section>
</div>
              
            
!

CSS

              
                .wrapper {
  display: flex;
  gap: 10px;
}

section {
  width: 50%;
  border: 1px solid grey;
  padding: 50px;
}
@media screen and (max-width: 960px) {
  .wrapper {
    flex-direction: column;
  }
  section {
    width: calc(100% - 100px);
  }
}

/* html/css implementation */
.accordion {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
}

summary {
  padding: 15px;
  background-color: #f1f1f1;
  cursor: pointer;
  font-weight: bold;
  border: 1px solid #ccc;
  /* Remove the default arrow icon */
  list-style: none;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

details[open] summary {
  /* Add custom styling for open state */
  background-color: #e0e0e0;
}

details {
  border: 1px solid #ccc;
  margin-bottom: 5px;
}

details p {
  padding: 15px;
  background-color: #fff;
}

/* js implementation */
.accordion {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
}

.accordion-item {
  border: 1px solid #ccc;
  margin-bottom: 5px;
}

.accordion-header {
  padding: 15px;
  background-color: #f1f1f1;
  cursor: pointer;
  font-weight: bold;
}

.accordion-content {
  display: none;
  padding: 15px;
  background-color: #fff;
}

              
            
!

JS

              
                document.querySelectorAll(".accordion-header").forEach((header) => {
  header.addEventListener("click", () => {
    const content = header.nextElementSibling;
    content.style.display = content.style.display === "none" ? "block" : "none";
  });
});

              
            
!
999px

Console