JSFiddle - React, Tailwind, and code Playground

by Ravindra Athreya

HTML

<h1>Infield Top Aligned Form Labels</h1>

<p>Quick demo for <a href="http://uxmovement.com/forms/why-infield-top-aligned-form-labels-are-quickest-to-scan">this article</a></p>

<form>
		<ul>
				<li>
						<input id="first-name" type="text" />
						<label for="first-name">First Name</label>
				</li>
				<li>
						<input id="last-name" type="text" />
						<label for="last-name">Last Name</label>
				</li>
				<li>
						<input id="email" type="text" />
						<label for="email">Email</label>
				</li>
				<li>
						<input id="spirit-animal" type="text" />
						<label for="spirit-animal">Spirit Animal</label>
				</li>
		</ul>
</form>

SCSS

$color  : #888888;
$bgColor: #fffdfa;
$lucida: "Lucida Grande", "Trebuchet MS", sans-serif;

html {
	min-height: 100%;
}
body {
	background-color: #ddd;
	background-image: linear-gradient(to bottom, #f3f3f3 50%  , #acacac 90%);
	color: $color;
	font-family: Helvetica, Arial, sans-serif;
	font-size: 16px;
	padding: 20px;	
}
form, ul, li, input, label {
	box-sizing: border-box;
}
h1, p {
	color: #333;
	font-family: $lucida;
	font-size: 1.6em;
	margin: 0.5em 0 1em 0;
	text-align: center;
}
p {
	font-size: 80%;
}
label, input {
	display: block
}
ul {
	background-color: $bgColor;
	border: 5px solid $color;
	list-style-type: none;
	margin: 3em auto;
	padding: 0;
	max-width: 350px;
}
li {
	border-bottom: 1px solid lighten($color, 25);
	margin-top: -1px; // border collapser
	position: relative;
}

label {
	font-family: $lucida;
	font-size: 70%;
	color: lighten($color, 15);
	letter-spacing: 0.03em;
	position: absolute;
	top: 10px;
	left: 10px;
	text-transform: uppercase;
	.active &, input:focus+& {
		color: darken(#0074D9, 10);
		font-weight: bold;
		letter-spacing: -0.01em;
	}
}
input, input:focus {
	background-color: transparent;
	border: none;
	color: darken($color, 15);
	font-size: 18px;
	margin: 9px 0 7px 0;
	margin: 0;
	padding: 2em 10px 10px 10px;
	outline: none;
	width: 100%;
}
input:focus {
	color: #000;
		background-color: lighten($color, 40);
		box-shadow: 0px 3px 4px -2px rgba(0,0,115,0.25) inset;
}
label, input {
	transition: color 0.4s ease, background-color 0.1s ease-in-out;
}