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

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

              
                <main>
  <h1>HTML Buddies: <code>&lt;details&gt;</code> & <code>&lt;summary&gt;</code></h1>
  
    <p>
      These styles are not be beautiful because I made none. I <em>did</em>, however, take the time to do some digging to make sure your implementation is accessible. Then you can apply your techniques following best practices of making hover <em>and</em> focus styles, ensuring good contrast, and making sure you are not relying on color changes or visual cues alone.
  </p>
  
  <details>
  <summary>There is a polyfill…</summary>
    <p>
      Edge does not yet support <code>&lt;details&gt;</code> & <code>&lt;summary&gt;</code>, but <a href="https://github.com/javan/details-element-polyfill">with this polyfill</a> you can make Edge play along like the rest. The polyfill is embedded in this pen as well.
    </p>
    <p>
      Note that in all browsers that support <code>&lt;details&gt;</code> & <code>&lt;summary&gt;</code>, holding down the <kbd>Enter</kbd> key makes it toggle repeatedly, but not with the <kbd>Space</kbd> bar . The polyfill lets it toggle repeatedly with <kbd>Space</kbd> in Edge.
    </p>
</details>
  
  <details>
    <summary>…or you can detect support</summary>
    <p>
      Modernizr <a href="https://modernizr.com/download?details-setclasses">provides a configuration option</a> to detect whether a browser supports <code>&lt;details&gt;</code> & <code>&lt;summary&gt;</code>. Maybe do not use it if you are using the polyfill.
  </details>


  
  <h2>References</h2>
  
    <ul>
    <li>
      <a href="https://github.com/javan/details-element-polyfill">Polyfill</a> (or copy it out of the JS block of this pen).
    </li>
      
    <li>
      <a href="https://modernizr.com/download?details-setclasses">Modernizr feature detection</a>.
    </li>

    <li>
      This pen is for the May 2018 week 2 CodePen challenge, <a href="https://codepen.io/challenges/2018/may/">HTML Buddies</a>.
    </li>
    
    <li>
      You can see a <a href="https://blog.codepen.io/2018/05/20/codepenchallenge-details-and-summary-roundup/">round-up of week 2 on the CodePen blog</a>.
    
    <li>
      See <a href="http://adrianroselli.com/2018/06/codepen-html-buddies-challenge.html" target="_top">all four of my pens for this challenge</a> at my site with additional context.
    </li>
  </ul>

</main>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Lato:400,700|VT323');

body {
  background-color: #8c90af;
  color: #333;
  font-family: Lato, Arial, sans-serif;
  padding: 0;
  margin: 0;
  line-height: 1.5;
}

li:not(:first-of-type) {
  margin-top: 1em;
}

code {
  font-family: 'VT323', 'Courier New', Courier, monospace;
  font-size: 110%;
  font-weight: normal;
  font-variant-ligatures: none;
  padding: 0.05em 0.25em;
  background-color: rgba(255, 255, 255, 0.75);
  border-radius: 0.5em;
}

main {
  display: block;
  box-sizing: border-box;
  width: 90%;
  margin: 1em auto;
  padding: 1em 2em;
  color: #000;
  background-color: rgba(255, 255, 255, 0.8);
  border: 0.07em solid rgba(0, 0, 0, 0.5);
  border-radius: 0.5em;
}

kbd		{	border: .07em solid #aaa;
			border-radius: 0.3em;
			box-shadow: 0.1em 0.2em 0.2em rgba(0,0,0,.5);
			background-color: #f9f9f9;
			background-image: linear-gradient(to bottom, #eee, #f9f9f9, #eee);
			padding: 0.1em 0.3em;
			font-family: Courier, "Courier New", monospace;
			font-size: 90%;
			color: #000;
			/* white-space: nowrap; */
			line-height: 1; }

code, kbd	{	box-decoration-break: slice;}

summary {
  font-weight: bold;
  margin: 0 0 0 -1em;
}

details {
  margin: 1em 1.5em;
}
              
            
!

JS

              
                /*
Details Element Polyfill 2.0.1
Copyright © 2018 Javan Makhmali
 */
(function(){}).call(this),function(){var t,e,n,r,u,o,i,a,l,s,c,d;s={element:function(){var t,e,n,r,u;return e=document.createElement("details"),"open"in e?(e.innerHTML="<summary>a</summary>b",e.setAttribute("style","position: absolute; left: -9999px"),r=null!=(u=document.body)?u:document.documentElement,r.appendChild(e),t=e.offsetHeight,e.open=!0,n=e.offsetHeight,r.removeChild(e),t!==n):!1}(),toggleEvent:function(){var t;return t=document.createElement("details"),"ontoggle"in t}()},s.element&&s.toggleEvent||(i=function(){return document.head.insertAdjacentHTML("afterbegin",'<style>@charset"UTF-8";details:not([open])>*:not(summary){display:none;}details>summary{display:block;}details>summary::before{content:"\u25ba";padding-right:0.3rem;font-size:0.6rem;cursor:default;}details[open]>summary::before{content:"\u25bc";}</style>')},o=function(){var t,e,n,r;return e=document.createElement("details").constructor.prototype,r=e.setAttribute,n=e.removeAttribute,t=Object.getOwnPropertyDescriptor(e,"open"),Object.defineProperties(e,{open:{get:function(){var e;return"DETAILS"===this.tagName?this.hasAttribute("open"):null!=t&&null!=(e=t.get)?e.call(this):void 0},set:function(e){var n;return"DETAILS"===this.tagName?(e?this.setAttribute("open",""):this.removeAttribute("open"),e):null!=t&&null!=(n=t.set)?n.call(this,e):void 0}},setAttribute:{value:function(t,e){return d(this,function(n){return function(){return r.call(n,t,e)}}(this))}},removeAttribute:{value:function(t){return d(this,function(e){return function(){return n.call(e,t)}}(this))}}})},a=function(){return r(function(t){var e;return e=t.querySelector("summary"),t.hasAttribute("open")?(t.removeAttribute("open"),e.setAttribute("aria-expanded",!1)):(t.setAttribute("open",""),e.setAttribute("aria-expanded",!0))})},u=function(){var e,n,r,u,o;for(u=document.querySelectorAll("summary"),e=0,n=u.length;n>e;e++)o=u[e],t(o);return"undefined"!=typeof MutationObserver&&null!==MutationObserver?(r=new MutationObserver(function(e){var n,r,u,i,a;for(i=[],r=0,u=e.length;u>r;r++)n=e[r].addedNodes,i.push(function(){var e,r,u;for(u=[],e=0,r=n.length;r>e;e++)a=n[e],"DETAILS"===a.tagName&&(o=a.querySelector("summary"))?u.push(t(o,a)):u.push(void 0);return u}());return i}),r.observe(document.documentElement,{subtree:!0,childList:!0})):document.addEventListener("DOMNodeInserted",function(e){return"SUMMARY"===e.target.tagName?t(e.target):void 0})},t=function(t,e){return null==e&&(e=n(t,"DETAILS")),t.setAttribute("aria-expanded",e.hasAttribute("open")),t.hasAttribute("tabindex")||t.setAttribute("tabindex","0"),t.hasAttribute("role")?void 0:t.setAttribute("role","button")},l=function(){var t;return"undefined"!=typeof MutationObserver&&null!==MutationObserver?(t=new MutationObserver(function(t){var e,n,r,u,o,i;for(o=[],n=0,r=t.length;r>n;n++)u=t[n],i=u.target,e=u.attributeName,"DETAILS"===i.tagName&&"open"===e?o.push(c(i)):o.push(void 0);return o}),t.observe(document.documentElement,{attributes:!0,subtree:!0})):r(function(t){var e;return e=t.getAttribute("open"),setTimeout(function(){return t.getAttribute("open")!==e?c(t):void 0},1)})},e=function(t){return!(t.defaultPrevented||t.altKey||t.ctrlKey||t.metaKey||t.shiftKey||t.target.isContentEditable)},r=function(t){return addEventListener("click",function(r){var u,o;return e(r)&&r.which<=1&&(u=n(r.target,"SUMMARY"))&&"DETAILS"===(null!=(o=u.parentElement)?o.tagName:void 0)?t(u.parentElement):void 0},!1),addEventListener("keydown",function(r){var u,o,i;return e(r)&&(13===(o=r.keyCode)||32===o)&&(u=n(r.target,"SUMMARY"))&&"DETAILS"===(null!=(i=u.parentElement)?i.tagName:void 0)?(t(u.parentElement),r.preventDefault()):void 0},!1)},n=function(){return"function"==typeof Element.prototype.closest?function(t,e){return t.closest(e)}:function(t,e){for(;t;){if(t.tagName===e)return t;t=t.parentElement}}}(),c=function(t){var e;return e=document.createEvent("Events"),e.initEvent("toggle",!0,!1),t.dispatchEvent(e)},d=function(t,e){var n,r;return n=t.getAttribute("open"),r=e(),t.getAttribute("open")!==n&&c(t),r},s.element||(i(),o(),a(),u()),s.element&&!s.toggleEvent&&l())}.call(this),function(){}.call(this);
              
            
!
999px

Console