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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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

              
                <!-- (Re)use the component using simple, resilient HTML. If JS doesn’t execute, the show still goes on. All JS and ARIA-related complexity hidden away. Easy to reuse. -->
<disclosure-widget label="system requirements">
  <!-- whatever content you want in here -->
  <h3>System requirements</h3>
  <p>You should be using the latest version of lorem ipsum dolor sit amet.</p>
</disclosure-widget>
              
            
!

CSS

              
                disclosure-widget {
  display: block;
  max-width: 60ch;
  border: 1px solid #ccc;
  padding: 1em;
}

/* unimportant styles */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
:root {
  font-family: system-ui;
}
body {
  padding: 10em;
  /*   display: grid;
  min-height: 100vh;
  width: 80ch;
  place-items: center; */
}
body * + * {
  margin-top: 1em;
}

              
            
!

JS

              
                // Prepare a <template> for upgrading our baseline HTML -->
let template = document.createElement("template");
template.innerHTML = `
  <style>[data-content] { margin-top: 1em; }</style> <!-- scoped styles! -->
  <button aria-expanded="false" data-trigger>Show/hide content</button>
  <div hidden data-content><slot></slot></div>
`;

// Our custom element class
export class DisclosureWidget extends HTMLElement {
  constructor() {
    super();

    // Attach a shadow root to the element.
    // This is better (perf, expectations) than via innerHTML.
    let shadowRoot = this.attachShadow({ mode: "open" });

    // Use our template as Shadow DOM
    shadowRoot.appendChild(template.content.cloneNode(true));
  }

  connectedCallback() {
    // Add the trigger button text and
    // prepare toggle functionality
    const trigger = document
      .querySelector("disclosure-widget")
      .shadowRoot.querySelector("[data-trigger]");
    trigger.textContent = `Show/hide ${this.getAttribute("label")}`;
    trigger.addEventListener("click", this.toggle);
  }

  toggle() {
    let expanded = this.getAttribute("aria-expanded") === "true" || false;
    this.setAttribute("aria-expanded", !expanded);
    let content = this.nextElementSibling;
    content.hidden = !content.hidden;
  }

  disconnectedCallback() {
    console.log("disconnected!");
  }
}

window.customElements.define("disclosure-widget", DisclosureWidget);

              
            
!
999px

Console