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

              
                <div class="accordion-container">
      <div class="accordion" data-theme="cheese">
        <div class="accordion__header">
          <h2>
            <button>
              <span class="accordion__title">Cheese</span>
              <div class="accordion__indicator">
                <svg class="indicator__plus" viewBox="0 0 80 80">
                  <use xlink:href="images/sprite.svg#plus" />
                </svg>
                <svg class="indicator__minus" viewBox="0 0 80 28">
                  <use xlink:href="images/sprite.svg#minus" />
                </svg>
              </div>
            </button>
          </h2>
        </div>

        <div class="accordion__content">
          <svg viewBox="0 0 141 65">
            <use xlink:href="images/sprite.svg#cheese" />
          </svg>
          <p>
            <a href="https://en.wikipedia.org/wiki/Cheese">Cheese</a> is a food
            derived from milk that is produced in a wide range of flavors,
            textures, and forms by coagulation of the milk protein casein.
          </p>
        </div>
      </div>

      <div class="accordion" data-theme="lettuce">
        <div class="accordion__header">
          <h2>
            <button>
              <span class="accordion__title">Lettuce</span>
              <div class="accordion__indicator">
                <svg class="indicator__plus" viewBox="0 0 80 80">
                  <use xlink:href="images/sprite.svg#plus" />
                </svg>
                <svg class="indicator__minus" viewBox="0 0 80 28">
                  <use xlink:href="images/sprite.svg#minus" />
                </svg>
              </div>
            </button>
          </h2>
        </div>

        <div class="accordion__content">
          <svg viewBox="0 0 110 73">
            <use xlink:href="images/sprite.svg#lettuce" />
          </svg>
          <p>
            <a href="https://en.wikipedia.org/wiki/Lettuce">Lettuce</a> is an
            annual plant of the daisy family, Asteraceae. It is most often grown
            as a leaf vegetable, but sometimes for its stem and seeds.
          </p>
        </div>
      </div>

      <div class="accordion" data-theme="tomato">
        <div class="accordion__header">
          <h2>
            <button>
              <span class="accordion__title">Tomato</span>
              <div class="accordion__indicator">
                <svg class="indicator__plus" viewBox="0 0 80 80">
                  <use xlink:href="images/sprite.svg#plus" />
                </svg>
                <svg class="indicator__minus" viewBox="0 0 80 28">
                  <use xlink:href="images/sprite.svg#minus" />
                </svg>
              </div>
            </button>
          </h2>
        </div>

        <div class="accordion__content">
          <svg viewBox="0 0 127 62">
            <use xlink:href="images/sprite.svg#tomatoes" />
          </svg>
          <p>
            The <a href="https://en.wikipedia.org/wiki/Tomato">tomato</a> is the
            edible, often red, fruit of the plant Solanum lycopersicum, commonly
            known as a tomato plant.
          </p>
        </div>
      </div>

      <div class="accordion" data-theme="beef">
        <div class="accordion__header">
          <h2>
            <button>
              <span class="accordion__title">Beef</span>
              <div class="accordion__indicator">
                <svg class="indicator__plus" viewBox="0 0 80 80">
                  <use xlink:href="images/sprite.svg#plus" />
                </svg>
                <svg class="indicator__minus" viewBox="0 0 80 28">
                  <use xlink:href="images/sprite.svg#minus" />
                </svg>
              </div>
            </button>
          </h2>
        </div>

        <div class="accordion__content">
          <svg viewBox="0 0 112 59">
            <use xlink:href="images/sprite.svg#beef" />
          </svg>
          <p>
            <a href="https://en.wikipedia.org/wiki/Beef">Beef</a> is the
            culinary name for meat from cattle, particularly skeletal muscle.
            Beef is a source of high-quality protein and essential nutrients.
          </p>
        </div>
      </div>
    </div>
              
            
!

CSS

              
                :root {
  --link-color: #2900b4;
  --link-color-dark: #190070;
}

[data-theme="cheese"] {
  --background-color: #f3ca5f;
  --text-color: #3a1e0e;
}

[data-theme="lettuce"] {
  --background-color: #88d28b;
  --text-color: #091e0a;
}

[data-theme="tomato"] {
  --background-color: #f46e6e;
  --text-color: #1a0201;
}

[data-theme="beef"] {
  --background-color: #ac5a30;
  --text-color: #170005;
}

html {
  font-size: 125%;
  font-family: "Nunito", sans-serif;
  line-height: 1.4;
}

body {
  background-image: linear-gradient(135deg, #ffc96a, #ffbfdd);
  min-height: 100vh;
  padding: 3em;
}

a {
  color: var(--link-color);
}

a:hover,
a:active {
  color: var(--link-color-dark);
}

.accordion-container {
  max-width: 30em;
}

.accordion {
  position: relative;
  background-color: var(--background-color);
  color: var(--text-color);
}

.accordion::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 1em;
  background-color: rgba(125, 89, 69, 0.6);
  content: "";
}

.accordion:first-child {
  border-top-left-radius: 1.5em;
  border-top-right-radius: 1.5em;
}

.accordion:first-child::before {
  border-top-left-radius: 1.5em;
}

.accordion:last-child {
  border-bottom-left-radius: 1.5em;
  border-bottom-right-radius: 1.5em;
}

.accordion:last-child::before {
  border-bottom-left-radius: 1.5em;
}

/**
 * START EDITING HERE
 * ==================
 */

/* Opens the accordion */
.accordion.is-open .accordion__content {
  display: grid;
}

.accordion__header button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: calc(100% - 1rem);
  margin-left: 1rem;
  padding: 1.5rem 2rem 1.5rem;
  border: 0;
  text-align: left;
}

.accordion__title {
  font-size: 1.5rem;
  text-transform: uppercase;
  font-weight: bold;
}

/* Indicators */
.accordion__indicator > * {
  width: 1rem;
}

.accordion .indicator__plus {
  display: block;
}

.accordion .indicator__minus {
  display: none;
}

.accordion.is-open .indicator__minus {
  display: block;
}

.accordion.is-open .indicator__plus {
  display: none;
}

/* Accordion content */
.accordion__content {
  display: none;
  grid-template-columns: 7.5em 1fr;
  grid-column-gap: 1.5em;
  align-items: center;
  padding-right: 3em;
  padding-bottom: 1.5em;
  padding-left: 3em;
}



              
            
!

JS

              
                // Get all the accordion section ( 4 ) and create an array from it
const accordions = Array.from(document.querySelectorAll('.accordion'));

//  Iterate inside our Array
accordions.forEach( accordion => {

  // Get the accordion Header
  const accordionHeader = accordion.querySelector('.accordion__header');

  // Create an event listener for toggle the "is-open" class in order to close and open ours accordions
  accordionHeader.addEventListener('click', () => {
    // Toggle our classList
    accordion.classList.toggle('is-open');
  });
});
              
            
!
999px

Console