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

              
                <!-- http://adrianroselli.com/2017/05/under-engineered-custom-radio-buttons-and-checkboxen.html -->

<h1>Under-Engineered Custom Radio Buttons and Checkboxen</h1>

<form action="#" autocomplete="off" method="get">
  <h2>Please fill out the things.</h2>
  <fieldset>
    <legend>Send Me Spam </legend>
    <div>
      <input type="radio" name="spam" id="spamY" value="me" checked> <label for="spamY">Please send me all the spam.</label>
    </div>
    <div>
      <input type="radio" name="spam" id="spamN" value="neighbor"> <label for="spamN">Please send it to my neighbor.</label>
    </div>
    <div>
      <input type="radio" name="spam" id="spamX" value="long"> <label for="spamX">Here is an option that is probably too long to fit on one line so it is an opportunity to test wrapping.</label>
    </div>
    <div>
      <input type="radio" name="spam" id="spamD" value="disabled" disabled> <label for="spamD">This one is disabled</label>
    </div>
  </fieldset>
  <div>
    <input type="checkbox" name="terms" id="terms"> <label for="terms">I have read your terms and they make no sense.</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="spamAnyway" id="spamAnyway" checked disabled> <label for="spamAnyway">Regardless of my choice above, sign me up for all your physical and electronical spam.</label>
  </div>
</form>


<form action="#" autocomplete="off" method="get" dir="rtl" lang="iw">
  <h2>אנא מלא את הדברים.</h2>
  <fieldset>
    <legend>שלח לי דואר זבל</legend>
    <div>
      <input type="radio" name="RTLspam" id="RTLspamY" value="me" checked> <label for="RTLspamY">אנא שלחו לי את כל הספאם.</label>
    </div>
    <div>
      <input type="radio" name="RTLspam" id="RTLspamN" value="neighbor"> <label for="RTLspamN">אנא שלחו אותו לשכני.</label>
    </div>
    <div>
      <input type="radio" name="RTLspam" id="RTLspamX" value="long"> <label for="RTLspamX">הנה אפשרות שכנראה ארוכה מכדי שתתאים לקו אחד ולכן זו הזדמנות לבחון עטיפה.</label>
    </div>
    <div>
      <input type="radio" name="RTLspam" id="RTLspamD" value="disabled" disabled> <label for="RTLspamD">זה מושבת</label>
    </div>
  </fieldset>
  <div>
    <input type="checkbox" name="RTLterms" id="RTLterms"> <label for="RTLterms">קראתי את התנאים שלך והם לא הגיוניים.</label>
  </div>
  <div>
    <input type="checkbox" name="RTLfreebies" id="RTLfreebies" disabled> <label for="RTLfreebies">אנא שלחו לי דברים בחינם.</label>
  </div>
  <div>
    <input type="checkbox" name="RTLspamAnyway" id="RTLspamAnyway" checked disabled> <label for="RTLspamAnyway">ללא קשר לבחירה שלי למעלה, הירשם אלי לכל ספאם הפיזי והאלקטרוני שלך.</label>
  </div>
</form>

<p>
  For the post <a href="http://adrianroselli.com/2017/05/under-engineered-custom-radio-buttons-and-checkboxen.html"><cite>Under-Engineered Custom Radio Buttons and Checkboxen</cite></a>.
</p>
              
            
!

CSS

              
                /* http://adrianroselli.com/2017/05/under-engineered-custom-radio-buttons-and-checkboxen.html */
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; */
  /*   font-size: 200%; */
  background-color: #fff;
  color: #101010;
}

/*-- forms --*/

form {
/*   background-color: #fff; */
  padding: .5em 2em;
}

form div {
  box-sizing: border-box;
  position: relative;
}

form > div,
form fieldset > div {
  margin: 1.5em 0;
}

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

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

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

/* Radios and checkboxen */

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

input[type=radio] + label,
input[type=checkbox] + label {
  display: block;
  padding: .5em;
  padding-left: 2em;
  max-width: calc(100% - 2em);
}

fieldset > div input[type=radio] + label {
  margin: -1em 0;
}

input[type=radio]:focus + label,
input[type=checkbox]:focus + label {
  color: #00f;
  outline: 1px dotted #00f;
}

input[type=radio] + label::before,
input[type=checkbox] + label::before {
  content: '';
  background: #fff;
  border: .1em solid rgba(0, 0, 0, .75);
  background-color: rgba(255, 255, 255, .8);
  display: block;
  box-sizing: border-box;
  float: left;
  width: 1em;
  height: 1em;
  margin-left: -1.5em;
  margin-top: .15em;
  vertical-align: top;
  cursor: pointer;
  text-align: center;
  transition: all .1s ease-out;
}

input[type=radio] + label::before {
  border-radius: 100%;
}

input[type=radio]:disabled + label::before,
input[type=checkbox]:disabled + label::before {
  border: .1em solid rgba(0, 0, 0, .1);
  background-color: rgba(0, 0, 0, .1);
}

input[type=radio]:disabled + label,
input[type=checkbox]:disabled + label {
  color: #ccc;
}

input[type=radio]:checked + label::before {
  background-color: #00f;
  box-shadow: inset 0 0 0 .15em rgba(255, 255, 255, .95);
}

input[type=checkbox] + label::after {
  display: block;
  content: '';
  position: absolute;
  top: .5em;
  left: .5em;
  width: 1em;
  height: 1em;
  transform: rotate(0deg);
  transition: all .1s ease-out;
}

input[type=checkbox]:checked + label::after {
  top: .4em;
  left: .7em;
  width: .4em;
  height: .8em;
  border-right: .25em solid #00f;
  border-bottom: .25em solid #00f;
  transform: rotate(45deg);
}

input[type=checkbox]:disabled + label::after {
  border: none;
}

input[type=checkbox]:checked:disabled + label::after {
  border-right: .25em solid #bbb;
  border-bottom: .25em solid #bbb;
}

/* RTL */

*[dir="rtl"] input[type=radio] + label,
*[dir="rtl"] input[type=checkbox] + label {
  padding-left: .5em;
  padding-right: 2em;
}

*[dir="rtl"] input[type=radio] + label::before,
*[dir="rtl"] input[type=checkbox] + label::before {
  float: right;
  margin-left: 0;
  margin-right: -1.5em;
}

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

*[dir="rtl"] input[type=checkbox]:checked + label::after {
  left: auto;
  right: .7em;
}

/* Dark mode */

@media screen and (prefers-color-scheme: dark) {
  body {
    background-color: #101010;
    color: #fff;
  }
  fieldset {
    border-color: rgba(255, 255, 255, .15);
  }
  input[type=radio]:focus + label,
  input[type=checkbox]:focus + label {
    color: #0ff;
    outline: 1px dotted #0ff;
  }
  input[type=radio] + label::before,
  input[type=checkbox] + label::before {
    background: #000;
    border-color: rgba(255, 255, 255, .75);
    background-color: rgba(0, 0, 0, .8);
  }
  input[type=radio]:disabled + label::before,
  input[type=checkbox]:disabled + label::before {
    border-color: rgba(255, 255, 255, .1);
    background-color: rgba(255, 255, 255, .1);
  }
  input[type=radio]:disabled + label,
  input[type=checkbox]:disabled + label {
    color: #555;
  }
  input[type=radio]:checked + label::before {
    background-color: #0ff;
    box-shadow: inset 0 0 0 .15em rgba(0, 0, 0, .95);
  }
  input[type=checkbox]:checked + label::after {
    border-right-color: #0ff;
    border-bottom-color: #0ff;
  }
  input[type=checkbox]:checked:disabled + label::after {
    border-right-color: #555;
    border-bottom-color: #555;
  }
}

/* WHCM */

@media screen and (-ms-high-contrast: active) {
  input[type=checkbox]:checked + label::after {
    border-right-color: windowText;
    border-bottom-color: windowText;
  }
/* Need to create an element because no shadows in WHCM */
/* -ms-high-contrast-adjust: none; does not do what we need */
  input[type=radio] + label::after {
    display: block;
    content: '';
    position: absolute;
    top: 1.05em;
    left: .9em;
    width: .2em;
    height: .2em;
    border: none;
    border-radius: 50%;
    background-color: transparent;
    transition: all .1s ease-out;
  }
  input[type=radio]:checked + label::after {
    top: .85em;
    left: .7em;
    width: .6em;
    height: .6em;
    background-color: windowText;
  }
  *[dir="rtl"] input[type=radio] + label::after {
    left: auto;
    right: .9em;
  }
  *[dir="rtl"] input[type=radio]:checked + label::after {
    left: auto;
    right: .7em;
  }
  input[type=checkbox]:disabled + label, input[type=checkbox]:disabled:checked + label::after, input[type=radio]:disabled + label {
    color: grayText;
    cursor: not-allowed;
    border-right-color: grayText;
    border-bottom-color: grayText;
  }
}

/* Print styles */

@media print {
  input[type=radio] + label::before,
  input[type=radio] + label::after,
  input[type=radio]:disabled + label,
  input[type=checkbox] + label::before,
  input[type=checkbox] + label::after,
  input[type=checkbox]:disabled + label {
    -webkit-print-color-adjust: exact;
    color-adjust: exact;
  }
}
              
            
!

JS

              
                
              
            
!
999px

Console