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

              
                 <div class="wrapper">

        <div class="colI">
            <details>
                <summary> The &lt;details&gt; Element
                    <div class="chevron">
                        <span class="chev"></span>
                    </div>
                </summary>
            </details>
            <div class="animate">
                <p class="content">
                    Introduced with HTML 5, the &lt;details&gt; element made it possible to create javascript-free accordions. However, they came with a downside, smooth opening and closing animations were not possible. Many would just use JS to allow animations, but that just defeats the purpose.
                    <br><br>
                    Thankfully, there <em>is</em> a CSS-only trick to improve the element.
                </p>
            </div>
        </div>

        <div class="colII">
            <details>
                <summary> The Trick
                    <div class="chevron">
                        <span class="chev"></span>
                    </div>
                </summary>
            </details>
            <div class="animate">
                <p class="content">
                    The solution is extremely simple &mdash; just use a sibling element!
                    <br><br>
                    Elements within the <code>&lt;details&gt;</code> tags which are not <code>&lt;summary&gt;</code> tags, display the content of the accordion. This nested element cannot be animated though. 
                    <br><br>
                    Instead, make the child a sibling of the details element.
                    <br><br>
                    Now all you have to do is hide the sibling by default and make it appear once the accordion is open, i.e., <code class="sel">details[<span>open</span>] + .sibling</code>. 
                </p>
            </div>
        </div>

        <div class="colIII">
            <details>
                <summary><span>Fun With &lt;details&gt;</span>
                    <div class="fun chevron">
                        <span class="fun chev"></span>
                    </div>
                </summary>
            </details>
                <div class="bro animate">
                    <p class="content">
                        With this trick you can add as many content elements and animations as you'd like!
                    </p>
                </div>
                <div class="st-fold fold animate">
                    <p class="content">
                        Lorem ipsum dolor sit amet.
                    </p>
                </div>
                <div class="nd-fold fold animate">
                    <p class="content">
                        Lorem, ipsum dolor sit amet consectetur adipisicing.
                    </p>
                </div>
                <div class="rd-fold fold animate">
                    <p class="content">
                        Lorem ipsum dolor sit amet consectetur.
                    </p>
                </div>
        </div>
   
    </div>
              
            
!

CSS

              
                
@import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Antonio:wght@300&display=swap');


body {
    height: 1300px;
    margin: 30px 55px;
    background-color: #edeff5;
    font-family: 'Poppins', sans-serif;
}

.wrapper {
    background-color: #fafbff;
    border: 1px solid #9c9c9c;
    border-radius: 6px;
}

code {
    padding: 3px;
    background-color: #d7dde5;
    color: #1385e3;
}

.sel {
    white-space: nowrap;
    color: #54870d;
}
.sel span {
    color: #dc561e;
}


/* Accordion Styling */


details summary {
    display: flex;
    position: relative;
    align-items: center;
    padding: 25px;
    border-top: 1px solid #d9d9d9;
    color: #035ee8;
    font-family: 'Antonio', sans-serif;
    font-size: 1.7rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;

    list-style: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none; 
    user-select: none; 
}

.colIII summary span {
    animation: fun 2s linear infinite;
}

@keyframes fun {
    20% {
        transform: perspective( 200px ) rotate3d(1,0,0,-30deg);
    }
    80% {
        transform: perspective( 200px ) rotate3d(1,0,0,30deg);
    }
}

.fun::before, .fun::after {
    animation: funn 2s infinite;
}

@keyframes funn {
    20% {
        background-color: #E90F0F;
    }
    20% {
        background-color: #FBB102;
    }
    60% {
        background-color: #00A901;
    }
    80%{
        background-color: #1937D4;
    }
    100% {
        background-color: #5906AB;
    }
}

/* Chevron Icons */

.chevron::before, .chevron::after, .chev::before, .chev::after {
    position: absolute;
    content: "";
    right: 30px;
    height: 2px;
    width: 12px;
    border-radius: 2px;
    background-color: #035ee8;
    transition: transform .2s ease-in-out;
}

.chevron {
    position: absolute;
    right: 0;
    transition: transform .2s ease-in-out;
}
details[open] .chevron {
    transform: translateY(-4px);
    transition: transform .2s ease-in-out;
}

.chevron::before, .chev::after {
    transform: rotate(45deg);
}
.chev::before, .chevron::after {
    transform: translateX(7px) rotate(-45deg);
}

details[open] .chevron::before {
    transform: rotate(45deg);
}
details[open] .chev::before {
    transform: translateX(7px) rotate(-45deg);
}

details[open] .chevron::after {
    transform: translateY(7px) rotate(-45deg);
}
details[open] .chev::after {
    transform: translateY(7px) translateX(7px) rotate(45deg);
}


/* Style & Animate Siblings */

.content {
    padding: 0 25px;
    margin-top: 0;
    font-size: 18px;
}

.animate {
    height: auto;
    max-height: 0;
    overflow: hidden;
    transition: all .5s ease;
    transition-delay: 0s;
}

details[open] ~ .animate {
    max-height: 100vh;
    overflow: hidden;
    transition: all .5s ease;
    transition-delay: 0s;
}

/* Fold */

.bro::after {
    position: absolute;
    content: "";
    left: 0;
    height: 100vh;
    width: 100vw;
    background-color: #edeff5;
}

.fold {
    margin-top: -2px;
    margin-left: -1px;
    border: solid #9c9c9c;
    border-width: 0 1px 1px 1px;
    opacity: 0;
}

details[open] ~ .fold {
    background-color: #fafbff;
    transform-origin: top;
    animation: fold .5s linear forwards;
}

details[open] ~ .st-fold {
    animation-delay: .1s;
}

details[open] ~ .nd-fold {
    animation-delay: .5s;
}

details[open] ~ .rd-fold {
    animation-delay: .8s;
}

@keyframes fold {
    from {
        opacity: 0;
        transform: perspective( 200px ) rotate3d(1,0,0,-90deg);
    }
    55% {opacity: 1;}
    to {
        transform: none;
        opacity: 1;
    }
}

              
            
!

JS

              
                
              
            
!
999px

Console