Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <div class="container">
  <div class="push"></div>
	<div class="row">
		<div class="col-xs-6 col-xs-offset-3">
			<div class="response hide">
				<p><strong>Post Data:</strong></p>
				<pre></pre>
			</div>
			<div class="alert alert-success hide" role="alert">
				<strong>Well done!</strong> You successfully completed this form.
			</div>
			<div class="alert alert-danger hide" role="alert">
				<strong>Oh snap!</strong> Change a few things up and try submitting again.
			</div>
			<form name="contact" action="#" method="post">
				<fieldset>
					<legend>Contact Information</legend>
					<div class="form-group">
						<label for="firstName" class="hide"><i class="glyphicon glyphicon-user"></i> First Name * &nbsp;</label>
						<input autofocus type="text" name="firstName" class="form-control name" id="firstName" placeholder="First Name *" pattern="^[a-zA-Z][a-zA-Z0-9-_\.]{1,20}$" title="Enter first name (e.g. John)" required>
					</div>
					<div class="form-group">
						<label for="lastName" class="hide"><i class="glyphicon glyphicon-user"></i> Last Name * &nbsp;</label>
						<input type="text" name="lastName" class="form-control name" id="lastName" placeholder="Last Name *" pattern="^[a-zA-Z][a-zA-Z0-9-_\.]{1,20}$" title="Enter last name (e.g. Smith)" required>
					</div>
					<div class="form-group">
						<label for="email" class="hide"><i class="glyphicon glyphicon-envelope"></i> E-mail * &nbsp;</label>
						<input type="email" name="email" class="form-control email" id="email" placeholder="E-mail *" pattern="[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$" title="Enter e-mail address (e.g. your.email@address.com)" required>
					</div>
					<div class="form-group">
						<label for="telephone" class="hide"><i class="glyphicon glyphicon-earphone"></i> Telephone * &nbsp;</label>
						<input type="tel" name="telephone" class="form-control tel" id="telephone" placeholder="Telephone *" pattern="^\(?\d{3}\)?[- ]?\d{3}[- ]?\d{4}$" title="Enter telephone number (e.g. 555-555-5555)" required>
					</div>
					<button type="submit" class="btn btn-primary btn-block">Submit</button>
				</fieldset>
			</form>
		</div>
	</div>
</div>
              
            
!

CSS

              
                // Variables
$bg-color:			#fff;
$input-bg-color:	#fff;
$valid:				green;
$invalid:			red;

// General
body {
	background: $bg-color;
}
.push {
	height: 100px;
}
.form-group {
	position: relative;
}

// Inputs
.form-control.valid {
	border-color: $valid;
	&:focus{
		box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(0,128,0,.6)
	}
}
.form-control.invalid {
	border-color: $invalid;
	&:focus{
		box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(128,0,0,.6)
	}
}

// Labels
label {
	position: absolute;
	left: 12px;
	top: -7px;
	background: linear-gradient(rgba($bg-color,1),rgba($bg-color,1) 51%, rgba($input-bg-color,1) 52%, rgba($input-bg-color,1) 100%);
	font-size: 1rem;
	padding: 0 0 0 3px;
	font-style: italic;
	opacity: 1;
	transition: color ease-in-out .15s;
	&.active:before,
	&.active:after {
		background: $input-bg-color;
		content: '';
		display: block;
		width: 2px;
		height: 2px;
		position: absolute;
		top: 7px;
	}
	&.active:before {
		box-shadow: 0 0 5px 5px $input-bg-color;
		left: 0;
	}
	&.active:after {
		box-shadow: 0 0 3px 3px $input-bg-color;
		right: 0;
	}
	&.valid {
		color: $valid;
	}
	&.invalid {
		color: $invalid;
	}
}

// Placeholder
::-webkit-input-placeholder {
	font-style: italic;
	line-height: 1.6rem;
}
input:focus::-webkit-input-placeholder {
	color: transparent;
}

// Placeholder icons
input::-webkit-input-placeholder::before {
	font-family: 'Glyphicons Halflings';
	position: relative;
	top: 1px;
	margin-right: 8px;
	font-style: normal;
}

input.name::-webkit-input-placeholder::before {
	content: "\e008";
}
input.email::-webkit-input-placeholder::before {
	content: "\2709";
}
input.tel::-webkit-input-placeholder::before{
	content: "\e182";  
}
              
            
!

JS

              
                var
	$form = $("form[name='contact']"),
	$input = $("form input"),
	$submit = $("button[type=submit]")
;

function phoneFormat(telValue) {
	telValue = telValue.replace(/[^0-9]/g, '');
	telValue = telValue.replace(/(\d{3})(\d{3})(\d{4})/, "($1) $2-$3");
	return telValue;
}

function processForm(e) {
	var
		formURL = $("form").attr("action"),
		postData = JSON.stringify({
			"first": $('#firstName').val(),
			"last": $('#lastName').val(),
			"email": $('#email').val(),
			"telephone": $('#telephone').val()
		})
	;

	$(".response").removeClass("hide");
	$(".response pre").html(JSON.stringify(postData));
	$form.addClass("hide");
	$(".alert-success").removeClass("hide");

	/*$.ajax({
		url: formUrl,
		dataType: 'json',
		type: 'post',
		contentType: 'application/json',
		data: postData,
		processData: false,
		success: function(data, textStatus, jQxhr) {
			$form.addClass("hide");
			$(".alert-success").removeClass("hide");
		},
		error: function(jqXhr, textStatus, errorThrown) {
			console.log(errorThrown);
			$(".alert-danger").removeClass("hide");
		}
	});
	e.preventDefault();*/
}

/*$form.submit(processForm);*/

$input.on('focus', function() {
	var $label = $("label[for='" + this.id + "']");
	$label.removeClass("hide").addClass('active');
});

$input.on('keyup focus blur', function() {
	var $label = $("label[for='" + this.id + "']");

	if(this.checkValidity()){
		$label.addClass("valid").removeClass("invalid");
		$(this).addClass("valid").removeClass("invalid");
	} else {
		$label.addClass("invalid").removeClass("valid");
		$(this).addClass("invalid").removeClass("valid");
	}

	$input.each(function(){
		var $label = $("label[for='" + this.id + "']");

		if($(this).val()){
			if(this.checkValidity()){
				$label.addClass("valid").removeClass("invalid");
				$(this).addClass("valid").removeClass("invalid");
			} else {
				$label.addClass("invalid").removeClass("valid");
				$(this).addClass("invalid").removeClass("valid");
			}
		}
	});

	// if($("form input.valid").length === $input.length){
	// 	$submit.prop("disabled", false);
	// } else {
	// 	$submit.prop("disabled", true);
	// }
});

$input.on('blur', function() {
	var $label = $("label[for='" + this.id + "']");

	$label.removeClass('active');

	if(!$(this).val()){
		$("label").addClass("hide");
	}

	$input.each(function(){
		var $label = $("label[for='" + this.id + "']");
		if($(this).val()){
			$label.removeClass("hide");
		}
	});

	if($("input.tel").val()){
		var telValue = $(".tel").val();
		telValue = phoneFormat(telValue);
		$(".tel").val(telValue);
	}
});

              
            
!
999px

Console