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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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="page">
  <header class="header">
    <div class="container">
      <div class="header-wrapper">
        <div class="logo">Logo</div>
      </div>
    </div>
  </header>
  <main class="main">
    <div class="container">
      <p class="subtitle">GreenSock</p>
      <h1 class="title">
        Accordion
      </h1>
      <div class="accordion">
        <div class="accordion__title">
          <h2>Lacus sed turpis tincidunt id aliquet</h2>
          <div class="accordion__icon"><i class="fas fa-chevron-up"></i></div>
        </div>
        <div class="accordion__content">
          <div class="accordion__content-wrapper">
            Risus feugiat in ante. Cursus metus aliquam eleifend mi in nulla. Scelerisque mauris pellentesque pulvinar pellentesque habitant. Suspendisse ultrices gravida dictum fusce ut placerat orci. Adipiscing vitae proin sagittis nisl rhoncus mattis rhoncus. Vivamus arcu felis bibendum ut tristique et egestas quis. Eu consequat ac felis donec. Eu turpis egestas pretium aenean pharetra magna ac. Velit ut tortor pretium viverra suspendisse potenti nullam. Donec enim diam vulputate ut pharetra sit. Quisque sagittis purus sit amet volutpat consequat mauris nunc congue. Massa sapien faucibus et molestie ac feugiat sed lectus. Quis commodo odio aenean sed. Morbi leo urna molestie at elementum eu facilisis sed odio.
          </div>
        </div>
      </div>
      <div class="accordion">
        <div class="accordion__title">
          <h2>Tellus orci ac auctor augue mauris</h2>
          <div class="accordion__icon"><i class="fas fa-chevron-up"></i></div>
        </div>
        <div class="accordion__content">
          <div class="accordion__content-wrapper">
            Sit amet consectetur adipiscing elit ut aliquam. Arcu non odio euismod lacinia. In hac habitasse platea dictumst quisque sagittis purus sit amet. Auctor augue mauris augue neque gravida in. Pretium vulputate sapien nec sagittis aliquam malesuada bibendum arcu vitae. Sit amet dictum sit amet justo donec. Odio euismod lacinia at quis risus sed vulputate odio ut. Aliquam eleifend mi in nulla. Maecenas sed enim ut sem viverra aliquet eget sit. Tristique magna sit amet purus.
          </div>
        </div>
      </div>
      <div class="accordion">
        <div class="accordion__title">
          <h2>Amet consectetur adipiscing elit</h2>
          <div class="accordion__icon"><i class="fas fa-chevron-up"></i></div>
        </div>
        <div class="accordion__content">
          <div class="accordion__content-wrapper">
            Ut aliquam purus sit amet luctus. Sit amet consectetur adipiscing elit pellentesque habitant morbi. Cursus in hac habitasse platea dictumst quisque sagittis purus sit. Fames ac turpis egestas integer eget aliquet nibh praesent tristique. In est ante in nibh mauris cursus. Tincidunt vitae semper quis lectus nulla at volutpat diam ut. Morbi quis commodo odio aenean sed adipiscing. Massa eget egestas purus viverra accumsan in nisl. Tristique magna sit amet purus gravida quis. Nisi quis eleifend quam adipiscing vitae proin sagittis nisl rhoncus. Urna porttitor rhoncus dolor purus non enim praesent elementum. Lorem sed risus ultricies tristique nulla. Sit amet consectetur adipiscing elit duis tristique sollicitudin nibh. Orci nulla pellentesque dignissim enim sit amet venenatis. Ut lectus arcu bibendum at.
          </div>
        </div>
      </div>
      <div class="accordion">
        <div class="accordion__title">
          <h2>Aliquet nibh praesent tristique magna sit amet purus</h2>
          <div class="accordion__icon"><i class="fas fa-chevron-up"></i></div>
        </div>
        <div class="accordion__content">
          <div class="accordion__content-wrapper">
            Malesuada bibendum arcu vitae elementum curabitur vitae nunc sed. Mauris in aliquam sem fringilla ut morbi tincidunt augue. Ut placerat orci nulla pellentesque dignissim enim sit. Ultricies tristique nulla aliquet enim tortor at auctor. Leo vel fringilla est ullamcorper eget nulla facilisi etiam dignissim. Odio tempor orci dapibus ultrices. Duis at tellus at urna condimentum mattis pellentesque id nibh. Nisl pretium fusce id velit ut tortor pretium viverra. Nisl nunc mi ipsum faucibus vitae aliquet.
          </div>
        </div>
      </div>
      <div class="accordion">
        <div class="accordion__title">
          <h2>Fermentum leo vel orci porta non pulvinar</h2>
          <div class="accordion__icon"><i class="fas fa-chevron-up"></i></div>
        </div>
        <div class="accordion__content">
          <div class="accordion__content-wrapper">
            Vel eros donec ac odio tempor orci dapibus ultrices. Fermentum posuere urna nec tincidunt praesent semper feugiat nibh sed. Ornare arcu dui vivamus arcu felis bibendum ut tristique et. Lorem donec massa sapien faucibus et molestie ac. Quisque non tellus orci ac auctor augue mauris augue. Volutpat consequat mauris nunc congue nisi vitae. Pretium quam vulputate dignissim suspendisse in est ante in nibh. Mauris a diam maecenas sed enim ut sem. Elementum integer enim neque volutpat ac tincidunt vitae semper. Malesuada bibendum arcu vitae elementum curabitur vitae nunc. Eu sem integer vitae justo eget magna fermentum iaculis. Nibh sed pulvinar proin gravida. Sit amet nulla facilisi morbi tempus iaculis urna id. Magna fermentum iaculis eu non diam phasellus vestibulum lorem sed. In mollis nunc sed id semper risus in. Nec dui nunc mattis enim ut tellus elementum sagittis vitae. Posuere morbi leo urna molestie at elementum eu facilisis sed. Nullam ac tortor vitae purus faucibus ornare suspendisse. A scelerisque purus semper eget duis at.
          </div>
        </div>
      </div>
    </div>
  </main>
</div>
              
            
!

CSS

              
                *,
*::after,
*::before {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  font-family: sans-serif;
  font-size: 20px;
  line-height: 1.4;
  height: 100%;
}

.page {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.container {
  margin: 0 auto;
  padding: 0 24px;
  max-width: 80%;
  height: 100%;
}

main {
  flex: 1 0 auto;
  padding: 32px 0 64px 0;
  background: #ebebeb;
}

.header {
  height: 80px;
  flex-shrink: 0;
  color: #fff;
  background: indigo;
}

.header-wrapper {
  height: 100%;
  display: flex;
  align-items: center;
}

.logo {
  text-transform: uppercase;
  font-weight: bold;
  font-size: 24px;
}

.title {
  margin-top: -12px;
}

.subtitle {
  text-align: left;
  margin: 0;
}

.accordion {
  margin-bottom: 24px;
  border-radius: px;
  overflow: hidden;
}

.accordion__title {
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #4b0082; /*  indigo  */
  color: white;
  padding: 16px 24px;
}

.accordion__title h2 {
  margin: 0;
  padding-right: 48px;
}

.accordion__icon i {
  font-size: 24px;
}

.accordion__content:first-child {
  transform: scale(-1);
}

.accordion__content {
  background: white;
  /*  !!!  */
  overflow: hidden;
  height: 0;
}

.accordion__content:first-child {
  height: auto;
  background: indigo;
  color: #000;
}

.accordion__content-wrapper {
  padding: 24px;
}

              
            
!

JS

              
                const list = gsap.utils.toArray(".accordion");

list.forEach((accordion, index) => {
  let isOpen = index === 0 ? true : false;

  const title = accordion.getElementsByClassName("accordion__title")[0];
  const icon = accordion.getElementsByClassName("accordion__icon")[0];
  const content = accordion.getElementsByClassName("accordion__content")[0];

  gsap.set(
    title,
    isOpen
      ? { background: "#fff", color: "#000" }
      : { background: "#4b0082", color: "#fff" }
  );
  gsap.set(content, { height: isOpen ? "auto" : "0px" });
  gsap.set(icon, { scale: isOpen ? -1 : 1 });

  title.addEventListener("click", () => {
    isOpen = !isOpen;

    gsap.to(
      title,
      isOpen
        ? { background: "#fff", color: "#000" }
        : { background: "#4b0082", color: "#fff" }
    );
    gsap.to(content, { height: isOpen ? "auto" : "0px" });
    gsap.to(icon, { scale: isOpen ? -1 : 1 });
  });
});

              
            
!
999px

Console