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

              
                <h1>Dynamic Accessible Names</h1>

<p>
  This sounds exciting because of the word <em>dynamic</em>, but it is not. Used in my post <a href="https://adrianroselli.com/2020/12/be-careful-with-dynamic-accessible-names.html"><cite>Be Careful with Dynamic Accessible Names</cite></a>.
</p>

<form>
  <div>
    <h2>Form Fields</h2>
    <div>
      <label for="Fnafn" id="lblFnafn" data-1="First Name" data-0="Close Enough" data-AccName="node">First Name</label>
      <input type="text" name="Fnafn" id="Fnafn" onblur="swapAccName('lblFnafn');">
    </div>
    <div>
      <label for="Comments" id="lblComments" data-1="Comments" data-0="Ignored" data-AccName="node">Comments</label>
      <textarea name="Comments" id="Comments" onblur="swapAccName('lblComments');"></textarea>
    </div>
    <div>
      <label for="State" id="lblState" data-1="State" data-0="Province" data-AccName="node" onblur="swapAccName('lblState');">State</label>
      <select name="State" id="State" onblur="swapAccName('lblState');">
        <option>Denial</option>
        <option>Your Name for the Record</option>
        <option>of the Union</option>
        <option>Puerto Rico</option>
      </select>
    </div>
    <fieldset>
      <legend>Spam</legend>
      <div>
        <input type="radio" name="Spam" id="SpamY" onblur="swapAccName('lblSpamY');">
        <label for="SpamY" id="lblSpamY" class="inline" data-1="Sign me up for spam." data-0="Signed up regardless." data-AccName="node">Sign me up for spam.</label>
      </div>
      <div>
        <input type="radio" name="Spam" id="SpamN" onblur="swapAccName('lblSpamN');">
        <label for="SpamN" id="lblSpamN" class="inline" data-1="Sign her up for spam." data-0="Also signed up regardless." data-AccName="node">Sign her up for spam.</label>
      </div>
    </fieldset>
    <div>
      <input type="checkbox" name="Terms" id="Terms" onblur="swapAccName('lblTerms');">
      <label for="Terms" id="lblTerms" class="inline" data-1="Agree to Terms &amp; Conditions." data-0="Agreed no matter what you choose." data-AccName="node">Agree to Terms &amp; Conditions.</label>
    </div>
    <div>
      <input type="submit" id="PlainSubmit" value="Submit" onclick="alert('input submit');return false;" data-1="Submit" data-0="Done" data-AccName="value" onblur="swapAccName(this.id);">
    </div>
  </div>

  <div>
    <h2>Controls</h2>
    <div>
      This is an <a href="http://example.com/?1" data-1="example link to nowhere" data-0="unnecessary link" data-AccName="node" id="PlainLink" onblur="swapAccName(this.id);">example link to nowhere</a>.
    </div>
    <div>
      <button type="button" id="PlainButton" data-1="Launch" data-0="Abort" data-AccName="node" onblur="swapAccName(this.id);">Launch</button>
    </div>
    <div>
      <button type="button" id="CloseButton" data-1="Close" data-0="Really Close" data-AccName="alabel" onblur="swapAccName(this.id);" aria-label="Close">&times;</button>
    </div>
    <div>
      <button type="button" onblur="swapAccName('ImgButton');">
        <img src="https://www.fillmurray.com/30/30" alt="Dr. Peter Venkman" id="ImgButton" data-1="Dr. Peter Venkman" data-0="Carl Spackler" data-AccName="alt">
      </button>
    </div>
    <div>
      <button type="button" id="btnDisc01" aria-expanded="false" onclick="toggleDisclosure(this.id);" aria-controls="Disclosed01" onblur="swapAccName('lblbtnDisc01');">
        <span>
          <svg xmlns="\http://www.w3.org/2000/svg&quot;" viewBox="0 0 80 80" focusable="false">
            <path d="M70.3 13.8L40 66.3 9.7 13.8z"></path>
          </svg>
        </span>
        <strong data-1="Show Me" data-0="Wasted My Time" data-AccName="node" id="lblbtnDisc01">Show Me</strong>
      </button>
      <div id="Disclosed01" class="disclosee">
        <p>
          Here is some disclosed content. <span aria-hidden="true">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</span>
        </p>
      </div>
    </div>
    <div>
      <button type="button" id="btnDisc02" aria-expanded="false" onclick="toggleDisclosure(this.id);" aria-controls="Disclosed02" onblur="swapAccName('FrigginSVG');">
        <span>
          <svg xmlns="\http://www.w3.org/2000/svg&quot;" viewBox="0 0 80 80" focusable="false" role="image" aria-label="Pointing Right" data-1="Pointing Right" data-0="Now It Is Down" data-AccName="alabel" id="FrigginSVG">
            <path d="M70.3 13.8L40 66.3 9.7 13.8z"></path>
          </svg>
        </span>
      </button>
      <div id="Disclosed02" class="disclosee">
        <p>
          Here is some disclosed content. <span aria-hidden="true">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</span>
        </p>
      </div>
    </div>
    <div class="toggles">
      <button type="button" id="alerts" aria-pressed="false" onclick="toggle(this.id);" data-1="Push alerts to my browser." data-0="Aw crap, undo those alerts." data-AccName="node" onblur="swapAccName(this.id);">
        Push alerts to my browser.
      </button>
    </div>
    <div>
      <span id="LeftAlt">Left Text</span>
      <button type="button" id="RefButton" data-1="LeftAlt" data-0="RightAlt" data-AccName="labelled" onblur="swapAccName(this.id);" aria-labelledby="LeftAlt">&gt;&lt;</button>
      <span id="RightAlt">East Text</span>
    </div>
  </div>

</form>
              
            
!

CSS

              
                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; */
}

:focus {
  outline: .5em solid rgba(0,0,255,.25);
  outline-offset: .2em;
}

/*-- forms --*/

form {
  padding: 0.5em 0;
  display: grid;
  grid-template-columns: repeat(2, [col] 1fr );
}

form div {
  box-sizing: border-box;
  position: relative;
  margin: 1em 0;
}

form > div {
  margin: 0 1em;
}

/* form > div, */
form fieldset > div {
  margin: .5em 0;
}

form fieldset > div:first-of-type {
  margin-top: .5em;
}

form fieldset > div:last-of-type {
  margin-bottom: 1em;
}

fieldset {
  border: .1em solid rgba(0, 0, 0, .15);
  padding: 0 1em;
  margin: 1em 0 1em 0;
}

label {
  display: block;
  margin: 0.25em 0 0 0;
}

label.inline {
  display: inline-block;
}

button, input[type=submit] {
  font: inherit;
}

button, input[type=submit] {
  -webkit-appearance: button;
}

/* All the CSS needed to make disclosures work */

button[aria-expanded="false"] + div {
  display: none;
}

/* END All the CSS needed to make disclosures work */

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

button[aria-expanded] span {
  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 span,
button[aria-expanded]:focus span {
  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);
}

.disclosee {
  padding: .25em .75em;
  border: .1em solid #ddd;
  background-color: #fff;
  margin-top: -.1em;
}

/* Toggles */

.toggles [aria-pressed] {
  display: block;
  box-sizing: border-box;
  border: none;
  color: inherit;
  background: none;
  font: inherit;
  line-height: inherit;
  text-align: left;
  padding: .4em 0 .4em 4em;
/*   position: relative; */
}

.toggles [aria-pressed][disabled],
.toggles [aria-pressed][disabled]:hover {
  color: #999;
}

.toggles [aria-pressed]:focus,
.toggles [aria-pressed]:hover {
  color: #00f;
  outline: none;
}

.toggles [aria-pressed]:focus::before,
.toggles [aria-pressed]:hover::before {
  box-shadow: 0 0 0.5em #333;
}

.toggles [aria-pressed]:focus::after,
.toggles [aria-pressed]:hover::after {
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='50' cy='50' r='50' fill='rgba(0,0,0,.25)'/%3E%3C/svg%3E");
  background-size: 30%;
  background-repeat: no-repeat;
  background-position: center center;
}

.toggles [aria-pressed]::before,
.toggles [aria-pressed]::after {
  content: "";
  position: absolute;
  height: 1.5em;
  transition: all 0.25s ease;
}

.toggles [aria-pressed]::before {
  left: 0;
  top: 0.2em;
  width: 3em;
  border: 0.2em solid #767676;
  background: #767676;
  border-radius: 1.1em;
}

.toggles [aria-pressed]::after {
  left: 0;
  top: 0.25em;
  background-color: #fff;
  background-position: center center;
  border-radius: 50%;
  width: 1.5em;
  border: 0.15em solid #767676;
}

.toggles [aria-pressed=true]::after {
  left: 1.6em;
  border-color: #36a829;
  color: #36a829;
}

.toggles [aria-pressed=true]::before {
  background-color: #36a829;
  border-color: #36a829;
}

.toggles [aria-pressed][disabled]::before {
  background-color: transparent;
  border-color: #ddd;
}

.toggles [aria-pressed][disabled]::after {
  border-color: #ddd;
}

.toggles [aria-pressed][disabled]:hover {
  color: #999; /* case for CSS custom property if not supporting IE/Edge */
}

.toggles [aria-pressed][disabled]:hover::before {
  box-shadow: none;
}

.toggles [aria-pressed][disabled]:hover::after {
  background-image: none;
}
              
            
!

JS

              
                function toggleDisclosure(btnID) {
  // Get the button that triggered this
  var theButton = document.getElementById(btnID);
  // If the button is not expanded...
  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");
  }
}

function toggle(btnID) {
  var theButton = document.getElementById(btnID);
  if (theButton.getAttribute("aria-pressed") == "false") {
    theButton.setAttribute("aria-pressed", "true");
  } else {
    theButton.setAttribute("aria-pressed", "false");
  }
}

function swapAccName(accNameId) {
  var accNameNode = document.getElementById(accNameId);
  var accName1 = accNameNode.getAttribute("data-1");
  var accName0 = accNameNode.getAttribute("data-0");
  var accNameType = accNameNode.getAttribute("data-AccName");
  if (accNameType == "node") {
    if (accNameNode.innerText == accName1) {
      accNameNode.innerText = accName0;
    } else {
      accNameNode.innerText = accName1;
    }
  } else if (accNameType == "value") {
    if (accNameNode.value == accName1) {
      accNameNode.value = accName0;
    } else {
      accNameNode.value = accName1;
    }
  } else if (accNameType == "alt") {
    if (accNameNode.alt == accName1) {
      accNameNode.alt = accName0;
    } else {
      accNameNode.alt = accName1;
    }
  } else if (accNameType == "labelled") {
    if (accNameNode.getAttribute("aria-labelledby") == accName1) {
      accNameNode.setAttribute("aria-labelledby", accName0);
    } else {
      accNameNode.setAttribute("aria-labelledby", accName1);
    }
  } else  { //if (accNameType == "alabel")
    if (accNameNode.getAttribute("aria-label") == accName1) {
      accNameNode.setAttribute("aria-label", accName0);
    } else {
      accNameNode.setAttribute("aria-label", accName1);
    }
  // } else {
  //   console.log("Problem.\n\naccNameId: " + accNameId + ",\naccNameType: " + accNameType + ",\naccName1: " + accName1 + ",\naccName0: " + accName0);
  }
}
              
            
!
999px

Console