Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <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>
</details>

<details>
  <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, include the <code>open</code> attribute on the opening tag:</p>
  <pre><code><​details open>...<​/details></code></pre>
</details>

<details>
  <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>
</details>

<details>
  <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 browsers. 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>
</details>

<details>
  <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>
</details>

<details>
  <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>
</details>

<details>
  <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 AX is at least as good as (if not better than) most JavaScript-dependent accordion solutions.</p>
</details>

<details>
  <summary>Excellent! More information, please!</summary>
  <p>You bet! Here are some great resources on <code>details</code> &amp; <code>summary</code>:</p>
  <ul>
    <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>
  </ul>
</details>

<details>
  <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>. (Or just wait for Edge to use Chromium, I guess. 😕)</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>
</details>
              
            
!

CSS

              
                *,
::before,
::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;
  
  &::before,
  &::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;
  }
}
              
            
!

JS

              
                // Nothing to see here…
              
            
!
999px

Console