cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <h1>All CSS Accordion</h1>
<div class="accordion">
        <!-- span to target fix closing accordion -->
        <span class="target-fix" id="accordion"></span>
         
        <!-- First Accoridon Option -->
        <div>
            <!-- span to target fix accordion -->
            <span class="target-fix" id="accordion1"></span>
            
            <!-- Link to open accordion, hidden when open --> 
            <a href="#accordion1" id="open-accordion1" title="open">First Accordion</a>
            
            <!-- Link to close accordion, hidden when closed -->
            <a href="#accordion" id="close-accordion1" title="close">First Accordion</a> 
            
            <!-- Accorion content goes in this div -->
            <div class="accordion-content">
                <p>Accordion 1 Content</p>
            </div>
        </div>

        <!-- Second Accoridon Option -->
        <div>
            <span class="target-fix" id="accordion2"></span>
            <a href="#accordion2" id="open-accordion2" title="open">Second Accordion</a>
            <a href="#accordion" id="close-accordion2" title="close">Second Accordion</a>
            <div class="accordion-content">
                <p>Accordion 2 Content.</p>       
            </div>
        </div>

        <!-- Third Accoridon Option -->
        <div>
            <span class="target-fix" id="accordion3"></span>
            <a href="#accordion3" id="open-accordion3" title="open">Third Accordion</a>
            <a href="#accordion" id="close-accordion3" title="close">Third Accordion</a>
            <div class="accordion-content">
                <p>Accordion 3 Content</p>
            </div>
        </div>
    </div>

<div class="readme">
  <p>For multiple accordions on a single page, repeat process, but assign different id names. 
  <a href="https://codepen.io/pollardld/full/lthAF"> Multiple accordions example</a></p>
  
  <p>Beware use on Android 2.2 and 2.3. The default browser on these versions does some curious things.</p>
</div>
            
          
!
            
              body {
  background: #734f79;
  font-family: 'Flamenco', serif;
}

h1 {
  color: #fff;
  font-weight: normal;
  font-size: 2.5rem;
  text-align: center;
}

.readme {
  color: #fff;
  margin: 0 auto;
  width: 80%;
  
  a {
    color: #00a486;
  }
}

/*_________________  Accordion
________________________________________*/
.accordion {
  position: relative;
  margin: 60px auto;
  width: 80%;
}

[id*="open-accordion"], [id*="close-accordion"] {
  background: #00a486;
  border-bottom: 1px solid #fff;
  line-height: 40px;
  height: 40px;
  display: block;
  margin: 0 auto;
  position: relative;
  width: 99%;
}

[id*="close-accordion"] {
  display: none;
}

.accordion a {
  color: #fff;
  font-size: 1.25em;
  font-weight: normal;
  padding-left: 2%;
  text-decoration: none;
  text-shadow: none;
}

[id*="open-accordion"]:after, [id*="close-accordion"]:after {
  content: "";
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 10px solid rgba(255, 255, 255, 0.6);
  position: absolute;
  right: 5px;
  top: 15px;
  z-index: 999;
  transform: rotate(-90deg);
  -webkit-transform: rotate(-90deg);
}

.target-fix {
  display: block;
  top: 0;
  left: 0;
  position: fixed;
}

.accordion-content {
  background: #fff;
  height: 0;
  margin: -1px auto 0;
  padding: 0 2.5%;
  position: relative;
  overflow: hidden;
  width: 90%;
  transition: all 0.1s ease;
  -webkit-transition: all 0.1s ease;
  -moz-transition: all 0.1s ease;
}

.accordion span:target ~ .accordion-content {
  display: block;
  height: auto;
  padding-bottom: 25px;
  padding-top: 10px;
}

.accordion span:target ~ [id*="close-accordion"] {
  display: block;
}

.accordion span:target ~ [id*="open-accordion"] {
  display: none;
}

.accordion span:target ~ [id*="close-accordion"]:after {
  border-top: 10px solid #333;
  transform: rotate(0deg);
  -webkit-transform: rotate(0deg);
}
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console