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

              
                <h1>Simple jQuery Accordion</h1>
<div class="accordion">
  <h3 class="accordion-toggle">Accordion 1 <span class="arrow arrow-open"></span></h3>
  <div class="accordion-content default">
    <p>Prefect's bathroom Trelawney veela squashy armchairs, SPEW: Gamp's Elemental Law of Transfiguration. Magic Nagini bezoar, Hippogriffs Headless Hunt giant squid petrified. Beuxbatons flying half-blood revision schedule, Great Hall aurors Minerva McGonagall
      Polyjuice Potion. Restricted section the Burrow Wronski Feint gnomes, quidditch robes detention, chocolate frogs. Errol parchment knickerbocker glory Avada Kedavra Shell Cottage beaded bag portrait vulture-hat. Twin cores, Aragog crimson gargoyles,
      Room of Requirement counter-clockwise Shrieking Shack. Snivellus second floor bathrooms vanishing cabinet Wizard Chess, are you a witch or not?</p>
  </div>
  <h3 class="accordion-toggle">Accordion 2 <span class="arrow"></span></h3>
  <div class="accordion-content">
    <p>Pumpkin juice Trevor wave your wand out glass orbs, a Grim knitted hats. Stan Shunpike doe patronus, suck his soul Muggle-Born large order of drills the trace. Bred in captivity fell through the veil, quaffle blue flame ickle diddykins Aragog. Yer
      a wizard, Harry Doxycide the woes of Mrs. Weasley Goblet of Fire.</p>
  </div>
  <h3 class="accordion-toggle">Accordion 3 <span class="arrow"></span></h3>
  <div class="accordion-content">
    <p>Toad-like smile Flourish and Blotts he knew I'd come back Quidditch World Cup. Fat Lady baubles banana fritters fairy lights Petrificus Totalus. So thirsty, deluminator firs' years follow me 12 inches of parchment. Head Boy start-of-term banquet Cleansweep
      Seven roaring lion hat. Unicorn blood crossbow mars is bright tonight, feast Norwegian Ridgeback. Come seek us where our voices sound, we cannot sing above the ground, Ginny Weasley bright red. Fanged frisbees, phoenix tears good clean match.</p>
    <p>Half-giant jinxes peg-leg gillywater broken glasses large black dog Great Hall. Nearly-Headless Nick now string them together, and answer me this, which creature would you be unwilling to kiss? Poltergeist sticking charm, troll umbrella stand flying
      cars golden locket Lily Potter. Pumpkin juice Trevor wave your wand out glass orbs, a Grim knitted hats. Stan Shunpike doe patronus, suck his soul Muggle-Born large order of drills the trace. Bred in captivity fell through the veil, quaffle blue
      flame ickle diddykins Aragog. Yer a wizard, Harry Doxycide the woes of Mrs. Weasley Goblet of Fire.</p>
  </div>
</div>
<a class="viewport" href="#">View mobile</a>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
              
            
!

CSS

              
                body {
  font-family: Century Gothic;
  width: 50%;
  margin: 0 auto;
  transition: all .2s ease;
}

.mobile {
  width: 320px;
  height: 568;
  overflow-y: scroll;
  border: 1px solid #f5f5f5;
}

.accordion {
  margin: 1em 0;
  background: #fff;
}

.accordion-toggle {
  cursor: pointer;
  margin: 0;
  padding: 10px 15px 10px 20px;
  background: #ccc;
  color: #fff;
  border-bottom: 2px solid #fff;
}

.accordion-content {
  display: none;
  overflow: hidden;
  margin: 1em 20px;
}

.accordion-content.default {
  display: block;
}

.arrow {
  display: inline-block;
  float: right;
  margin: 7px 0 0 0;
  width: 0;
  height: 0;
  border-top: .35em solid transparent;
  border-bottom: .35em solid transparent;
  border-left: .35em solid #fff;
  transition: all .2s ease;
}

.arrow-open {
  transform: rotate(90deg);
}
              
            
!

JS

              
                $('.accordion').find('.accordion-toggle').click(function() {
  //Expand or collapse this panel
  $(this).next().slideToggle(250);
  //Hide the other panels
  $('.accordion-content').not($(this).next()).slideUp(400);
  //Turn the arrow
  $('.arrow-open').removeClass('arrow-open');
  $(this).find('.arrow').toggleClass('arrow-open');
});
$('.viewport').click(function() {
  $('body').toggleClass('mobile');
  $(this).text(function(i, v) {
    return v === 'View desktop' ? 'View mobile' : 'View desktop'
  })
  return false
});
              
            
!
999px

Console