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

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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);


🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................