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.

            
              <div class="wrapper">
<h1>More responsive, accessible, mobile-first forms</h1>  
<p>This set is based on the article <a href="http://uxmovement.com/forms/why-infield-top-aligned-form-labels-are-quickest-to-scan/comment-page-1/">Why Infield Top Aligned Form Labels are Quickest to Scan</a> on <a href="http://www.uxmovement.com">uxmovement.com</a> The research indicated several advantages to this style fo form. I've leveraged the accessibility from my <a href="http://codepen.io/mdonahue37/pen/OPMNZJ?editors=110"> previous forms pen</a>. Even added a touch of material design.</p>
  
<h3 class="form-title">Mailing address form 1</h3>
<form>
  <ul id="address">
  <li class="">
    <label for="street">Street 1</label>
    <input id="street" type="text" />
  </li>
  <li class="">
    <label for="street2">Street 2<span class="hint"> (optional)</span></label>
    <input id="street2" type="text" />
  </li>
  <li class="half alpha">
    <label for="city">City</label>
    <input type="text" id="city" />
  </li>
  <li class="quarter sm-half">
      <label for="state" id="state_label">State</label>
      <datalist id="states">
        <select name="state" aria-describedby="state_label">
          <option>Alabama</option> 
          <option>Alaska</option> 
          <option>Arizona</option> 
          <option>Arkansas</option> 
          <option>California</option> 
          <option>Colorado</option> 
          <option>Connecticut</option> 
          <option>Delaware</option> 
          <option>Florida</option> 
          <option>Georgia</option> 
          <option>Hawaii</option> 
          <option>Idaho</option> 
          <option>Illinois</option> 
          <option>Indiana</option> 
          <option>Iowa</option> 
          <option>Kansas</option> 
          <option>Kentucky</option> 
          <option>Louisiana</option> 
          <option>Maine</option> 
          <option>Maryland</option> 
          <option>Massachusetts</option> 
          <option>Michigan</option> 
          <option>Minnesota</option> 
          <option>Mississippi</option> 
          <option>Missouri</option> 
          <option>Montana Nebraska</option> 
          <option>Nevada</option> 
          <option>New Hampshire</option> 
          <option>New Jersey</option> 
          <option>New Mexico</option> 
          <option>New York</option> 
          <option>North Carolina</option> 
          <option>North Dakota</option> 
          <option>Ohio</option> 
          <option>Oklahoma</option> 
          <option>Oregon</option> 
          <option>Pennsylvania</option>
          <option>Rhode Island</option> 
          <option>South Carolina</option> 
          <option>South Dakota</option> 
          <option>Tennessee</option> 
          <option>Texas</option> 
          <option>Utah</option> 
          <option>Vermont</option> 
          <option>Virginia</option> 
          <option>Washington</option> 
          <option>West Virginia</option> 
          <option>Wisconsin</option> 
          <option>Wyoming</option>
        </select>
        If other, please specify.
      </datalist>
      <input id="state" name="state" list="states" />
  </li>
  <li class="quarter sm-half">
    <label for="zip">Zip</label>
    <input type="text" id="zip" />
  </li>
  <footer>
    <button>Save address</button>
  </footer>
</ul>
</form>

<h3 class="form-title">Mailing address form 2</h3>
<form>
  <ul id="address">
  <li class="three-quarter alpha">
    <label for="street">Street 1</label>
    <input id="street" type="text" />
  </li>
  <li class="quarter">
    <label for="apartment">Apt/Suite <span class="hint">optional</span></label>
    <input id="apartment" type="text" />
  </li>
  <li class="half alpha">
    <label for="city">City</label>
    <input type="text" id="city" />
  </li>
  <li class="quarter sm-half">
      <label for="state" id="state_label">State</label>
      <datalist id="states">
        <select name="state" aria-describedby="state_label">
          <option>Alabama</option> 
          <option>Alaska</option> 
          <option>Arizona</option> 
          <option>Arkansas</option> 
          <option>California</option> 
          <option>Colorado</option> 
          <option>Connecticut</option> 
          <option>Delaware</option> 
          <option>Florida</option> 
          <option>Georgia</option> 
          <option>Hawaii</option> 
          <option>Idaho</option> 
          <option>Illinois</option> 
          <option>Indiana</option> 
          <option>Iowa</option> 
          <option>Kansas</option> 
          <option>Kentucky</option> 
          <option>Louisiana</option> 
          <option>Maine</option> 
          <option>Maryland</option> 
          <option>Massachusetts</option> 
          <option>Michigan</option> 
          <option>Minnesota</option> 
          <option>Mississippi</option> 
          <option>Missouri</option> 
          <option>Montana Nebraska</option> 
          <option>Nevada</option> 
          <option>New Hampshire</option> 
          <option>New Jersey</option> 
          <option>New Mexico</option> 
          <option>New York</option> 
          <option>North Carolina</option> 
          <option>North Dakota</option> 
          <option>Ohio</option> 
          <option>Oklahoma</option> 
          <option>Oregon</option> 
          <option>Pennsylvania</option>
          <option>Rhode Island</option> 
          <option>South Carolina</option> 
          <option>South Dakota</option> 
          <option>Tennessee</option> 
          <option>Texas</option> 
          <option>Utah</option> 
          <option>Vermont</option> 
          <option>Virginia</option> 
          <option>Washington</option> 
          <option>West Virginia</option> 
          <option>Wisconsin</option> 
          <option>Wyoming</option>
        </select>
        If other, please specify.
      </datalist>
      <input id="state" name="state" list="states" />
  </li>
  <li class="quarter sm-half">
    <label for="zip">Zip</label>
    <input type="text" id="zip" />
  </li>
  <footer>
    <button>Save address</button>
  </footer>
</ul>
</form>

<h3 class="form-title">Contact us</h3>
<form>
  <ul id="contact">
  <li class="half alpha">
    <label for="first-name">First Name</label>
    <input id="first-name" type="text" />
  </li>
  <li class="half">
    <label for="last-name">Last Name</label>
    <input id="last-name" type="text" />
  </li>
  <li class="clear">
    <label for="email">Email <span class="hint">(username@domain.com)</span></label>
    <input id="email" type="text" />
  </li>
  <li>
    <label for="message">Message</label>
    <textarea name="message" id="message" rows="10"></textarea>
  </li>
  <footer>
    <button>Send message</button>
  </footer>
</ul>
</form>

<h3 class="form-title">Sign up form</h3>
<form>
  <ul id="contact">
  <li class="half alpha">
    <label for="first-name">First Name</label>
    <input id="first-name" type="text" />
  </li>
  <li class="half">
    <label for="last-name">Last Name</label>
    <input id="last-name" type="text" />
  </li>
  <li class="clear">
    <label for="email">Email <span class="hint">(username@domain.com)</span></label>
    <input id="email" type="text" />
  </li>
  <li class="half alpha">
    <label for="password">Password</label>
    <input id="password" type="text" />
  </li>
  <li class="half">
    <label for="confirm-pw">Confirm password</label>
    <input id="confirm-pw" type="text" />
  </li>
  <li class="clear">
    <label for="username">Username <span class="hint">(must at least 8 characters)</span></label>
    <input id="username" type="text" />
  </li>
  <footer>
    <p class="three-quarter">By submit this request you accept all the terms and conditions. This could take a few moments.</p>
    <button>Submit</button>
  </footer>
</ul>
</form>
</div>
            
          
!
            
              body, ul, li, input, textarea, p {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
  color: #555;
}

html {
  background-color: #F8F8F8;
  margin: 0 1em;
}

.wrapper {
  max-width: 600px;
  margin: 2em auto;
}

ul {
  list-style: none;
  border-left: 1px solid #ddd;
  border-right: 1px solid #ddd;
  border-bottom: 1px solid #ddd;
  overflow: hidden;
  background-color: #f3f3f3;
  margin-bottom: 2em;
  -webkit-box-shadow: 1px 1px 1px 0 rgba(0,0,0,.2);
  box-shadow: 1px 1px 1px 0 rgba(0,0,0,.2);
  -webkit-border-radius: 0 0 4px 4px;
  border-radius: 0 0 4px 4px;}

li {
  border-top: 1px solid #ddd;
  padding: .75em;
}

li.active {
  background-color: #fff;
  color: #bbb;
  -webkit-box-shadow:inset 0 0 1px 0 rgba(0,0,0,.2);
  box-shadow:inset 0 0 1px 0 rgba(0,0,0,.2);
}

/*.footer {
  background-color: #eee;
}*/

.form-title {
  background-color: #333;
  color: #fff;
  padding: .75em;
  margin-bottom: 0;
  -webkit-border-radius: 4px 4px 0 0;
  border-radius: 4px 4px 0 0;
}

.error {
  background-color: #FFCCCC;
  color: red;
}

input, input:active, textarea, textarea:active {
  border: none;
  width: 100%;
  background-color: transparent;
  outline: none;
  font-size: 1.2em;
}

input, input:active {
  height: 32px;
}

label {
  margin-bottom: .125em;
  display: block;
}

.sm-half {
  width: 50%;
  float: left;
  border-left: 1px solid #ddd;
}

.half, .quarter, .three-quarter {
  border-left:  1px solid #ddd;
}

.alpha {
  border-left: none;
}

.hint {
  color: #bbb;
  font-size: .9em;
}

.clear {
    clear: both;
}

button {
  padding: .75em 1.5em;
  border-radius: 4px;
  border: none;
  background-color: #3366ff;
  color: #fff;
  font-size: 1.25em
}

button:active, button:hover {
  background-color: #2255ff;
}

footer {
  background-color: #eee;
  padding: .75em;
  -webkit-border-radius: 0 0 4px 4px;
  border-radius: 0 0 4px 4px;
  border-top: 1px solid #ddd;
  clear: both;
}

@media all and (min-width: 480px) {
  
.three-quarter {
  width: 75%;
  float: left;
}
  
.half {
  width: 50%;
  float: left;
}

.quarter {
  width: 25%;
  float: left;
}

}
            
          
!
            
              /**
 * Author credit
 * JavaScript below created by Will Moore
 * http://codepen.io/willthemoor/pen/dooRag
 * Requires jQuery
 * Highlights the li tag containing the active input field
 * Only works on input field, textarea does not highlight li
 */

var hocusPocus = function(evt) {

		// Where did the event come from?
		var $target = $(evt.target);

		// Avoid recursion 
		if ($target.parents('.active').length) {
				return false;
		}

		// Highlight the outer box
		$target.closest('li').addClass('active');

};

var cleanUp = function(evt) {
		// Clean up form 'active' state.
		// Called on blur instead of focus because the form can lose focus. 
		// Avoids stragglers.
		$('form').find('.active').removeClass('active');
};

$('input')
		.on('focus', hocusPocus)
		.on('blur', cleanUp);

$('textarea')
		.on('focus', hocusPocus)
		.on('blur', cleanUp);
            
          
!
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