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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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>Custom form controls</h1>
<p><em>You should use standard form controls whenever possible.</em> That said, here are examples of styled <b>checkbox</b> and <b>radio</b> inputs. Coming soonish: select (maybe).</p>
<form action="#" method="get">
  <fieldset>
    <legend>Checkbox</legend>
    <ol>
      <li>
        <input type="checkbox" id="cx1" checked /> <label for="cx1">One (checked)</label>
      </li>
      <li>
        <input type="checkbox" id="cx2" /> <label for="cx2">Two</label>
      </li>
      <li>
        <input type="checkbox" id="cx3" checked disabled /> <label for="cx3">Three (checked, disabled)</label>
      </li>
    </ol>
  </fieldset>
  <fieldset>
    <legend>Radio (enabled)</legend>
    <ol>
      <li>
        <input type="radio" name="re" id="re1" checked /> <label for="re1">One (checked)</label>
      </li>
      <li>
        <input type="radio" name="re" id="re2" /> <label for="re2">Two</label>
      </li>
    </ol>
  </fieldset>
  <fieldset>
    <legend>Radio (disabled)</legend>
    <ol>
      <li>
        <input type="radio" name="rd" id="rd1" disabled /> <label for="rd1">One</label>
      </li>
      <li>
        <input type="radio" name="rd" id="rd2" disabled checked /> <label for="rd2">Two (checked)</label>
      </li>
    </ol>
  </fieldset>
</form>
              
            
!

CSS

              
                *, ::before, ::after {
  box-sizing: border-box;
}

:root {
  font-family: Georgia, serif;
  font-size: 100%;
  line-height: 1.25;
}

h1 {
  font-size: 1.25rem;
  font-weight: normal;
  line-height: 1;
}

fieldset, h1, p {
  margin: 0 0 1.25rem;
}

ol {
  list-style-type: none;
  margin: 0;
  padding: 0;
}

/* don't mess with browsers that can't handle this stuff; note that the opacity support detection could be overkill */
@supports (transform: rotate(1turn)) and (opacity: 0) {
  :root {
    /* Choose names that are meaningful to you; these might not be the right ones. The same goes for colors; these might not be the right ones for you (or for anyone); they're arbitrary. */
    --borderColor: #666;
    --borderColorDisabled: #999;
    --checkColor: #1c0;
    --checkColorDisabled: #999;
  }
  
  input[type="checkbox"],
  input[type="radio"] {
    position: absolute;
    opacity: 0;
  }
  
  input[type="checkbox"] + label,
  input[type="radio"] + label {
    display: inline-block;
    min-height: 1rem;
    padding-left: 1.5rem;
    position: relative;
  }
  
  input[type="checkbox"] + label::before,
  input[type="radio"] + label::before {
    border: calc(2rem/16) solid var(--borderColor);
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    margin-top: -.5rem;
    height: 1rem;
    width: 1rem;
  }
  
  input[type="radio"] + label::before {
    background-color: #fff;
    border-radius: 1rem;
  }
  
  input[type="checkbox"]:focus + label::before,
  input[type="radio"]:focus + label::before {
    /* macOS default focus, change as needed, but be sure to include focus-specific styles! */
    box-shadow: 0 0 calc(2rem/16) calc(2rem/16) #7aacfe;
    outline: calc(2rem/16) solid transparent;
  }
  
  
  input[type="checkbox"]:checked + label::after,
  input[type="radio"]:checked + label::after {
    content: '';
    position: absolute;
    top: 50%;
    margin-top: -.25rem;
    height: .5rem;
  }
  
  input[type="checkbox"]:checked + label::after {
    border-top: calc(2rem/16) solid var(--checkColor);
    border-left: calc(2rem/16) solid var(--checkColor);
    left: .375rem;
    transform: rotate(.625turn);
    width: .25rem;
  }
  
  input[type="radio"]:checked + label::after {
    background-color: var(--checkColor);
    border-radius: 1rem;
    left: .25rem;
    width: .5rem;
  }
  
  input[type="checkbox"]:disabled + label::before,
  input[type="radio"]:disabled + label::before {
    border-color: var(--borderColorDisabled);
  }
  
  input[type="checkbox"]:checked:disabled + label::after {
    border-color: var(--checkColorDisabled);
  }
  
  input[type="radio"]:checked:disabled + label::after {
    background-color: var(--checkColorDisabled);
  }
}
              
            
!

JS

              
                document.querySelector('form').addEventListener('submit', event => {
  event.preventDefault();
  event.stopPropagation(); // just in case :D
});

/* future
const singleSelects = document.querySelectorAll('select:not([multiple])');
*/
              
            
!
999px

Console