123

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <form>
  <fieldset class="toggles">
    <legend>Toggles</legend>
    <div>
      <input type="checkbox" name="alerts" id="alerts">
      <label for="alerts">Push alerts to my browser.</label>
    </div>
    <div>
      <input type="checkbox" name="freebies" id="freebies" disabled>
      <label for="freebies">Please send me free things.</label>
    </div>
    <div>
      <input type="checkbox" name="terms" id="terms" checked>
      <label for="terms">I have read your terms and they make no sense.</label>
    </div>
    <div>
      <input type="checkbox" name="indd" id="indd" disabled>
      <label for="indd">This one is indeterminate.</label>
    </div>
  </fieldset>

  <fieldset class="toggles flip">
    <legend>Flipped Toggles</legend>
    <div>
      <input type="checkbox" name="wifi" id="wifi">
      <label for="wifi">Wifi</label>
    </div>
    <div>
      <input type="checkbox" name="cell" id="cell" checked disabled>
      <label for="cell">Cellular service</label>
    </div>
    <div>
      <input type="checkbox" name="bluetooth" id="bluetooth" checked>
      <label for="bluetooth">Bluetooth</label>
    </div>
    <div>
      <input type="checkbox" name="airplane" id="airplane">
      <label for="airplane">Airplane mode</label>
    </div>
  </fieldset>
</form>

<form dir="rtl">
  <fieldset class="toggles flip" lang="ur">
    <legend>Flipped RTL Toggles</legend>
    <div>
      <input type="checkbox" name="RTLwifi" id="RTLwifi">
      <label for="RTLwifi">وائی فائی</label>
    </div>
    <div>
      <input type="checkbox" name="RTLcell" id="RTLcell" checked disabled>
      <label for="RTLcell">سیلولر سروس</label>
    </div>
    <div>
      <input type="checkbox" name="RTLbluetooth" id="RTLbluetooth" checked>
      <label for="RTLbluetooth">بلوٹوتھ</label>
    </div>
    <div>
      <input type="checkbox" name="RTLairplane" id="RTLairplane">
      <label for="RTLairplane">ہوائی جہاز موڈ</label>
    </div>
  </fieldset>
  
  <fieldset class="toggles" lang="iw">
    <legend>RTL Toggles</legend>
    <div>
      <input type="checkbox" name="RTLalerts" id="RTLalerts">
      <label for="RTLalerts">לחץ על התראות לדפדפן שלי.</label>
    </div>
    <div>
      <input type="checkbox" name="RTLfreebies" id="RTLfreebies" disabled>
      <label for="RTLfreebies">אנא שלח לי דברים בחינם.</label>
    </div>
    <div>
      <input type="checkbox" name="RTLterms" id="RTLterms" checked>
      <label for="RTLterms">קראתי את התנאים שלך והם לא הגיוני.</label>
    </div>
    <div>
      <input type="checkbox" name="RTLindd" id="RTLindd" disabled>
      <label for="RTLindd">זה לא מוגדר.</label>
    </div>
  </fieldset>
</form>

<p>
  For the post <cite><a href="http://adrianroselli.com/2019/03/under-engineered-toggles.html">Under-Engineered Toggles</a></cite>.
</p>
            
          
!
            
              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; */
}

form {
  background-color: #fff;
  padding: 1em 2em;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: flex-start;
}

fieldset {
  margin: 1em;
  flex: 1 0 10em;
}

fieldset.toggles div {
  box-sizing: border-box;
  position: relative;
}

fieldset.toggles > div {
  margin: 1.5em 0;
}

fieldset.toggles > div:first-of-type {
  margin-top: 1em;
}

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

fieldset.toggles {
  border: 0.1em solid rgba(0, 0, 0, 0.15);
}

.toggles [disabled] + label,
.toggles [disabled]:hover + label {
  color: #999;
}

.toggles [type="checkbox"] {
  position: absolute;
  top: auto;
  overflow: hidden;
  clip: rect(1px, 1px, 1px, 1px);
  width: 1px;
  height: 1px;
  white-space: nowrap;
}

.toggles [type="checkbox"] + label {
  display: block;
  position: relative;
  padding: 0.5em;
  padding-left: 4em;
  max-width: calc(100% - 2em);
}

.toggles [type="checkbox"]:focus + label,
.toggles [type="checkbox"]:hover + label {
  color: #00f;
}

.toggles [type="checkbox"]:focus + label::before,
.toggles [type="checkbox"]:hover + label::before {
  box-shadow: 0 0 0.5em #333;
}

.toggles [type="checkbox"]:focus + label::after,
.toggles [type="checkbox"]:hover + label::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 [type="checkbox"] + label::before,
.toggles [type="checkbox"] + label::after {
  content: "";
  position: absolute;
  height: 1.5em;
  transition: all 0.25s ease;
}

.toggles [type="checkbox"] + label::before {
  left: 0;
  top: 0.2em;
  width: 3em;
  border: 0.2em solid #767676;
  background: #767676;
  border-radius: 1.1em;
}

.toggles [type="checkbox"] + label::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 [type="checkbox"]:checked + label::after {
  left: 1.6em;
  border-color: #36a829;
  color: #36a829;
}

.toggles [type="checkbox"]:indeterminate + label::after {
  left: 0.8em;
}

.toggles [type="checkbox"]:indeterminate + label::before {
  background-color: #ddd;
}

.toggles [type="checkbox"]:checked + label::before {
  background-color: #36a829;
  border-color: #36a829;
}

.toggles [type="checkbox"][disabled] + label::before {
  background-color: transparent;
  border-color: #ddd;
}

.toggles [type="checkbox"][disabled] + label::after {
  border-color: #ddd;
}

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

.toggles [type="checkbox"][disabled]:hover + label::before {
  box-shadow: none;
}

.toggles [type="checkbox"][disabled]:hover + label::after {
  background-image: none;
}

/* Put toggles on the right like the iOS the kids like */

.toggles.flip [type="checkbox"] + label::before,
.toggles.flip [type="checkbox"] + label::after {
  left: auto;
  right: 0;
}

.toggles.flip [type="checkbox"] + label::after {
  left: auto;
  right: 1.6em;
}

.toggles.flip [type="checkbox"]:checked + label::after {
  right: 0;
}

.toggles.flip [type="checkbox"]:indeterminate + label::after {
  right: 0.8em;
}

.toggles.flip [type="checkbox"] + label {
  padding-left: 0;
  padding-right: 4em;
}

/* Windows High Contrast Mode Support */
@media screen and (-ms-high-contrast: active) {
  .toggles [type="checkbox"]:focus + label::before,
  .toggles [type="checkbox"]:hover + label::before {
    outline: 1px dotted windowText;
    outline-offset: 0.25em;
  }
  .toggles [type="checkbox"] + label::after {
    background-color: windowText;
  }
  .toggles [type="checkbox"][disabled] + label::after {
    background-color: transparent;
  }
}

/* Reduced motion */
@media screen and (prefers-reduced-motion: reduce) {
  .toggles [type="checkbox"] + label::before,
  .toggles [type="checkbox"] + label::after {
    transition: none;
  }
}

/* Dark mode */
@media screen and (prefers-color-scheme: dark) {
  form {
    background-color: #101010;
  }
  .toggles {
    color: #fff;
  }
  fieldset.toggles {
    border: 0.1em solid rgba(255, 255, 255, 0.15);
  }
  .toggles [type="checkbox"]:focus + label,
  .toggles [type="checkbox"]:hover + label {
    color: #99f;
  }
  .toggles [type="checkbox"] + label::before {
    border-color: #808080;
    background: #808080;
  }
  .toggles [type="checkbox"] + label::after {
    background-color: #101010;
  }
  .toggles [type="checkbox"]:not([disabled]):indeterminate + label::before {
    background-color: #444;
  }
  .toggles [type="checkbox"]:focus + label::after,
  .toggles [type="checkbox"]:hover + label::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(255,255,255,.25)'/%3E%3C/svg%3E");
  }
  .toggles [type="checkbox"][disabled] + label::before,
  .toggles [type="checkbox"][disabled] + label::after {
    border-color: #555;
  }
}

/* RTL */
/* https://twitter.com/dror3go/status/1102946375396982784 */
*[dir="rtl"] .toggles [type="checkbox"] + label {
  padding-left: 0;
  padding-right: 4em;
}

*[dir="rtl"] .toggles [type="checkbox"] + label::before,
*[dir="rtl"] .toggles [type="checkbox"] + label::after {
  left: auto;
  right: 0;
}

*[dir="rtl"] .toggles [type="checkbox"] + label::after {
  right: 0;
}

*[dir="rtl"] .toggles [type="checkbox"]:checked + label::after {
  right: 1.6em;
}

*[dir="rtl"] .toggles [type="checkbox"]:indeterminate + label::after {
  right: 0.8em;
}

/* Put toggles on the right like the iOS the kids like */

*[dir="rtl"] .toggles.flip [type="checkbox"] + label::before,
*[dir="rtl"] .toggles.flip [type="checkbox"] + label::after {
  left: 0;
  right: auto;
}

*[dir="rtl"] .toggles.flip [type="checkbox"] + label::after {
  right: auto;
  left: 1.6em;
}

*[dir="rtl"] .toggles.flip [type="checkbox"]:checked + label::after {
  left: 0;
}

*[dir="rtl"] .toggles.flip [type="checkbox"]:indeterminate + label::after {
  left: 0.8em;
}

*[dir="rtl"] .toggles.flip [type="checkbox"] + label {
  padding-right: 0;
  padding-left: 4em;
}

/* Print styles */
@media print {
  .toggles [type="checkbox"] + label::before,
  .toggles [type="checkbox"] + label::after,
  .toggles [type="checkbox"][disabled] + label {
    -webkit-print-color-adjust: exact;
    color-adjust: exact;
  }
}
            
          
!
            
              // This is NOT needed for these styles to work,
// only to set a checkbox to indeterminate state.
// document.getElementById('ind').indeterminate='true';
document.getElementById('indd').indeterminate='true';
document.getElementById('airplane').indeterminate='true';
document.getElementById('RTLindd').indeterminate='true';
document.getElementById('RTLairplane').indeterminate='true';
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console