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.

              <details open>
  <summary>Have you heard about <code>details</code>?</summary>
  <p>It's a pretty useful element that handles accordion / collapsed text natively!</p>

  <summary>So how does it work?</summary>
  <p>You wrap a <code>details</code> element around any block of HTML content. The browser will collapse that block of text until a user opens the <code>details</code> block.</p>
  <p>Once a user opens a <code>details</code> block, they'll be able to read all that hidden content!</p>
  <p>If you want the details block open by default, set the <code>open</code> on the opening tag:</p>
  <pre><code><​details open>...<​/details></code></pre>

  <summary>But how do I set a custom title?</summary>
  <p>That's pretty manageable too! Use the <code>summary</code> element.</p>
  <p>Put a <code>summary</code> at the beginning of your details element and <b>Boom!</b> - you've got a custom title for your <code>details</code> block.</p>
  <p>No worries if you don't add a <code>summary</code>. The browser will put the word "Details" in there for you. (After all, users need something to click!)</p>

  <summary>That's cool, but what about styles?</summary>
  <p>Yes, you're covered there too! Style the <code>details</code> element however you like. Give it a border, some padding, whatever.</p>
  <p>The <code>summary</code> element is where the <code>▸</code> marker lives. If you want to get rid of that, there is a prefixed pseudo-element selector <code>::-webkit-details-marker</code>: set that to <code>display: none</code> for WebKit browser. In Firefox, it's much simpler: set the <code>summary</code> to <code>display: block</code> or <code>flex</code> (anything but the native <code>display: list-item</code>) and you'll get rid of the <code>▸</code> for you.</p>

  <summary>Ok, ok, but what about styling based on state?</summary>
  <p>Once again, <code>details</code> has got your back! When a <code>details</code> block is open, it has the <code>open</code> attribute that I mentioned earlier. To style it (or its children) based on its state, use <code>details[open] { }</code>.</p>
<p>Note: there's no <code>closed</code> attribute: styles you apply by "default" will be used on the closed state.</p>

  <summary>But this requires JavaScript, right?</summary>
  <p>Open the JS panel on this pen. Clean as a whistle! This is handled totally by the browser.</p>

  <summary>What about accessibility? Is that the catch?</summary>
  <p>Sorry to disappoint you. Since these are native HTML elements, they provide useful semantic information to screen readers.</p>
  <p>Screen readers will typically read the <code>summary</code> for a collapsed <code>details</code> block (and communicate that it's collapsed). They'll also provide an interactive hook for users to open the <code>details</code> block. If the <code>details</code> is already expanded, they'll read the whole content.</p>
  <p>I don't rely on assistive tech to read the web, so I'm probably not aware of some limitations or drawbacks to using <code>details</code> and <code>summary</code>, but I suspect their AT UX is at least as good as (if not better than) most JavaScript-dependent accordion solutions.</p>

  <summary>Excellent! More information, please!</summary>
  <p>You bet! Here are some great resources on <code>details</code> &amp; <code>summary</code>:</p>
    <li>MDN: <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details" target="_blank" rel="noopener">details</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/summary" target="_blank" rel="noopener">summary</a></li>
    <li><a href="http://html5 doctor.com/the-details-and-summary-elements/" target="_blank" rel="noopener">HTML5Doctor</a></li>
    <li><a href="https://www.scottohara.me/blog/2018/09/03/details-and-summary.html" target="_blank" rel="noopener">Scott O'Hara</a></li>
    <li><a href="https://blog.teamtreehouse.com/use-details-summary-elements" target="_blank" rel="noopener">Treehouse Blog</a></li>
    <li><a href="https://webdesign.tutsplus.com/tutorials/explaining-the-details-and-summary-elements--cms-21999" target="_blank" rel="noopener">Envato Tuts+</a></li>
    <li><a href="https://caniuse.com/#feat=details" target="_blank" rel="noopener">caniuse table for <code>details</code></a></li>

  <summary>But what about cross-browser compatibility?</summary>
  <p>Yeah, sorry. Here's some bad news. IE, Edge, and Opera Mini don't currently support <code>details</code>/<code>summary</code> with native open/close behavior (check out <a href="https://caniuse.com/#feat=details" target="_blank" rel="noopener">caniuse data for <code>details</code></a>).<p>
  <p>These browsers will show all your <code>details</code> elements expanded. That's not the worst though: it's a bit of progressive enhancement: if the browser doesn't support the native UI behavior, the content will still be visible to users.</p>
  <p>It's unlikey IE11 will be getting any updates on this front, but there's hope for Edge! If this is important to you, please <a href="https://wpdev.uservoice.com/forums/257854-microsoft-edge-developer/suggestions/6261266-details-summary-elements" target="_blank" rel="noopener">cast a vote a vote for Edge to support <code>details</code>/<code>summary.</code></a>.</p>
  <p>If you do need to have open/close behavior in IE11 (or any other non-supporting browser), you'll probably need a polyfill. This <a href="https://www.smashingmagazine.com/2014/11/complete-polyfill-html5-details-element/" target="_blank" rel="noopener">Smashing Magazine <code>details</code> polyfill tutorial</a> looks like a good place to start.</p>
::after {
  box-sizing: border-box;

html {
  background-color: #CFD8DC;

details {
  margin: 1rem auto;
  padding: 0 1rem;
  width: 35em;
  max-width: calc(100% - 2rem);
  position: relative;
  border: 1px solid #78909C;
  border-radius: 6px;
  background-color: #ECEFF1;
  color: #263238;
  transition: background-color .15s;
  > :last-child {
    margin-bottom: 1rem;
  &::before {
    width: 100%;
    height: 100%;
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    border-radius: inherit;
    opacity: .15;
    box-shadow: 0 .25em .5em #263238;
    pointer-events: none;
    transition: opacity .2s;
    z-index: -1;
  &[open] {
    background-color: #FFF;
    &::before {
      opacity: .6;

summary {
  padding: 1rem 2em 1rem 0;
  display: block;
  position: relative;
  font-size: 1.33em;
  font-weight: bold;
  cursor: pointer;
  &::after {
    width: .75em;
    height: 2px;
    position: absolute;
    top: 50%;
    right: 0;
    content: '';
    background-color: currentColor;
    text-align: right;
    transform: translateY(-50%);
    transition: transform .2s ease-in-out;
  &::after {
    transform: translateY(-50%) rotate(90deg);
    [open] & {
      transform: translateY(-50%) rotate(180deg);
  &::-webkit-details-marker {
    display: none;

p {
  margin: 0 0 1em;
  line-height: 1.5;

ul {
  margin: 0 0 1em;
  padding: 0 0 0 1em;

li:not(:last-child) {
  margin-bottom: 0.5em;

code {
  padding: 0.2em;
  border-radius: 3px;
  background-color: #E0E0E0;
  pre > & {
    display: block;
    padding: 1em;
    margin: 0;
              // Nothing to see here…
🕑 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 ..................