css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <link href='https://fonts.googleapis.com/css?family=Old+Standard+TT' rel='stylesheet' type='text/css'>

<div class="wrap">
	
    <h1 class="heading">The NO-JS Accordion Experiment Using :checked, general sibling, and CSS3 transitions</h1>
	
    <ul class="accordion js-accordion">
        <li class="accordion-item">
            <input class="accordion-item-input" type="checkbox" name="accordion" id="item1" />
            <label for="item1" class="accordion-item-hd js-accordionTrigger">Some Sort of heading for an example.<span class="accordion-item-hd-cta">&#9650;</span></label>
            <div class="accordion-item-bd">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ex consequuntur architecto maxime, saepe repudiandae quidem quisquam aliquam cumque possimus inventore, deserunt nostrum, explicabo modi voluptatibus sed, labore quaerat. Accusamus, officiis.
            </div>
        </li>
        <li class="accordion-item">
            <input class="accordion-item-input" type="checkbox" name="accordion" id="item2" />
            <label for="item2" class="accordion-item-hd js-accordionTrigger">Some Sort of heading for an example.<span class="accordion-item-hd-cta">&#9650;</span></label>
            <div class="accordion-item-bd">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ex consequuntur architecto maxime, saepe repudiandae quidem quisquam aliquam cumque possimus inventore, deserunt nostrum, explicabo modi voluptatibus sed, labore quaerat. Accusamus, officiis.
            </div>
        </li>
    </ul>
	
    <h2>Features</h2>
	
    <ul>
        <li>No JS</li>
        <li>Clean and Responsive</li>
        <li>Animation doesn't need a set height</li>
        <li>Switching between radio or checkbox input type determines whether one or many can be open at the same time</li>
        <li>Accessible and screen reader friendly. (Doesn't use display: none;)</li>
        <li>Progressively works in IE9, but without the animation (need to test this).</li>
        <li>Large clickable trigger region: The entire head section triggers the expansion of the body.</li>
        <li>Super vanilla and can easily be customized.</li>
    </ul>
</div>
            
          
!
            
              // Local SASS Variables
$accordion-CTA_HEIGHT: 12px;
$accordion-CTA_WIDTH: 30px;
$accordion-SPACING_UNIT: 15px;

body { // Some styles for presentation.
  font-family: "Old standard TT";
background: linear-gradient(to right, rgba(76,76,76,1) 0%, rgba(71,71,71,1) 0%, rgba(89,89,89,1) 0%, rgba(102,102,102,1) 0%, rgba(45,54,110,1) 78%, rgba(45,54,110,1) 100%);
	color: white;
	text-shadow: 2px 2px black;
}

.wrap {
	max-width: 600px; // Change this to experiment with it's responsiveness.
	margin: 0 auto;
}

.heading {
	text-align: center;
	text-shadow: 2px 4px black
}

// Start Main Styles
.accordion {
 border: 1px solid white;
  padding: 0 10px;
	margin: 0 auto;
  list-style: none outside;
}

.accordion > * + * {
  border-top: 1px solid white;
}

.accordion-item-hd {
  display: block;
  // Large clickable trigger is a plus
  padding: $accordion-SPACING_UNIT $accordion-CTA_WIDTH $accordion-SPACING_UNIT 0;
  position: relative;
  cursor: pointer;
  font-size: 18px;
  font-weight: bold;
}

.accordion-item-input:checked ~ .accordion-item-bd {
  max-height: 1000px; //It'll animate to it's natural height, but this needs to be something to accomodate all potential heights.
  padding-top: $accordion-SPACING_UNIT;
  margin-bottom: $accordion-SPACING_UNIT;
  transition: max-height 1s ease-in, margin .3s ease-in, padding .3s ease-in;
}

.accordion-item-input:checked ~ .accordion-item-hd > .accordion-item-hd-cta {
  transform: rotate(0);
}

.accordion-item-hd-cta {
  display: block;
  width: $accordion-CTA_WIDTH;
  position: absolute;
  top: calc(50% - #{$accordion-CTA_HEIGHT / 2} ); /*minus half font-size*/
  right: 0;
  pointer-events: none;
  transition: transform .3s ease;
  transform: rotate(-180deg);
  text-align: center;
  font-size: $accordion-CTA_HEIGHT;
  line-height: 1;
}

.accordion-item-bd {
  max-height: 0; // Closed Default: Animating max-height allows no set heights if the range is big enough.
  margin-bottom: 0;
  overflow: hidden;
  transition: max-height .15s ease-out, margin-bottom .3s ease-out, padding .3s ease-out;
}

.accordion-item-input { //Visually hiding the form element being leveraged for it's :checked state/class.
	clip: rect(0 0 0 0);
	width: 1px;
	height: 1px;
	margin: -1;
	overflow: hidden;
	position: absolute;
	left: -9999px;
}
            
          
!
            
              // Aint nothin to see here folks.
            
          
!
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