cssAudio - ActiveCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

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.

            
              <center>
  <form>
    <fieldset>
      <!-- Entypo &#128100; = User -->
      <input type="text" name="username" id="username" placeholder="Username" pattern="^[a-zA-Z][a-zA-Z0-9-_\.]{1,12}$" data-validation-msg="Username must be 2 - 12 characters" required />
      <label for="username" data-icon="&#128100;">Username</label>
      <!-- Entypo &#128274; = Locked -->
      <input type="password" name="password" id="password" placeholder="Password" pattern="^[a-zA-Z][a-zA-Z0-9-_\.]{1,12}$" data-validation-msg="Password must be 2-12 characters" required />
      <label for="password" data-icon="&#128274;">Password</label>
      <!-- Entypo &#58542; = Right Arrow -->
      <button value="Submit" data-icon="&#58542;" />
    </fieldset>
  </form>
</center>
            
          
!
            
              @import "compass/css3";

// HTML5 Form Validation
// -----------------------------------------------------
// Design based on Sign In by Rogie King -
// http://dribbble.com/shots/344627-Sign-In

// Imports
// -----------------------------------------------------
// Font - Entypo
@import url(http://weloveiconfonts.com/api/?family=entypo);

// Mixins
// -----------------------------------------------------
// Input placeholder attribute
@mixin input-placeholder {
  @if $experimental-support-for-webkit {
    &::-webkit-input-placeholder { @content; }
  }
  @if $experimental-support-for-mozilla {
    &::-moz-placeholder { @content; }
  }
  @if $experimental-support-for-microsoft {
    &:-ms-input-placeholder { @content; }
  }
}

// Variables
// -----------------------------------------------------
$body-background:                  #292931 !default;
$data-icon-font-size:              16px !default;
$form-margin:                      20px 0 0 0 !default;
$form-fieldset-background:         #423142 !default;
$form-fieldset-width:              200px !default;
$form-fieldset-padding:            16px !default;
$form-label-width:                 32px !default;
$form-label-height:                32px !default;
$form-label-color:                 #847384 !default;
$form-label-background:            #dedede !default;
$form-label-border-radius:         3px 0 0 3px !default;
$form-label-border:                1px solid #cecece !default;
$form-input-text-width:            166px !default;
$form-input-text-height:           32px !default;
$form-input-text-margin:           0 0 10px $form-label-width !default;
$form-input-text-padding:          0 0 0 8px !default;
$form-input-text-border-radius:    0 3px 3px 0 !default;
$form-input-text-border:           0 !default;
$form-input-text-font:             14px Corbel, "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", "Bitstream Vera Sans", "Liberation Sans", Verdana, "Verdana Ref", sans-serif !default;
$form-input-text-placeholder-color:#848484 !default;
$form-button-color:                #ffffff !default;
$form-button-background:           #ad6bad !default;
$form-button-width:                32px !default;
$form-button-height:               32px !default;
$form-button-border:               0 !default;
$form-button-border-radius:        0 3px 3px 0 !default;
$form-error-height:                $form-input-text-height !default;
$form-error-padding:               0 10px !default;
$form-error-font:                  $form-input-text-font !default;
$form-error-color:                 #ffffff !default;
$form-error-background:            #e62163 !default;
$form-error-border:                0 !default;
$form-error-box-shadow:            0 0 0 rgba(0,0,0,0) !default;
$form-error-border-radius:         3px !default;
$form-error-arrow-width:           8px !default;
$form-error-white-space:           nowrap !default;

body {
  background: $body-background;
  padding: 0;
  margin: 0;
}

[data-icon]:after {
  font-family: "entypo";
  content: attr(data-icon);
  speak: none;
} 

.hide-text {
  display: block;
  text-indent: 150%;
  overflow: hidden;
  
  &:before,
  &:after {
    text-indent: 0;
  }
}

form {
  margin: $form-margin;  
}

fieldset {
  @include box-sizing(border-box);
  position: relative;
  width: $form-fieldset-width;
  padding: $form-fieldset-padding $form-fieldset-padding $form-fieldset-padding/2 $form-fieldset-padding;
  background: $form-fieldset-background;
  border: 0;
}

label,
button {
  // Icon
  &[data-icon]:after {
    position: absolute;
    top: 50%;
    left: 50%;
    font-size: $data-icon-font-size;
  }
}

label {
  @extend .hide-text;
  @include border-radius($form-label-border-radius);
  position: absolute;
  margin-top: -#{$form-label-height + 10};
  width: $form-label-width;
  height: $form-label-height;
  background: $form-label-background;
  border-right: $form-label-border;
  cursor: pointer;

  // Icon
  &[data-icon]:after {
    color: $form-label-color;
  }

  // Icon - User
  &[for="username"][data-icon]:after {
    margin: -#{$data-icon-font-size/1.75} 0 0 -#{$data-icon-font-size/2.25};
  }

  // Icon - Locked
  &[for="password"][data-icon]:after {
    margin: -#{$data-icon-font-size/1.75} 0 0 -#{$data-icon-font-size/3.25};
  }
}

input[type="text"],
input[type="password"] {
  &::-webkit-input-placeholder {
    color: $form-input-text-placeholder-color;
  }
  &::-moz-input-placeholder {
    color: $form-input-text-placeholder-color;
  }
  &:-ms-input-placeholder {
    color: $form-input-text-placeholder-color;
  }
  /*@include input-placeholder {
    color: $form-input-text-placeholder-color;
  }*/
  @include border-radius($form-input-text-border-radius);
  height: $form-input-text-height;
  width: $form-input-text-width;
  border: $form-input-text-border;
  margin: $form-input-text-margin;
  padding: $form-input-text-padding;
  font: $form-input-text-font;

  // Tooltip - Valid Error Message
  + label + span {
    display: none;
    @include border-radius($form-error-border-radius);
    @include box-shadow($form-error-box-shadow);
    position: absolute;
    left: #{$form-input-text-width + $form-label-width + $form-fieldset-padding*2.25};  
    margin-top: -#{$form-input-text-height + 10};
    padding: $form-error-padding;
    height: $form-error-height;
    color: $form-error-color;
    background: $form-error-background;
    border: $form-error-border;
    font: $form-error-font;
    line-height: $form-error-height;
    white-space: $form-error-white-space;

    // Left Arrow
    &:before {
      width: 0;
      height: 0;
      left: -$form-error-arrow-width;
      top: #{($form-error-height / 2) -($form-error-arrow-width / 2)};
      content: '';
      position: absolute;
      border-top: #{$form-error-arrow-width / 2} solid transparent;
      border-right: $form-error-arrow-width solid $form-error-background;
      border-bottom: #{$form-error-arrow-width / 2} solid transparent;
    }
  }
  
  // Invalid
  &:invalid {
    display: block;
    box-shadow: none;
    outline: none;
  }

  // Invalid - Label
  //&:focus:required:invalid
  &.blur:required:invalid + label {
    background: $form-error-background;
    border-right-color: #ffffff;
         
    &:after {
      margin: -#{$data-icon-font-size/1.75} 0 0 -#{$data-icon-font-size/2};
      // Icon - ! Info
      content: '\26A0';
      color: $form-error-color;
    }
  }
}

button {
  @include border-radius($form-button-border-radius);
  @extend .hide-text;
  position: absolute;
  right: $form-fieldset-padding;
  width: $form-button-width;
  height: $form-button-height;
  margin-top: -#{$form-input-text-height + 10};
  color: $form-button-color;
  background: $form-button-background;
  border: $form-button-border;

  // Icon - Right Arrow
  &[data-icon]:after {
    position: absolute;
    top: 50%;
    left: 50%;
    margin: -#{$data-icon-font-size/1.75} 0 0 -#{$data-icon-font-size/2.5};
    color: $form-button-color;
    font-size: $data-icon-font-size;
  }
}
            
          
!
            
              // Custom validation messages
// Set msg on 'data-validation-msg' input attribute
// -------------------------------------------------
$(function () {
  var inputs = document.getElementsByTagName('input'),
      inputsLen = inputs.length,
      input,
      inputMsg,
      inputValidationMsg,
      label,
      button = document.getElementsByTagName('button')[0],
      form = document.getElementsByTagName('form')[0];

  // Let's hide the default validation msg as
  // -webkit-validation-bubble no longer works in Chrome 28+. Booooooo!
  form.addEventListener('invalid', function (e) {
    e.preventDefault();
  }, true);

  // Validate form on submit - display tooltip if input has no value
  button.onclick = function () {
    inputsLen = inputs.length;
    
    while (inputsLen--) {
      if (inputs[inputsLen].value.length > 0) {
        return true;
      }     
    next(inputs[inputsLen]).nextSibling.style.display = 'block'; 
    }
  }
  
  while (inputsLen--) {
    input = inputs[inputsLen];
    label = next(input);
    
    if (input.hasAttribute('data-validation-msg')) {   
      // Create span element for our validation msg
      inputValidationMsg = input.getAttribute('data-validation-msg');
      inputMsg = document.createElement('span');
      inputMsg.innerHTML = inputValidationMsg;
    
      // Add our own validation msg element so we can style it
      label.parentNode.insertBefore(inputMsg, label.nextSibling);
    
      input.onblur = function (e) {
        // If value does not exist or is invalid, toggle validation msg
        e.target.classList.add('blur');
        next(e.target).nextSibling.style.display = (!this.value || this.validity.valid === false) ? 'block' : 'none';
      }
    }
  }
});
  
// Credit to John Resig for this function taken from Pro JavaScript techniques 
function next(elem) {
  do {
    elem = elem.nextSibling;
  }
  while (elem && elem.nodeType !== 1);
  return elem;        
}
            
          
!
999px
Close

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.

Go PRO

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

Console