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

              
                <div style="margin: 2em auto; max-width: 400px;">

  <form novalidate>

    <div class="input-wrap">
      <label for="n">
        Name (not required):
      </label>
      <input type="text" id="n" class="txt-field" aria-describedby="n_msg">
      <span id="n_msg">Try not to be clever</span>
    </div>

    <div class="input-wrap">
      <label for="e">
        Email:
      </label>
      <input type="email" id="e" class="txt-field" aria-invalid="false" required data-error="e_msg" aria-describedby="e_msg" data-msg="Your email is required.">
      <span id="e_msg"></span>
    </div>

    <div class="input-wrap">
      <label for="num">
        Number:
      </label>
      <input type="number" id="num" class="txt-field" aria-invalid="false" required data-error="nu_msg" aria-describedby="nu_msg" data-msg="A numeric value must be entered.">
      <span id="nu_msg"></span> 
    </div>

    <div class="input-wrap">
      <label for="rn2">
        Name (no default invalid false):
      </label>
      <input type="text" id="rn2" class="txt-field" data-error="rn2_mess" aria-describedby="rn2_mess" data-msg="Your name is required." required>
      <span id="rn2_mess"></span>
    </div>


    <div class="input-wrap">
      <label for="rn2bbb">
        Name:
      </label> <span id="help">(first and last)</span>
      <input type="text" id="rn2bbb" class="txt-field" data-error="rn2bbb_mess" aria-describedby="rn2bbb_mess help" data-msg="Your name is required." required aria-invalid="false">
      <span id="rn2bbb_mess"><!-- populate error message here as needed --></span>
    </div>


    <div class="input-wrap">
      <label for="rn">
        Name:
      </label>
      <input type="text" id="rn" class="txt-field" aria-invalid="false" data-error="rn_mess" aria-describedby="rn_mess" data-msg="Your name is required." required>
      <span id="rn_mess"></span>
    </div>

    <div class="input-wrap">
      <label for="req_mess">
        Message (req):
      </label>
      <textarea id="req_mess" class="txt-field" data-msg="You must enter a message." aria-invalid="false" data-error="rmess_msg" aria-describedby="rmess_msg" required></textarea>
      <span id="rmess_msg"></span>
    </div>

    <button style="margin-top: 2em;
                   border: 2px solid;
                   padding: .5em 2em;
                   font-size: inherit;"
            id="s">Test</button>
  </form>

</div> 
              
            
!

CSS

              
                html,
body {
  background: #fcfcfc;
  font-family: arial;
  font-size: 100%;
  margin: 0;
  padding: 0;
}

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

body {
  line-height: 1.4;
}

.input-wrap:not(:first-of-type) {
  margin-top: 1.5em;
}

.txt-field {
  border: 1px solid #63738a;
  box-shadow: none;
  font-size: inherit;
  padding: .5em;
  width: 100%;
}

.txt-field[disabled] {
  background: #e8ebf0;
}

.txt-field[readonly] {
  background: #fafafa;
}

.txt-field:hover:not([disabled]) {
  outline: 1px solid #63738a;
}

.txt-field:focus {
  border-color: #0062b2;
  outline: 1px solid #0062b2;
}

.txt-field[aria-invalid="true"]:invalid:not(:focus) {
  border-color: #d6312b;
  outline: 1px solid #d6312b;
}

.txt-field[aria-invalid="true"] + span {
  color: red;
  font-weight: bold;
}


textarea.txt-field {
  resize: vertical;
  max-height: 10em;
  min-height: 4em;
}

              
            
!

JS

              
                (function () {
  var fields = document.querySelectorAll('.txt-field[required]');

  var checkIt = function ( e ) {
    var msg;

    if ( this.hasAttribute('data-msg') ) {
      msg = document.getElementById(this.getAttribute('data-error'));
    }

    if ( this.required && this.validity.valid ) {
      this.setAttribute('aria-invalid', 'false');
      msg.innerHTML = '';
      this.removeEventListener('keyup', checkIt, false);
    }
    else if ( this.required && !this.validity.valid  ) {
      this.setAttribute('aria-invalid', 'true');
      msg.innerHTML = this.getAttribute('data-msg');
      this.addEventListener('keyup', checkIt, false);
    }

  };


  for ( var i = 0; i < fields.length; i++ ) {
    fields[i].addEventListener('blur', checkIt, false);
  }
})();
              
            
!
999px

Console