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

              
                <!-- Generic show/hide options -->
<!-- Written as an accordion, but with different CSS also be used for toggling a menu on small screens, or for tooltip-style disclosures -->
<div class="group">
<!-- 1. if you use a link, it must have a href pointing to the panel. Blind users will expect links to go to a new location --> 
<div class="panel-wrapper">
  <a href="#panel1" class="panel-control">Item Title
    <i class="icon-arrow-down" aria-hidden="true"></i><i class="icon-arrow-up" hidden aria-hidden="true"></i>
  </a>
  <div class="panel-content hidden-all" id="panel1" tabindex="-1">
    <p>Content goes here</p>
  </div>
</div>
<!-- 2. If you use a button, you can use aria-expanded to signal the current state to blind users and leave focus on the button -->
<div class="panel-wrapper">
  <button class="panel-control" type="button" aria-expanded="false">Item Title
    <i class="icon-arrow-down" aria-hidden="true"></i><i class="icon-arrow-up" hidden aria-hidden="true"></i>
  </button>
  <div class="panel-content hidden-all" id="panel2">
    <p>Oh look it's more content</p>
  </div>
</div>
</div>
<!-- Both types must have a visual indicator of the current state. Any accessible icon method is fine. Alternatively, use img elements with appropriate alt text and you can ditch the aria on buttons. I find the aria method easier to integrate with an icon system though. -->

              
            
!

CSS

              
                body {
  font-size: 100%;
  font-family: sans-serif;
}
.hidden-all {
  display: none;
}

.panel-wrapper {
  border: 1px solid #cccccc;
  border-radius: 0.25em;
  margin-bottom: 1em; 
  width: 50%;
}
.panel-control {
  font-size: 1em;
  display: block;
  border: 0;
  padding: 0.5em;
  margin: 0;
  background: inherit;
  width: 100%;
  text-align: left;
  text-decoration: none;
  line-height: 1.2;
  box-sizing: border-box;
}
.panel-control:hover,
.panel-control:focus {
  background: #eeeeee;
  text-decoration: underline;
}
.panel-control i {
  float: right;
}
.panel-content {
  padding: 0.5em;
}
/* Icon font stuff from here on */
@font-face {
  font-family: 'icomoon';
  src:
    url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/236520/icomoon.ttf') format('truetype'),
    url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/236520/icomoon_copy.svg') format('svg');
  font-weight: normal;
  font-style: normal;
}

i {
  /* use !important to prevent issues with browser extensions that change fonts */
  font-family: 'icomoon' !important;
  speak: none;
  font-style: normal;
  font-weight: normal;
  font-variant: normal;
  text-transform: none;
  line-height: 1.2;

  /* Better Font Rendering =========== */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.icon-arrow-up:before {
  content: "\ea41";
}
.icon-arrow-down:before {
  content: "\ea43";
}
              
            
!

JS

              
                const group = document.querySelector('.group')
const toggle1 = group.querySelector("a");
const panel1 = group.querySelector("#panel1");
const toggle2 = group.querySelector('button');
const panel2 = group.querySelector('#panel2')

// events
// Must manage focus on in-page links
toggle1.addEventListener("click", function(e) {
  e.preventDefault();
  if (panel1.classList.contains("hidden-all")) {
    panel1.classList.remove("hidden-all");
    panel1.focus();
    updateIcon(this, 'up');
  } else {
    panel1.classList.add("hidden-all");
    updateIcon(this, 'down');
  }
});

// Must update ARIA attribute as well as panel for buttons
toggle2.addEventListener("click", function(e) {
  if (panel2.classList.contains("hidden-all")) {
    panel2.classList.remove("hidden-all");
    panel2.setAttribute('aria-expanded', 'true');
    updateIcon(this, 'up')
  } else {
    panel2.classList.add("hidden-all");
    panel2.setAttribute('aria-expanded', 'false');
    updateIcon(this, 'down')
  }
});

//utility functions
function updateIcon(whichOne, direction) {
  if (direction === 'up') {
    whichOne.children[0].setAttribute('hidden', 'true');
    whichOne.children[1].removeAttribute('hidden');
  } else {
    whichOne.children[0].removeAttribute('hidden');
    whichOne.children[1].setAttribute('hidden', 'true');
  }
}
              
            
!
999px

Console