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="disclosure" data-disclosure>
  <template data-disclosure-trigger-template>
    <button aria-expanded="false">Show/hide content</button>
  </template>
  <div class="disclosure__content" data-disclosure-content>
    <p>This is the collapsable/expandable content</p>
  </div>
</div>

<!-- Alternate, non PE-based approach: -->
<!-- <div class="disclosure" data-disclosure>
  <button aria-expanded="false" data-disclosure-trigger>Show/hide content</button>
  <div hidden class="disclosure__content" data-disclosure-content>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Neque, aliquid esse nisi ut atque velit!</p>
    <p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Omnis quisquam expedita cum, saepe veritatis nulla delectus obcaecati voluptatem nihil dolore hic in, atque eligendi doloremque ab iste repellat, tempora eum.</p>
  </div>
</div> -->
              
            
!

CSS

              
                /* Can handle toggled hiding in either CSS or JS (by toggling `hidden`).
The decision is sometimes arbitrary but I prefer CSS at the mo because it has more flexibility in hiding options. E.g. sometimes you’ll be animating so need to use CSS’s `visibility` because unlike hidden and display, it’s animatable.
If you are going the CSS route (which means creating a selector you wouldn’t need with the JS route), reuse the aria-expanded that’ll be on the button to DRY up the handling of different user experiences.
*/
[aria-expanded="false"] + .disclosure__content {
  visibility: hidden;
}
/* end of note */

input,
button {
  font-size: inherit;
  padding: 0.5em;
}

:root {
  font-size: 110%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}

              
            
!

JS

              
                const disclosure = document.querySelector("[data-disclosure]");
const btnTmpl = document.querySelector("[data-disclosure-trigger-template]");
const btnClone = btnTmpl.content.cloneNode(true);
const btn = btnClone.querySelector("button");
const disclosureContent = document.querySelector("[data-disclosure-content]");

btn.addEventListener("click", function () {
  let expanded = this.getAttribute("aria-expanded") === "true" || false;
  this.setAttribute("aria-expanded", !expanded);
});

disclosure.insertBefore(btnClone, disclosureContent);

// Alternate approach based on a "hidden" attribute on the content area// const disclosure = document.querySelector("[data-disclosure]");
// const triggerButton = document.querySelector("[data-disclosure-trigger]");
// const disclosureContent = document.querySelector("[data-disclosure-content]");
// disclosureContent.hidden = true;

// triggerButton.addEventListener("click", function () {
//   let expanded = this.getAttribute("aria-expanded") === "true" || false;
//   this.setAttribute("aria-expanded", !expanded);
//   disclosureContent.hidden = expanded ? true : false;
// });

              
            
!
999px

Console