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

              
                <form method="get" action="#">
  <button type="button" aria-expanded="true" id="DisclosureGroupTrigger" onclick="toggleDisclosure(this.id);" aria-controls="DisclosedGroup">
    <span class="icon">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 80 80" focusable="false">
        <path d="M70.3 13.8L40 66.3 9.7 13.8z"></path>
      </svg>
    </span>
    Mammals
    <span class="counter">(<span id="DisclosureGroupCheckCount">0</span> of <span id="DisclosureGroupCount">26</span> selected)</span>
  </button>
  <div role="group"  aria-labelledby="DisclosureGroupTrigger" id="DisclosedGroup" tabindex="0">
    <p>
      <a href="#Skip04">Skip to next group</a>
    </p>
    <input type="checkbox" name="Mam" id="Mam01" value="Aardvark">
    <label for="Mam01">Aardvark</label>
    <input type="checkbox" name="Mam" id="Mam02" value="Babirusa">
    <label for="Mam02">Babirusa</label>
    <input type="checkbox" name="Mam" id="Mam03" value="Chipmunk">
    <label for="Mam03">Chipmunk</label>
    <input type="checkbox" name="Mam" id="Mam04" value="Douc">
    <label for="Mam04">Douc</label>
    <input type="checkbox" name="Mam" id="Mam05" value="English Cream Golden Retriever">
    <label for="Mam05">English Cream Golden Retriever</label>
    <input type="checkbox" id="Mam06" value="Fennec Fox">
    <label for="Mam06">Fennec Fox</label>
    <input type="checkbox" name="Mam" id="Mam07" value="Gibbon">
    <label for="Mam07">Gibbon</label>
    <input type="checkbox" name="Mam" id="Mam08" value="Honey Badger">
    <label for="Mam08">Honey Badger</label>
    <input type="checkbox" name="Mam" id="Mam09" value="Impala">
    <label for="Mam09">Impala</label>
    <input type="checkbox" name="Mam" id="Mam10" value="Jaguar">
    <label for="Mam10">Jaguar</label>
    <input type="checkbox" name="Mam" id="Mam11" value="Kodkod">
    <label for="Mam11">Kodkod</label>
    <input type="checkbox" name="Mam" id="Mam12" value="Lemming">
    <label for="Mam12">Lemming</label>
    <input type="checkbox" name="Mam" id="Mam13" value="Marmot">
    <label for="Mam13">Marmot</label>
    <input type="checkbox" name="Mam" id="Mam14" value="North American Black Bear">
    <label for="Mam14">North American Black Bear</label>
    <input type="checkbox" name="Mam" id="Mam15" value="Otter">
    <label for="Mam15">Otter</label>
    <input type="checkbox" name="Mam" id="Mam16" value="Pangolin">
    <label for="Mam16">Pangolin</label>
    <input type="checkbox" name="Mam" id="Mam17" value="Quokka">
    <label for="Mam17">Quokka</label>
    <input type="checkbox" name="Mam" id="Mam18" value="Rhinoceros">
    <label for="Mam18">Rhinoceros</label>
    <input type="checkbox" name="Mam" id="Mam19" value="Saiga">
    <label for="Mam19">Saiga</label>
    <input type="checkbox" name="Mam" id="Mam20" value="Treeing Tennessee Brindle">
    <label for="Mam20">Treeing Tennessee Brindle</label>
    <input type="checkbox" name="Mam" id="Mam21" value="Unau (Linnaeus’s Two-Toed Sloth)">
    <label for="Mam21">Unau (Linnaeus’s Two-Toed Sloth)</label>
    <input type="checkbox" name="Mam" id="Mam22" value="Vicuña">
    <label for="Mam22">Vicuña</label>
    <input type="checkbox" name="Mam" id="Mam23" value="Warthog">
    <label for="Mam23">Warthog</label>
    <input type="checkbox" name="Mam" id="Mam24" value="Xoloitzcuintli">
    <label for="Mam24">Xoloitzcuintli</label>
    <input type="checkbox" name="Mam" id="Mam25" value="Yak">
    <label for="Mam25">Yak</label>
    <input type="checkbox" name="Mam" id="Mam26" value="Zebu">
    <label for="Mam26">Zebu</label>
  </div>
</form>

<p id="Skip04">
  This content is only here as a destination for the skip link.
</p>

<p>
  Used in the post <a href="https://adrianroselli.com/2022/05/under-engineered-multi-selects.html" target="_top"><cite>Under-Engineered Multi-Selects</cite></a>. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi aliquam, massa a feugiat consectetur, sapien orci ultricies risus, sollicitudin volutpat erat mauris sit amet nisl. Vestibulum eu urna orci. Donec eget arcu congue purus tristique scelerisque. Curabitur sit amet odio in est scelerisque gravida. Integer vitae mi interdum, egestas lectus id, varius arcu.
</p>
              
            
!

CSS

              
                :root {
  --page-bg: #eee;
  --text-color: #333;
  --scroll-bg: #fff;
}

body {
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto,
    Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  line-height: 1.4;
  /*   line-height: 1.5; */
  /*   letter-spacing: 0.12em; */
  /*   word-spacing: 0.16em; */
  background: var(--page-bg);
  color: var(--text-color);
}

[role="group"][aria-labelledby] {
  border: .1em solid #ccc;
  padding: 0 .75em;
  margin-top: -.1em;
}

[role="group"][aria-labelledby] > p {
  margin: .2em .5em;
}

[role="group"][aria-labelledby] > label {
  display: block;
  padding: .2em .5em .2em 1.5em;
  text-indent: 0;
}

[role="group"][aria-labelledby] > input {
  float: left;
  margin-top: .6em;
}

[role="group"][aria-labelledby][tabindex] {
  max-height: 11em;
  max-width: 20em;
  overflow: auto;
  background:
    linear-gradient(var(--scroll-bg) 30%, var(--scroll-bg)),
    linear-gradient(var(--scroll-bg), var(--scroll-bg) 70%) 0 100%,
    radial-gradient(farthest-side at 50% 0, rgba(0,0,0,.2), rgba(0,0,0,0)),
    radial-gradient(farthest-side at 50% 100%, rgba(0,0,0,.2), rgba(0,0,0,0)) 0 100%;
  background-repeat: no-repeat;
  background-color: var(--scroll-bg);
  background-size: 100% 4em, 100% 4em, 100% 1.4em, 100% 1.4em;
  background-attachment: local, local, scroll, scroll;
  padding: 0;
}

[role="group"][aria-labelledby][tabindex]:focus-visible {
  outline: .2em solid #00c;
}

/* Hide the set of checkboxes unless the button has aria-expanded=true */
button[aria-expanded="false"] + [role="group"][tabindex] {
  display: none;
}

/* Hide the selected counter unless JS has run */
button[aria-expanded]:not([data-js]) > .counter {
  display: none;
}

/* Only position the checkboxes over other content if JS has run */
button[aria-expanded][data-js] + [role="group"][tabindex] {
  position: absolute;
  background: #fff;
}

/* Hide the skip link if JS has run */
button[aria-expanded][data-js] + [role="group"][tabindex] > p {
  display: none;
}



/* Interaction styles */

button[aria-expanded] + [role="group"][tabindex] input:checked + label {
  background-color: #eee;
  color: var(--text-color);
}

button[aria-expanded] + [role="group"][tabindex] input:focus {
  outline-color: #eee;
}

button[aria-expanded] + [role="group"][tabindex] label:hover, button[aria-expanded] + [role="group"][tabindex] input:focus + label {
  background-color: #666;
  color: #fff;
}




/* Target styles for the demo only */
@keyframes Target {
  from { outline-offset: -.25em; outline-color: #999; outline-width: .1em; }
  to { outline-offset: 2em; outline-color: transparent; outline-width: 1em; }
}

:target {
  outline-width: .2em;
  outline-style: solid;
  outline-color: #ccc;
}

@media screen and (prefers-reduced-motion: no-preference) {
	:target {
    outline-width: 0;
    animation: Target 1s ease-out 2;
  }
}

/* Disclosure trigger styles */
/* https://adrianroselli.com/2020/05/disclosure-widgets.html */

button[aria-expanded] {
  border: .1em solid #ccc;
  padding: .5em 1em .5em .5em;
  font: inherit;
  background-color: #eee;
  border-radius: .5em .5em 0 0;
  text-align: left;
  line-height: 1.2;
}

button[aria-expanded] > .icon {
  display: inline-block;
  font-size: 60%;
  color: #000;
  background-color: #00f;
  padding: 0.3em 0.2em 0 0.2em;
  border: 0.2em solid #00f;
  border-radius: 50%;
  line-height: 1;
  text-align: center;
  text-indent: 0;
  transform: rotate(270deg);
}

button[aria-expanded] svg {
  width: 1.25em;
  height: 1.25em;
  fill: #fff;
  transition: transform 0.25s ease-in;
  transform-origin: center 45%;
}

button[aria-expanded]:hover,
button[aria-expanded]:focus {
  background-color: #666;
  color: #fff;
  outline: none;
  border-color: #666;
}

button[aria-expanded]:hover .icon:first-child,
button[aria-expanded]:focus .icon:first-child {
  background-color: #fff;
  outline: none;
}

button[aria-expanded]:hover svg,
button[aria-expanded]:focus svg {
  fill: #00f;
}

/* Lean on programmatic state for styling */
button[aria-expanded="true"] svg {
  transform: rotate(90deg);
}

              
            
!

JS

              
                function toggleDisclosure(btnID,force) {
  // Get the button that triggered this
  var theButton = document.getElementById(btnID);
  // Force the button to collapse
  if (force === "close") {
    // Now set the button to collapsed
    theButton.setAttribute("aria-expanded", "false");
  // If the button is not expanded...
  } else if (theButton.getAttribute("aria-expanded") == "false") {
    // Now set the button to expanded
    theButton.setAttribute("aria-expanded", "true");
  // Otherwise button is not expanded...
  } else {
    // Now set the button to collapsed
    theButton.setAttribute("aria-expanded", "false");
  }
}



// Get the count for the disclosure button
var chkBoxen = Array.prototype.slice.call(document.querySelectorAll('#DisclosedGroup input'));
var totalChkBoxen = document.getElementById('DisclosureGroupCount');
var totalCheckedChkBoxen = document.getElementById('DisclosureGroupCheckCount');
totalChkBoxen.innerHTML = chkBoxen.length;

// attach event listeners
chkBoxen.forEach(function(chkBoxen) {
  chkBoxen.addEventListener('click',checkCheck);
});

// event handlers
function checkCheck(event) {
  var chkCount = document.querySelectorAll('#DisclosedGroup input:checked').length;
  totalCheckedChkBoxen.innerHTML = chkCount;
}


// Close disclosure on Esc
document.onkeydown = function(evt) {
  evt = evt || window.event;
  var isEscape = false;
  if ("key" in evt) {
    isEscape = evt.key == "Escape" || evt.key == "Esc";
  } else {
    isEscape = evt.keyCode == 27;
  }
  if (isEscape) {
    //alert("Escape");
    // hard-coding this because it is a demo
    toggleDisclosure("DisclosureGroupTrigger","close");
  }
};


// Close disclosure when focus leaves it
function handleNavFocusOut(event) {
  var navContainsFocus = this.contains(event.relatedTarget);
  if (!navContainsFocus) {
    // var button = this.querySelector('button[aria-controls]');
    // button && toggleDisclosure(button,"close");
    toggleDisclosure("DisclosureGroupTrigger","close");
  }
}

// attach focusout listener to the parent of disclosure button
var subNavContainers = Array.prototype.slice.call(document.querySelectorAll('body'));
subNavContainers.forEach(function(navContainer) {
  navContainer.addEventListener('focusout', handleNavFocusOut);
});

// Crappy PE effort on the disclosure
var discTrigger = document.getElementById('DisclosureGroupTrigger');
discTrigger.setAttribute('aria-expanded','false');
discTrigger.setAttribute('data-js','true');
              
            
!
999px

Console