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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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

              
                <h1>Animated input labels</h1>
<h2>Inspired by: https://codepen.io/oknoblich/pen/wFGIH</h2>
<p>An example with placeholders, required and invalid attributes</p>

<form>
  <fieldset class="span6 reset">
    <div class="form_row">
      <div class="input"> 
        <input placeholder="Fill out your name" type="text" id="name" required />
        <label for="name"> Name: <span class="blue">*</span></label>
      </div>
    </div>

    <div class="form_row">
      <div class="input">
        <input placeholder="Fill out your email" type="email" id="email" required />
        <label for="email"> Email: <span class="blue">*</span></label>
      </div>
    </div>

    <div class="form_row">
      <div class="input">
        <input placeholder="Fill out your company" type="text" id="company" />
        <label for="company"> Company:</label>
      </div>

    </div>
  </fieldset>

  <fieldset class="span6">
    <div class="form_row">
      <div class="input">
        <input placeholder="Fill out your phone" type="tel" pattern="[0-9]{10}" id="tel"required />
        <label for="tel"> Telephone: <span class="blue">*</span></label>
      </div>

    </div>

    <div class="form_row">
      <div class="input">
        <input placeholder="Fill out your subject" type="text" id="subject" required />
        <label for="subject"> Subject: <span class="blue">*</span></label>
      </div>

    </div>

    <div class="form_row">
      <div class="input">
        <input placeholder="Fill out your website" type="text" id="website" />
        <label for="website"> Website:</label>
      </div>

    </div>
  </fieldset>

  <fieldset class="span12 reset">
    <div class="form_row">
      <div class="input">
        <textarea placeholder="Fill out your message" id="message" cols="55" rows="7" required></textarea>
        <label for="message">Message: <span class="blue">*</span></label>
      </div>
    </div>

    <div class="form_row">
      <input class="more wider" type="submit" value="Send Form" />
    </div>
  </fieldset>
</form>
              
            
!

CSS

              
                @import "compass/css3";

@import url(https://fonts.googleapis.com/css?family=Roboto:400,300,700);

$core: #13A7D7;
$white: #fff;
$grey:#777;
$red: #e9322d;
$darkgrey: #333;
$lightgrey: #ccc;
$font: "Roboto", Helvetica, Arial, sans-serif;
.blue { color:$core; }
.reset { margin-left:0 !important; clear:both; }

@mixin gradient-vertical($startColor: #555, $endColor: #333) {
  background-color: mix($startColor, $endColor, 60%);
  background-image: -moz-linear-gradient(top, $startColor, $endColor); // FF 3.6+
  background-image: -ms-linear-gradient(top, $startColor, $endColor); // IE10
  background-image: -webkit-gradient(linear, 0 0, 0 100%, from($startColor), to($endColor)); // Safari 4+, Chrome 2+
  background-image: -webkit-linear-gradient(top, $startColor, $endColor); // Safari 5.1+, Chrome 10+
  background-image: -o-linear-gradient(top, $startColor, $endColor); // Opera 11.10
  background-image: linear-gradient(top, $startColor, $endColor); // The standard
  background-repeat: repeat-x;
  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#{darken($startColor, 1%)}', endColorstr='#{darken($endColor, 1%)}', GradientType=0); // IE9 and down
}

* {
  @include box-sizing(border-box);
  outline:0;
  &:after, &:before {
    @include box-sizing(border-box);
  }
}
body {
  font-family:$font;
  margin:0;
  padding:50px;
}

h1,h2 {
  color:$core;
  margin-bottom:15px;
  text-align:center;
}

p {
  color:$darkgrey;
  margin-bottom:35px;
  text-align:center;
}

.more {
  @include border-radius(4px);
  @include box-shadow(0 1px 2px rgba(0, 0, 0, .2));
  @include gradient-vertical(lighten($core, 5%), $core);
  border:none;
  border-top: rgba(255, 255, 255, .2) 1px solid;
  border-bottom: rgba(0, 0, 0, .4) 1px solid;
  color: $white;
  display: inline-block;
  font-size:1em;
  font-weight: 700;
  padding: 15px 20px;
  text-align: center;
  text-transform: uppercase;
  text-shadow: 0px 1px 1px rgba(0, 0, 0, 0.5);
  &:hover {
    @include gradient-vertical(lighten($core, 2%), darken($core, 2%));
    cursor: pointer;
    text-decoration: none;
  }
  &.wider {
    padding-left: 25px !important;
    padding-right: 25px !important;
  }
}

form {
  margin:0 auto;
  padding:0;
  width:600px;
  
  fieldset {
    border:0;
    margin:0;
    padding:0;
  }
  
  .form_row {
    margin:0 0 10px 0;
    position:relative;
  }
  
  .input {
    input,textarea {
      @include border-radius(14px);
      @include transition(all .2s linear);
      background:white;
      border: 1px solid $lightgrey;
      color:$core;
      display: inline-block;
      height: 45px;
      font-family:$font;
      font-size:0.75em;
      font-weight:300;
      margin: 0;
      overflow:hidden;
      padding: 10px 20px 10px 100px;
      width:100%;
    }
    textarea {
      height:250px;
    }
    label {
      @include transition(all .2s linear);
      color:$darkgrey;
      cursor: text;
      font-size:0.8em;
      font-weight:400;
      position: absolute;
      top: 14px;
      left: 15px;
    }
    &.active {
      overflow:hidden;
      
      input,textarea {
        padding-left: 120px;
      }
      input:required:invalid, textarea:required:invalid {
        border:1px solid $red;
        color:$red;
        + label {
          background:$red;
        }
        &:focus {
          + label {
            background:$red;
          }
        }
      }
      label {
        @include border-radius(14px 0 0 14px);
        color: $white;
        background: $core;
        top: 0;
        left: 0;
        padding: 14px 10px;
        text-align: center;
        width:100px;
        span {
          color:$white !important;
        }
      }
      textarea + label {
        @include border-radius(14px 0);
      }
    }
  }
  :-moz-placeholder {
    color: $grey;
  }
  :-ms-input-placeholder {
    color: $grey;
  }
  ::-webkit-input-placeholder {
    color: $grey;
  }
}

@media only screen and (min-width: 768px) {
  [class*="span"] {
    display: block;
    float: left;
    min-height: 30px;
    margin-left: 2.564102564102564%;
  }
  .span6 {
    width: 48.717948717948715%;
    *width: 48.664757228587014%;
  }
  .span12 {
    width: 100%;
    *width: 99.94680851063829%;
  }
}
              
            
!

JS

              
                $(function () {
  $('input, textarea').each(function() {
        $(this).on('focus', function() {
            $(this).parent('.input').addClass('active');
        });

        $(this).on('blur', function() {
            if ($(this).val().length == 0) {
                $(this).parent('.input').removeClass('active');
            }
        });
        if ($(this).val() != '') $(this).parent('.input').addClass('active');
    });
});
              
            
!
999px

Console