cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

              <a href="#" class="button js-button" role="button">Show content</a>

<div class="content">
  <p>This demonstrates how to markup an <code>&lt;anchor&gt;</code> element as if it were a <code>&lt;button&gt;</code> element.</p>
  <p>Key takeaway is to add <code>role="button"</code> and handle the 'space' key as native buttons will excecute JS events on 'space' keypress by default.</p>
              body {
  padding: 2em;

.button {
  background-color: ForestGreen;  
  border-radius: 5px;
  color: white;
  padding: .5em;
  text-decoration: none;

.button:hover {
  background-color: DarkGreen;

.content {
  display: none;
  margin: 1em 0;

.no-js .content {
  display: block;
              (function (document, window, undefined) {
  'use strict';
  // Buttons
  var buttons = document.querySelectorAll('.js-button');   
  var displayContent = function (button, content) {
    if (content.classList.contains('active')) {
        // Hide content
        button.setAttribute('aria-expanded', 'false');
        content.setAttribute('aria-hidden', 'true');
      } else {
        // Show content
        button.setAttribute('aria-expanded', 'true');
        content.setAttribute('aria-hidden', 'false');
  [].forEach.call(buttons, function(button, index) {
    // Content var
    var content = button.nextElementSibling;
    // Set button attributes
    button.setAttribute('id', 'button-' + index);
    button.setAttribute('aria-expanded', 'false');
    button.setAttribute('aria-controls', 'content-' + index);
    // Set content attributes
    content.setAttribute('id', 'content-' + index);
    content.setAttribute('aria-hidden', 'true');    
    content.setAttribute('aria-labelledby', 'button-' + index);
    button.addEventListener('click', function () {
      displayContent(this, content);
      return false;
    }, false);
    button.addEventListener('keydown', function (event) {
      // Handle 'space' key
      if (event.which === 32) {
        displayContent(this, content);
    }, false);
})(document, window);
Loading ..................