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

              
                <h1>Toggles</h1>

<fieldset>
  <legend>Checkbox</legend>
  <div>
    <input type="checkbox" id="ck01" checked>
    <label for="ck01">Hammer</label>
  </div>
  <div>
    <input type="checkbox" id="ck02">
    <label for="ck02">Sandwich</label>
  </div>
  <div>
    <input type="checkbox" id="ck03">
    <label for="ck03">Animal</label>
  </div>
</fieldset>

<fieldset>
  <legend>Button with <code>aria-pressed</code></legend>
  <button type="button" id="b01" aria-pressed="true" onclick="toggle(this.id);">Hot Dog</button>
  <button type="button" id="b02" aria-pressed="false" onclick="toggle(this.id);">Drill</button>
  <button type="button" id="b03" aria-pressed="mixed" onclick="toggle(this.id);">Vegetable</button>
</fieldset>

<fieldset>
  <legend>Checkbox with <code>switch</code> role</legend>
  <div>
    <input type="checkbox" id="ck01s" role="switch" checked>
    <label for="ck01s">Taco</label>
  </div>
  <div>
    <input type="checkbox" id="ck02s" role="switch">
    <label for="ck02s">Wrench</label>
  </div>
  <div>
    <input type="checkbox" id="ck03s" role="switch">
    <label for="ck03s">Mineral</label>
  </div>
</fieldset>

<fieldset>
  <legend>Button with <code>aria-checked</code> and <code>switch</code> role</legend>
  <button type="button" id="b01s" aria-checked="true" role="switch" onclick="toggle(this.id);">Panino</button>
  <button type="button" id="b02s" aria-checked="false" role="switch" onclick="toggle(this.id);">Pliers</button>
  <button type="button" id="b03s" aria-checked="mixed" role="switch" onclick="toggle(this.id);">General</button>
</fieldset>

<p>
  This pen is used in the post <cite><a href="https://adrianroselli.com/2021/10/switch-role-support.html" target="_top">Switch Role Support</a></cite>.
</p>
              
            
!

CSS

              
                body {
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto,
    Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  line-height: 1.5;
}

button {
  font: inherit;
}

[aria-pressed], [aria-checked] {
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg height='100' width='100' xmlns='http://www.w3.org/2000/svg' xml:space='preserve' viewBox='0 0 333 333' fill-rule='evenodd' clip-rule='evenodd' shape-rendering='geometricPrecision' text-rendering='geometricPrecision' image-rendering='optimizeQuality'%3E%3Cpath d='M167 33c73 0 133 60 133 134 0 73-60 133-133 133-74 0-134-60-134-133C33 93 93 33 167 33zM96 80l158 158c16-20 25-44 25-71 0-62-50-113-112-113-27 0-52 10-71 26zm142 174L80 96c-16 19-26 44-26 71 0 62 51 112 113 112 27 0 51-9 71-25z' fill-rule='nonzero'/%3E%3C/svg%3E");
  padding-left: 2em;
  background-repeat: no-repeat;
  background-size: auto 90%;
  background-position: .25em 50%;
}

[aria-pressed="mixed"], [aria-checked="mixed"] {
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg height='100' width='100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M16 996.36v12h68v-12z' style='text-indent:0;text-transform:none;block-progression:tb' overflow='visible' color='%23000' transform='translate(0 -952.36)'/%3E%3C/svg%3E");
}

[aria-pressed="true"], [aria-checked="true"] {
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg height='100' width='100' xmlns='http://www.w3.org/2000/svg' xml:space='preserve'%3E%3Cpath d='m74.6 38.4.5-.4-6-6-26.4 26.3-11.8-11.8-6 5.9 17.8 17.8z'/%3E%3Cpath d='M50 96.1c25.5 0 46.1-20.7 46.1-46.1C96.1 24.5 75.5 4 50 4S4 24.5 4 50c0 25.3 20.5 46.1 46 46.1zM50 9c22.6 0 41 18.4 41 41S72.6 91 50 91 9 72.6 9 50 27.4 9 50 9z'/%3E%3C/svg%3E");
}
              
            
!

JS

              
                // This is only to set a checkbox to indeterminate state.
document.getElementById("ck03").indeterminate = "true";
document.getElementById("ck03s").indeterminate = "true";

// Toggle the thingers
function toggle(btnID) {
  var theControl = document.getElementById(btnID);
  if (theControl.getAttribute("role")) {
    if (theControl.getAttribute("aria-checked") == "true") {
      theControl.setAttribute("aria-checked", "false");
    } else {
      theControl.setAttribute("aria-checked", "true");
    }
  } else {
    if (theControl.getAttribute("aria-pressed") == "true") {
      theControl.setAttribute("aria-pressed", "false");
    } else {
      theControl.setAttribute("aria-pressed", "true");
    }
  }
}

              
            
!
999px

Console