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

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

              
                <h1>Checkbox-Hack Accordion</h1>

<div class="accordion">

  <input class="accordion__input" type="radio" id="batman" name="accordion" checked />
  <div class="accordion__item" id="batman-content">
    <h2>Batman</h2>
    <p>Batman is a fictional superhero appearing in American comic books published by DC Comics. The character was created by artist Bob Kane and writer Bill Finger, and first appeared in Detective Comics #27 in 1939. Originally named the "Bat-Man," the character is also referred to by such epithets as the Caped Crusader, the Dark Knight, and the World's Greatest Detective.</p>
  </div>
  <label for="batman" id="batman-button" class="accordion__button">Batman</label>

  <input class="accordion__input" type="radio" id="superman" name="accordion" />
  <div class="accordion__item" id="superman-content">
    <h2>Superman</h2>
    <p>Superman is a fictional superhero. The character was created by writer Jerry Siegel and artist Joe Shuster, and first appeared in Action Comics #1, a comic book published on April 18, 1938. The character regularly appears in comic books published by DC Comics, and has been adapted to a number of radio serials, movies, and television shows.</p>
  </div>
  <label for="superman" id="superman-button" class="accordion__button">Superman</label>


  <input class="accordion__input" type="radio" id="spiderman" name="accordion" />
  <div class="accordion__item" id="spiderman-content">
    <h2>Spiderman</h2>
    <p>Spider-Man is a fictional superhero created by writer-editor Stan Lee and writer-artist Steve Ditko. He first appeared in the anthology comic book Amazing Fantasy #15 (August 1962) in the Silver Age of Comic Books. He appears in American comic books published by Marvel Comics, as well as in a number of movies, television shows, and video game adaptations set in the Marvel Universe.</p>
  </div>
  <label for="spiderman" id="spiderman-button" class="accordion__button">Spiderman</label>

  
</div>
              
            
!

CSS

              
                // Colors
$color1: #f0f0f0;
$color2: #f6f9fa;
$color3: #ffffff;
$color4: #22caeb;
$color5: #333333;


// General styles
body {
  padding: 10%;
  font-size: 16px;
  background: $color1;
  @media(max-width: 768px) {
    padding: 10% 2% 10% 2%;
  }
}

* {
  box-sizing: border-box;
}

h1 {
  text-align: center;
}

// Accordion
.accordion {
  font-size: 0; // Remove gap between inline-block elements
  box-shadow: 0 0 10px rgba(0,0,0,0.2);
  position: relative;

  &__input {
    display: none;
  }

  &__input:checked + &__item {
    height: auto;
    opacity: 1;
  }

  // Enables highlihting selected tab
  &__input#batman:checked ~ &__button#batman-button,
  &__input#superman:checked ~ &__button#superman-button,
  &__input#spiderman:checked ~ &__button#spiderman-button {
    background: $color3;
    border-top-color: lighten($color4, 25%);
    opacity: 1;
  }

  &__button {
    font-size: 16px; // Reset font-size
    background: $color2;
    width: 33.3333333%;
    display: inline-block;
    padding: 20px;
    color: $color5;
    text-decoration: none;
    text-align: center;
    border-top: 3px solid transparent;
    transition: all 150ms ease-in-out;
    border-top-color: lighten($color5, 30%);
    cursor: pointer;
    opacity: 0.6;
    &:hover {
      border-top-color: lighten($color4, 35%);
      opacity: 1;
    }
  }

  &__item {
    font-size: 16px; // Reset font-size
    line-height: 1.5;
    position: absolute;
    top: 60px;
    padding: 20px;
    width: 100%;
    height: 0;
    overflow: hidden;
    background: $color3;
    opacity: 0;
  }
}

              
            
!

JS

              
                
              
            
!
999px

Console