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 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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

            
              <input type="checkbox" id="one" hidden />
<div class="accordion">
    <label for="one">Accordion One</label>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eveniet nulla, molestiae delectus impedit placeat facere, asperiores error et voluptate voluptas repellat doloremque, provident fugit eius itaque aliquam cupiditate ratione sequi!</p>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Vel repellat, optio quaerat omnis eveniet quos reprehenderit accusantium impedit aut officia incidunt quasi non explicabo magnam! Eum quae eius veniam saepe.</p>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Sunt autem fuga expedita aliquid molestiae, provident dolore repellendus illum, reprehenderit nobis dolores eaque dicta labore voluptatum sint recusandae ipsam asperiores incidunt?</p>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Illum perspiciatis quos explicabo, commodi pariatur, est cupiditate velit magni corrupti distinctio praesentium minus officiis. Vel enim quia, dicta ab reprehenderit maiores.</p>
</div>

<input type="checkbox" id="two" hidden />
<div class="accordion">
    <label for="two">Accordion Two</label>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Eveniet nulla, molestiae delectus impedit placeat facere, asperiores error et voluptate voluptas repellat doloremque, provident fugit eius itaque aliquam cupiditate ratione sequi!</p>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Vel repellat, optio quaerat omnis eveniet quos reprehenderit accusantium impedit aut officia incidunt quasi non explicabo magnam! Eum quae eius veniam saepe.</p>
    <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/68939/norway-001.jpg" />
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Sunt autem fuga expedita aliquid molestiae, provident dolore repellendus illum, reprehenderit nobis dolores eaque dicta labore voluptatum sint recusandae ipsam asperiores incidunt?</p>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Illum perspiciatis quos explicabo, commodi pariatur, est cupiditate velit magni corrupti distinctio praesentium minus officiis. Vel enim quia, dicta ab reprehenderit maiores.</p>
</div>

<a href="https://codepen.io/aaronbushnell/pen/eGVdzv/" target="_blank">In response to this pen by Aaron Bushnell</a>
            
          
!
            
              

.accordion {
    transition: max-height 300ms;       //  animation
    max-height: 60px;                   //  max-height when closed     
    input:checked + & {                 //  checkbox/radio input to trigger open/close
        max-height: var(--max-height);  //  switch to css var when open 
    }
}

/***
   if browser does not support CSS Variables 
   .accordion {
        transition: max-height 300ms;       //  animation
        input:not(:checked) + & {           //  checkbox/radio input to trigger open/close
            max-height: 60px !important;    //  force closed max height when closed using !important 
        }
   }
****/






//  simple reset
html { box-sizing: border-box; } 
*,*::before,*::after { box-sizing: inherit; }
body { margin: 0; }

//  just a bit of  not important styling 
.accordion {
    max-width: 80%;
    margin: 30px auto;
    border: 1px solid silver; 
    padding: 20px;
    overflow: hidden;
    transition: 300ms;
    border-radius: 5px;
    label { 
        cursor: pointer;
        display: block; 
        margin-bottom: 20px; 
        font-style: italic;
        &:before { 
            content: '▶'; 
            font-style: normal;
            vertical-align: middle;
            display: inline-block; 
            transition: 300ms;
            font-size: .7em;
            margin-right:.5em;
        }
    }
    input:checked + & label:before { transform: rotate(90deg); }
    img { width: 100%;}
}
a { 
    color: #666;
    display: block;
    text-align: center;
}
            
          
!
            
              //  collection of all accordions
const accordions = [].map.call(document.querySelectorAll('.accordion'), el => el);

//  update --max-height style on load and resize
['load','resize'].map(event => window.addEventListener(event, () => {
    accordions.map(el => el.style.setProperty('--max-height', `${el.scrollHeight}px`));
    
    //  if browser does not support CSS Variables 
    //  accordions.map(el => el.style.maxHeight = `${el.scrollHeight}px`);
}));    






            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console