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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <h3>
  <button data-expandable="section-name">Title of section</button>
</h3>
<p id="section-name">Section content tincidunt turpis nec ultrices tristique. Aliquam bibendum metus dignissim dui placerat, sed porta urna blandit. Ut condimentum magna sit amet nulla finibus vestibulum. Maecenas maximus leo sed neque ornare, eu semper urna aliquam. Nam luctus enim eros, vel lacinia dolor tincidunt ut. Aenean laoreet pretium blandit.</p>

              
            
!

CSS

              
                body {
  max-width: 700px;
  padding: 1.6em;
  font-size: 120%;
}

/* style the expandable's button */
[data-expandable] {
  display: block;
  width: 100%;
  text-align: left;
  background: #293352;
  border: 0;
  color: #fff;
  padding: 0.25em 0.5em;
  margin-bottom: 0.25em;
}

/* make sure there is a focus style for keyboard accessibility */
[data-expandable]:focus {
  outline: 2px solid #005C9C;
  outline-offset: 1px;
}

/* the arrow using pseudo-content and unicode */
[data-expandable][aria-expanded="false"]::before {
  content: '\25b8\0020';
}
/* the arrow for the expanded state using pseudo-content and unicode */
[data-expandable][aria-expanded="true"]::before {
  content: '\25bE\0020';
}

/* pair visual appearance with accessible state  */
.expandable[aria-hidden="true"] {
  display: none;
}
              
            
!

JS

              
                /*!
  jQuery a11yExpandable plugin
  @name jquery.a11yExpandable.js
  @author Heydon (heydon@heydonworks.com or @heydonworks)
  @version 1.0
  @date 01/01/2013
  @category jQuery Plugin
  @copyright (c) 2015 (Heydon Pickering)
  @license Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
*/

(function( $ ) {
  $.fn.a11yExpandable = function() {
 
    return this.each(function() {
        
      var elem = $(this);
      var plugin = this;
      
      // set the ARIA state and relationship attributes
      elem.attr({
        'aria-expanded': 'false',
        'aria-controls': elem.attr('data-expandable') 
      });
      
      // find the element to expand by id
      var expandable = $('#'+elem.attr('data-expandable')).attr({
        'aria-hidden': 'true',
        'class': 'expandable'
      });
      
      // click handler
      elem.on('click', function() {
        
        // Cast the expanded state as a boolean
        var expanded = $(this).attr('aria-expanded') === 'false' ? false : true;
  
        // Switch the states of aria-expanded and aria-hidden
        elem.attr('aria-expanded', !expanded);
        expandable.attr('aria-hidden', expanded);
        
      });
      
    });
 
  };
}( jQuery ));

$('[data-expandable]').a11yExpandable();
              
            
!
999px

Console