<form class="hs-form stacked">
<fieldset class="form-columns-2">
<div class="field hs-form-field">
<label>First Name</label>
<div class="input">
<input class="hs-input left" type="text" />
</div>
</div>
<div class="field hs-form-field">
<label>Last Name</label>
<div class="input">
<input class="hs-input right" type="text" />
</div>
</div>
</fieldset>
<div class="field hs-form-field">
<label>Company</label>
<div class="input">
<input class="hs-input" type="text" />
</div>
</div>
<div class="field hs-form-field">
<label>Email</label>
<div class="input">
<input class="hs-input" type="email" />
</div>
</div>
<a class="hs-button large primary" href="#">Start Today!</a>
</form>
@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700&display=swap");
body {
font-family: "Montserrat", sans-serif;
display: flex;
align-items: center;
justify-content: center;
margin: 0 2rem;
}
.hs-form {
width: 100%;
max-width: 500px;
margin: 4rem auto;
}
fieldset {
border: 0;
padding: 0;
margin: 0;
max-width: 500px;
}
fieldset.form-columns-2 .hs-form-field {
width: 50%;
float: left;
}
.hs-form-field {
line-height: 1.5;
margin: 0 0 1.5rem;
position: relative;
}
.hs-form-field .form-columns-2 {
line-height: 1.5;
margin: 0 0 1.5rem;
position: relative;
}
.hs-form-field label {
color: gray;
display: block;
position: absolute;
left: 1rem;
top: 1rem;
transform: translate(0, 0) scale(1);
transform-origin: bottom left;
transition: all 200ms ease;
}
.hs-form-field.active label {
transform: scale(0.75);
color: #a867eb;
background: white;
padding: 0 0.25rem;
top: -0.9rem;
left: 1rem;
z-index: 5;
}
.hs-input {
width: 100%;
border: 0px none;
border-radius: 0.5rem;
border: 1px solid #767676;
color: #555;
padding: 1.1rem 1.25rem;
appearance: none;
font-size: 1rem;
background: transparent;
position: relative;
box-sizing: border-box;
}
.hs-input.left {
border-radius: 0.5rem 0 0 0.5rem;
border-width: 1px 0 1px 1px;
}
.hs-input.right {
border-radius: 0 0.5rem 0.5rem 0;
}
.hs-input:focus {
outline: 0 none;
border-color: #a867eb;
}
.hs-input:invalid {
border-color: red;
}
.hs-button {
margin-top: 20px;
padding: 1.25rem 2.5rem;
display: inline-block;
background-color: #a867eb;
color: white;
text-decoration: none;
text-align: center;
font-weight: 700;
box-shadow: 4px 5px 0 0 rgb(22 49 86 / 10%);
}
.hs-button:hover,
.hs-button:focus {
background-color: #ea67eb;
color: white;
text-decoration: none;
outline: 0 none;
}
/* animation push for submit buttons */
@keyframes animation-push {
50% {
transform: scale(0.85);
}
100% {
transform: scale(1);
}
}
.hs-button:active,
.hs-button:focus,
.hs-button:hover {
animation-name: animation-push;
animation-duration: 0.3s;
animation-timing-function: linear;
animation-iteration-count: 1;
}
var $input = $(".hs-input");
// move label on input focus
$input
.on("focus", function() {
$(this)
.parent()
.parent()
.addClass("active");
})
.blur();
// move label if input is empty or not
$input
.focusout(function() {
if (!$(this).val()) {
$(this)
.parent()
.parent()
.removeClass("active");
} else {
$(this)
.parent()
.parent()
.addClass("active");
}
})
.focusout(); // focusout event for prefilled forms
This Pen doesn't use any external CSS resources.