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

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


              
            
!

CSS

              
                

.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;
}
              
            
!

JS

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

Console