cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

  <div class="left-column">
    <p id="message">
      <span class="bad">Some fields were not completed properly.</span>
      <span class="good">Form is ready to send.</span>
    <p>Fill in the form and check for errors. While filling the form, note the 2px indicator to the right of the form. The indicator will turn green when the required conditions have been met.</p>
    <button id="error-trigger" type="button">Check Errors</button> 
  <h1>HTML5 Validation</h1>
  <label for="name">Name - <em>Cannot be empty</em></label>
  <input id="name" type="text" required>
  <label for="email">Email - <em>Must be valid email from 'specific-domain.com'</em></label>
  <input id="email" type="email" required pattern="^[A-Za-z0-9._%+-]+@specific-domain.com$">
  <label for="phone">Phone - <em>Accepts Intl and USA formats (+99(99)9999-9999 or 999-999-9999)</em></label>
  <input id="phone" type="text" required pattern="[\+]\d{2}[\(]\d{2}[\)]\d{4}[\-]\d{4}|\d{3}[\-]\d{3}[\-]\d{4}">
  <label for="form-message">Message - <em>Send a message or not, whatever</em></label>
  <textarea id="form-message"></textarea> 

              $success: #007621;
$required: #B00000;
$error: #DC0809;
$black: #000000;
$grey: #aaaaaa;

html, body{
  font-family: Helvetica, Arial, sans-serif;

body {
  background: rgb(244,239,241);
  background: -moz-radial-gradient(center, ellipse cover,  rgba(244,239,241,1) 0%, rgba(223,210,247,1) 100%);
  background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%,rgba(244,239,241,1)), color-stop(100%,rgba(223,210,247,1)));
  background: -webkit-radial-gradient(center, ellipse cover,  rgba(244,239,241,1) 0%,rgba(223,210,247,1) 100%);
  background: -o-radial-gradient(center, ellipse cover,  rgba(244,239,241,1) 0%,rgba(223,210,247,1) 100%);
  background: -ms-radial-gradient(center, ellipse cover,  rgba(244,239,241,1) 0%,rgba(223,210,247,1) 100%);
  background: radial-gradient(ellipse at center,  rgba(244,239,241,1) 0%,rgba(223,210,247,1) 100%);
  filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f4eff1', endColorstr='#dfd2f7',GradientType=1 );

.left-column {

form {

label {

textarea {
  border: 1px solid $grey;
  padding: 5px;
  transition:border-color 500ms;
  /* Mark required fields */
  &:required {
  border-right: 2px solid $required;
  :required:valid will change the red required mark to green when requirement is met.
  good for input patterns:
  &:required:valid {
  border-right: 2px solid $success;
  &.error {
    border: 1px solid $error;
  &:focus {
    outline: 0 none;

/* Laser beam */
.error-line {
  height: 0;
  position: absolute;
  width: 1px;
  background-color: $error;
  z-index: 1000;
  transform-origin: top left;
  transition: height 300ms;

#message {
  background-color: $success;
  color: #fff;
  padding: 10px;
    display: none;
    background-color: $error;
      display: block;
    .good {display: none;}

em {
  font-size: small;

              var $message = $(document.getElementById('message'));

// Handle validation errors
if ($message.length) {


// FIRE!
function triggerLasers() {
    console.log('pew pew');
    var errorDelay = 250,
        $invalidFields = $('input:required:invalid'),
        hasErrors = !!$invalidFields.length;
    if (hasErrors) {

        // select required fields that are currently invalid
        $invalidFields.each(function() {
            var error = $(this);
            setTimeout(function() {
            }, errorDelay);
            errorDelay += 250;

    $message.toggleClass('error', hasErrors);


// Show fields with validation errors
function linkErrors(error) {
    var linkLine = $(document.createElement('div')).addClass('error-line').appendTo('body'),
        $messageOffset = $message.offset(),
        errorOffset = error.offset();

    $messageOffset.left += $message.outerWidth();
    $messageOffset.top += $message.outerHeight();

    var originX = $messageOffset.left,
        originY = $messageOffset.top - 2,
        lineLength = Math.sqrt((errorOffset.left - originX) * (errorOffset.left - originX) + (errorOffset.top - originY) * (errorOffset.top - originY)),
        angle = 180 / 3.1415 * Math.acos((errorOffset.top - originY) / lineLength),
        inverseAngle = 180 - angle;

    // invert angle if to the right of origin
    if (errorOffset.left > originX) {
        angle *= -1;

    // set linkLine origin
        'top': $messageOffset.top,
        'left': $messageOffset.left

    // draw line from vague error message to field with error
        'height': lineLength,
        '-webkit-transform': 'rotate(' + angle + 'deg)',
        '-moz-transform': 'rotate(' + angle + 'deg)',
        '-o-transform': 'rotate(' + angle + 'deg)',
        '-ms-transform': 'rotate(' + angle + 'deg)'

    // flip line, hide and add error class to field with error
    setTimeout(function() {
            'top': errorOffset.top,
            'left': errorOffset.left,
            'height': 0,
            '-webkit-transform': 'rotate(' + inverseAngle + 'deg)',
            '-moz-transform': 'rotate(' + inverseAngle + 'deg)',
            '-o-transform': 'rotate(' + inverseAngle + 'deg)',
            '-ms-transform': 'rotate(' + inverseAngle + 'deg)'
        error.focus(function() {
    }, 300);



Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.


Loading ..................