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

              
                <accordion-wrapper>
  <a-section>
    <a-title>
      <span>Paris</span><span>🧀</span>
    </a-title>
    <a-content>
      Paris is the capital and most populous city of France, with a population of 2,148,271 residents. Since the 17th century, Paris has been one of Europe's major centres of finance, diplomacy, commerce, fashion, science and the arts.
    </a-content>
  </a-section>
  <a-section>
    <a-title>
      <span>Lech</span><span>⛷</span>
    </a-title>
    <a-content>
      Lech am Arlberg is a mountain village and an exclusive ski resort in the Bludenz district in the Austrian state of Vorarlberg on the banks of the river Lech.
    </a-content>
  </a-section>
  <a-section>
    <a-title>
      <span>Madrid</span><span>🍷</span>
    </a-title>
    <a-content>
      Madrid is the capital and most populous city of Spain. As the capital city of Spain, seat of government, and residence of the Spanish monarch, Madrid is also the political, economic and cultural centre of the country.
    </a-content>
  </a-section>
</accordion-wrapper>

<accordion-wrapper class="sideways">
  <a-section>
    <a-title>
      <span>Paris</span><span>🧀</span>
    </a-title>
    <a-content>
      Paris is the capital and most populous city of France, with a population of 2,148,271 residents. Since the 17th century, Paris has been one of Europe's major centres of finance, diplomacy, commerce, fashion, science and the arts.
    </a-content>
  </a-section>
  <a-section>
    <a-title>
      <span>Lech</span><span>⛷</span>
    </a-title>
    <a-content>
      Lech am Arlberg is a mountain village and an exclusive ski resort in the Bludenz district in the Austrian state of Vorarlberg on the banks of the river Lech.
    </a-content>
  </a-section>
  <a-section>
    <a-title>
      <span>Madrid</span><span>🍷</span>
    </a-title>
    <a-content>
      Madrid is the capital and most populous city of Spain. As the capital city of Spain, seat of government, and residence of the Spanish monarch, Madrid is also the political, economic and cultural centre of the country.
    </a-content>
  </a-section>
</accordion-wrapper>
              
            
!

CSS

              
                accordion-wrapper {
  display: block;
  margin: 30px auto;
  width: 400px;
  box-shadow: 0 10px 20px -10px #646f74;
}

a-title::part(link) {
  display: flex;
  justify-content: space-between;
  padding: 15px 15px 15px 25px;
  background: white;
  border-top: 1px solid #edf2f8;
  border-bottom: 1px solid white;
  cursor: pointer;
  transition: border 0.2s, font-weight 0.2s;
}
a-title::part(link)::before {
  display: inline;
  content: "+";
}
a-title::part(link):hover {
  border-bottom: 1px solid #646f74;
  font-weight: bold;
}
a-title::part(expanded) {
  border-bottom: 1px solid #646f74;
}
a-title::part(expanded)::before {
  content: "-";
}
a-content::part(content) {
  background: #edf2f8;
  visibility: hidden;
  height: 0;
  padding: 0;
  font-size: 0;
  transition: height 0.2s, visibility 0.2s, padding 0.2s;
}
a-content::part(content expanded) {
  visibility: visible;
  height: auto;
  padding: 15px;
  font-size: 1em;
  border-bottom: 1px solid #edf2f8;
}

accordion-wrapper.sideways {
  display: flex;
  flex-flow: row nowrap;
  // width: 100%;
  // max-width: 1920px;

  a-section {
    display: flex;
    flex-flow: row nowrap;
    align-items: stretch;
  }

  a-title::part(link) {
    flex-flow: column nowrap;
    justify-content: center;
    align-items: center;
    height: 100%;
    box-sizing: border-box;
  }

  a-title::part(link):hover {
    border-right: 1px solid #646f74;
    border-bottom: none;
    font-weight: bold;
  }
  a-title::part(expanded) {
    border-right: 1px solid #646f74;
    border-bottom: none;
  }

  a-content::part(content) {
    height: auto;
    width: 0;
    transition: width 0.2s, visibility 0.2s, padding 0.2s;
  }
  a-content::part(content expanded) {
    width: auto;
  }
}

              
            
!

JS

              
                import {
  ref,
  provide,
  inject,
  computed,
  defineCustomElement
} from "https://unpkg.com/vue@3/dist/vue.esm-browser.js";

const AccordionWrapper = defineCustomElement({
  props: ["class"],
  template: `<slot />`,
  setup() {
    const activeIndex = ref(-1);
    provide("activeIndex", activeIndex);
    return {
      activeIndex
    };
  }
});

customElements.define("accordion-wrapper", AccordionWrapper);

let SECTION_INDEX = 0;
const ASection = defineCustomElement({
  props: ["class"],
  template: `<slot />`,
  setup() {
    const activeIndex = inject("activeIndex");

    // provide
    const index = SECTION_INDEX;
    provide("index", index);
    SECTION_INDEX++;

    if (activeIndex.value === -1) {
      activeIndex.value = index;
    }

    provide("activate", () => {
      activeIndex.value = index;
    });

    provide(
      "isActive",
      computed(() => activeIndex.value === index)
    );

    return {
      index
    };
  }
});

customElements.define("a-section", ASection);

const ATitle = defineCustomElement({
  props: ["class"],
  template: `<a :part="classes + ' link'" @click="activate"><slot/></a>`,
  setup() {
    const isActive = inject("isActive");
    const activate = inject("activate");

    const classes = computed(() => {
      return isActive.value ? "expanded" : "closed";
    });

    return {
      activate,
      classes
    };
  }
});

customElements.define("a-title", ATitle);

const AContent = defineCustomElement({
  props: ["class"],
  template: `<div :part="classes + ' content'"><slot /></div>`,
  setup() {
    const isActive = inject("isActive");

    const classes = computed(() => {
      return isActive.value ? "expanded" : "closed";
    });

    return {
      classes
    };
  }
});

customElements.define("a-content", AContent);

              
            
!
999px

Console