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

              
                <form class="form-example" method="post">
  <fieldset>
    <legend>Personal Information</legend>

    <label for="full-name">
      Full Name
      <span class="required">
        (required)
      </span>

      <span class="error-message">
        You must input a real name.
      </span>

      <input id="full-name" name="full-name" required="" type="text">

    </label>

    <label for="email">
      Email
      <span class="required">
        (required)
      </span>

      <span class="error-message">
        The email address you entered is not valid.
      </span>

      <input id="email" name="email" required="" type="email">

    </label>

  </fieldset>

  <fieldset>
    <legend>Credit Card Information</legend>

    <label for="cc">
      Credit Card Number
      <span class="required">
        (required)
      </span>

      <span class="error-message">
        Your credit card number should be all numbers.
      </span>

      <input id="cc" name="cc" required="" type="text" minlength='13' maxlength='20' pattern='\s*[0-9]+-?\s*[0-9]+-?\s*[0-9]+-?\s*[0-9]+-?\s*'>

    </label>
  </fieldset>

  <fieldset>
    <label for='text-comments'>
      Please leave your comments or questions here
      <span class="required">
        (required)
      </span>

      <span class="error-message">
        Please give us a little more information about your inquiry.
      </span>

      <textarea id='text-comments' required=''></textarea>
    </label>
  </fieldset>

  <fieldset>
    <legend id='legend-1'>Can we add you to our email mailing list? <span class="required">(required)</span></legend>

    <ul aria-labelledby='legend-1' role='radiogroup'>
      <li>
        <label for="yes">
          <span class="error-message">
            Please select yes or no.
          </span>

          <input id="yes" required="" type="radio" name="answers" value="yes">

          Yes
        </label>
      </li>
      <li>
        <label for="no">
          <input id="no" type="radio" name="answers" value="no">

          No
        </label>
      </li>
    </ul>
  </fieldset>

  <fieldset>
    <legend id='legend-2'>Which topics interest you? <span class="required">(required)</span></legend>

    <ul aria-labelledby='legend-2' role='group'>
      <li>
        <label for="science">
          <span class="error-message">
            Please select at least one category.
          </span>

          <input id="science" required="" type="checkbox" name="categories" value="science">

          Science
        </label>
      </li>
      <li>
        <label for="children-programs">
          <input id="children-programs" required="" type="checkbox" name="categories" value="children-programs">

          Programs for Children
        </label>
      </li>
      <li>
        <label for="new-events">
          <input id="new-events" required="" type="checkbox" name="categories" value="new-events">

          New Events
        </label>
      </li>
    </ul>
  </fieldset>

  <fieldset>
    <label for="options">Choose from the following:
      <span class="required">
        (required)
      </span>

      <span class="error-message">
        Please choose one of the following options.
      </span>
      <select name="options" id="options" required=''>
        <option value=''> Select </option>
        <option value="value1">Option A</option>
        <option value="value2">Option B</option>
        <option value="value3">Option C</option>
      </select>
    </label>
  </fieldset>

  <button class='form-example-submit' type="submit">Submit Form</button>
</form>
              
            
!

CSS

              
                input.edited:invalid {
  box-shadow: 0 0 5px 1px red;
}

input:focus:invalid {
  outline: none;
}
              
            
!

JS

              
                function handleFormSubmission(){
  $('.form-example input').on('keyup', function(e){
    $(this).addClass('edited');
  });

  $('.form-example [type="submit"]').on('click.formValidation', function(e){
    shouldPrevent = false;
    errorList = [];


    $form = $(this).parents('form');
    $inputs = $form.find('input[required], textarea[required], select[required]');

    $inputs.each(function(index, input){
      errorMessageSelector = 'label[for="' + $(input).attr('id') + '"] .error-message';
      $form.find(errorMessageSelector).removeAttr('aria-live');
      error = $form.find(errorMessageSelector);
      error.css('display', 'none');

      if(!input.validity.valid){
        error.css('display', 'inline-block');
        shouldPrevent = true;
        errorList.push(error);

      }
      else {
        error.css('display', 'none');
      }
    });

    if(!$form[0].checkValidity()){
      e.preventDefault();
      errorList[0].attr('aria-live', 'assertive');
    }
  });
}

$(document).ready(function(){
  handleFormSubmission();
});
              
            
!
999px

Console