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

              
                main
  .accordion
    .accordion-item
      .accordion-header
        h2 Lorem ipsum dolor sit amet 1
      .accordion-body
        p 1 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
        
    .accordion-item
      .accordion-header
        h2 Lorem ipsum dolor sit amet 2
      .accordion-body
        p 2 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
        
        
    .accordion-item
      .accordion-header
        h2 Lorem ipsum dolor sit amet 3
      .accordion-body
        p 3 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
        
  .credits
    p Animation inspired by: 
      a(href="https://dribbble.com/hellobaha" target="_blank") Bakhtiyar 😱 Sattarov
    
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Roboto:400,500')

*
  box-sizing: border-box

$blue: #2b42b6
$border-radius: 5px

body, html
  width: 100%
  height: 100%
  font-family: 'Roboto', sans-serif

main
  width: 100%
  min-height: 100%
  display: flex
  justify-content: center
  align-items: flex-start
  background-color: $blue
  padding: 150px 30px
  
.accordion
  max-width: 550px

  &-item
    background-color: transparent
    margin-bottom: 15px
    border-radius: $border-radius
    box-shadow: 0 2px 9px 0 rgba(black, .1)
    transition: background-color .2s ease-in .3s

    &.active
      background-color: white
      transition: background-color .2s ease-in 0s

      .accordion
        &-header
          color: black
          background-color: white
          transition: background-color .2s ease-in 0s, color .2s ease-in .2s
          
          h2
            &:before, &:after
              background-color: black
              transition: background-color .2s ease-in .2s, transform .2s ease .1s
            &:before
              display: none
            
            &:after
              transform: rotate(90deg)

        &-body
          max-height: 900px
          padding: 0 15px 15px
          transition: max-height .3s ease-in 0s, padding .2s ease-in 0s
          
          p
            opacity: 1
            transition: opacity .2s ease-in .2s

  &-header
    color: white
    background-color: lighten($blue, 15%)
    border-radius: $border-radius
    padding: 25px 15px
    cursor: pointer
    transition: background-color .2s ease-out .3s, color .2s ease-out 0s

    h2
      position: relative
      font-size: 1rem
      font-weight: 500
      letter-spacing: .025em
      margin: 0

      &:before, &:after
        content: ""
        position: absolute
        background-color: white
        transition: background-color .2s ease-in 0s, transform .2s ease 0s
      
      &:before
        width: 10px
        height: 2px
        right: 0
        top: calc(50% - 1px)
      
      &:after
        width: 2px
        height: 10px
        right: 4px
        top: calc(50% - 5px)
        transform: none

  &-body
    max-height: 0
    padding: 0 15px
    overflow: hidden
    transition: max-height .2s ease-out 0s, padding .1s ease-out .2s

    p
      font-size: .875rem
      line-height: 1.6
      opacity: 0
      margin: 0
      transition: opacity .2s ease-in 0s
      
.credits
  position: absolute
  bottom: 30px
  right: 30px
  font-size: 14px
  p
    color: lighten($blue, 30%)
    margin: 0
  a
    color: white
              
            
!

JS

              
                const accordionItem = document.querySelectorAll('.accordion-item');
                             
const onClickAccordionHeader = e => {
  if (e.currentTarget.parentNode.classList.contains('active')) {
    e.currentTarget.parentNode.classList.remove("active");
  } else {
    Array.prototype.forEach.call(accordionItem, e => e.classList.remove('active'));
    e.currentTarget.parentNode.classList.add("active");
  }
};

const init = () => {
  Array.prototype.forEach.call(accordionItem, e => e.querySelector('.accordion-header').addEventListener('click', onClickAccordionHeader, false));
};

document.addEventListener('DOMContentLoaded', init);
              
            
!
999px

Console