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

              
                <h1>jQuery Accordions</h1>

<div class="accordion">
  <h4 class="accordion__title">
    Accordion Title 01
    <i class="accordion__icon">
      <div class="line-01"></div>
      <div class="line-02"></div>
    </i>
  </h4><!-- end .accordion__title -->
  <div class="accordion__content">
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio.</p>
    <p>Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper
      suscipit, posuere a, pede.</p>
  </div><!-- end .accordion__content -->
</div><!-- end .accordion 01 -->

<div class="accordion">
  <h4 class="accordion__title">
    Accordion Title 02
    <i class="accordion__icon">
      <div class="line-01"></div>
      <div class="line-02"></div>
    </i>
  </h4><!-- end .accordion__title -->
  <div class="accordion__content">
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio.</p>
    <p>Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper
      suscipit, posuere a, pede.</p>
  </div><!-- end .accordion__content -->
</div><!-- end .accordion 02 -->

<div class="accordion">
  <h4 class="accordion__title">
    Accordion Title 03
    <i class="accordion__icon">
      <div class="line-01"></div>
      <div class="line-02"></div>
    </i>
  </h4><!-- end .accordion__title -->
  <div class="accordion__content">
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio.</p>
    <p>Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper
      suscipit, posuere a, pede.</p>
  </div><!-- end .accordion__content -->
</div><!-- end .accordion 03 -->

<div class="accordion">
  <h4 class="accordion__title">
    Accordion Title 04
    <i class="accordion__icon">
      <div class="line-01"></div>
      <div class="line-02"></div>
    </i>
  </h4><!-- end .accordion__title -->
  <div class="accordion__content">
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio.</p>
    <p>Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper
      suscipit, posuere a, pede.</p>
  </div><!-- end .accordion__content -->
</div><!-- end .accordion 04 -->
              
            
!

CSS

              
                /**
 * Required CSS 
 */
.accordion__title {
  cursor: pointer;
  margin: 0;
  position: relative;
}

.accordion__icon {
  position: absolute;
  top: 50%;
  right: 24px;
  transform: translateY(-50%);
}

.accordion__icon .line-01,
.accordion__icon .line-02 {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 2px;
  background-color: #272343;
  transition: 0.3s;
}

.accordion__icon .line-02 {
  transform: rotate(90deg);
}

.accordion__content {
  display: none;
}

.accordion--open .line-02 {
  transform: rotate(0deg);
}
/* end Required CSS */

/**
 * Now let's make it look pretty! 
 */
body {
  font-family: "Rubik", sans-serif;
  max-width: 768px;
  margin: 0 auto;
  padding: 40px 5%;
  color: #111;
  overflow-y: scroll;
}

h1 {
  text-align: center;
  margin: 0 0 40px;
}

.accordion {
  margin-top: -1px;
  border-top: 1px solid #272343;
  border-bottom: 1px solid #272343;
}

.accordion__title {
  padding: 20px 16px;
  font-size: 16px;
  transition: 0.2s;
}

.accordion__content {
  padding: 24px 16px 16px;
}

.accordion__content p {
  margin: 0 0 16px;
}

.accordion__title:hover {
  background-color: #433d6f;
  color: #fff;
}

.accordion__title:hover .line-01,
.accordion__title:hover .line-02 {
  background-color: #fff;
}

.accordion--open .accordion__title {
  background-color: #272343;
  color: #fff;
}

.accordion--open .line-01,
.accordion--open .line-02 {
  background-color: #fff;
}

              
            
!

JS

              
                // When any accordion title is clicked...
$(".accordion__title").click(function() {
  const $accordion_wrapper = $(this).parent();
  const $accordion_content = $(this).parent().find(".accordion__content");
  const $accordion_open = "accordion--open";

  // If this accordion is already open
  if ($accordion_wrapper.hasClass($accordion_open)) {
    $accordion_content.slideUp();                     // Close the content.
    $accordion_wrapper.removeClass($accordion_open);  // Remove the accordionm--open class.
  }
  // If this accordion is not already open
  else {
    $accordion_content.slideDown();                 // Show this accordion's content.
    $accordion_wrapper.addClass($accordion_open);   // Add the accordion--open class.
  }
});

              
            
!
999px

Console