Login Form with Floating Label using HTML & CSS

Login Form with Floating Label using HTML & CSS

Login Form with Floating Label using HTML & CSS

In this article, you will learn how to create a Login Form with Floating Label using HTML and CSS. Earlier I shared with you the design of different types of login forms. However, Floating Label animation has been added to this login form.

I used HTML and CSS to create this project (Login Form with Floating Label Animation). In normal forms, the label is fixed above the input box.

This label is in the input box. As you click on the input box, the label will move upwards. Usually, we use a placeholder in the input box. However, in many cases, the label is used.

Login Form with Floating Label

It is much more modern and beautiful than the ordinary input box. I used only HTML and CSS to create this modal login form with floating labels. No JavaScript is used here.
 
Below I have given a demo that will help you to know how it works. Here you will find the required source code and preview.

See the Pen
Login Form With Floating label
by Foolish Developer (@foolishdevweb)
on CodePen.

As you can see above, two input boxes have been created here. One label at a time has been used for the input box. Which is in that input box. 

When you click on that input box, the label will go up a bit. This will change the color of the input box and label.

How to Create Animated Form Label in CSS

This Login Form with Floating Label is not very nice. But it will help you to understand how to create a Floating Label in the input box.

Step 1: Basic structure of login form

The following HTML code is the basic structure of this login form. Then the webpage is designed by CSS.

<form>
</form>
body {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
font-family: ‘Lato’, sans-serif;
background-color: #fcfcfc;
flex-direction: column;
}
form {
padding: 20px 40px;
}

Step 2: Add input boxes and labels

I created the input boxes using the following HTML and CSS codes. One level at a time has been used in these input boxes.

<div class=”form-group”>
   <input type=”text” required/><label>Username</label>
</div>
<div class=”form-group”>
   <input type=”password” required/><label>Password</label>
</div>

I designed the input spaces using the following CSS codes. The width of the input space here is 300px and there is no border around the space. 

Instead of a border around, only a 1-pixel border has been used at the bottom.

.form-group {
position: relative;
padding: 20px 0;
width: 300px;
max-width: 100%;
}
.form-group input {
background-color: transparent;
border: none;
border-bottom: 1px solid #9e9e9e;
color: #333;
font-size: 16px;
padding: 10px 0;
display: block;
width: 100%;
}
Add input boxes and labels

Step 3: Design the labels

These CSS Floating Labels have been designed using the following CSS. Here font-size: 16px is used to increase the size of the Floating Label. 

Transform: translateY (30px) is used to keep the labels slightly down. As a result, the labels will be down 30px.

.form-group label {
color: #9e9e9e;
font-size: 16px;
font-weight: 100;
position: absolute;
pointer-events: none;
top: 0;
transform: translateY(30px);
transition: all 0.2s ease-in-out;
left: 0px;
}
Design the labels

Step 4: Floating Label has been activated

This login Form with Floating Label has been implemented using the following CSS. These labels will move up when you click on the input box. Under normal circumstances, the transform is used to keep the labels down. 

Labels are placed below 30px using transform. The instructions here are that when you click on the input box, the value of that transform will become zero. As a result, those levels will go up again.

.form-group input:valid,
.form-group input:focus {
border-bottom-color: #ee6e73;
outline: none;
}
.form-group input:valid + label,
.form-group input:focus + label {
color: #ee6e73;
font-size: 14px;
transform: translateY(0);
}

Floating Label has been activated

Step 5: Create a login button

The buttons were created using the following HTML and CSS codes. The background color of the button is red and it is accompanied by a border of 2 pixels.

<input type=”button” value=”Submit” />
input[type=”button”] {
background-color: #ee6e73;
border: 2px solid #ee6e73;
border-radius: 2px;
box-sizing: border-box;
color: #fff;
cursor: pointer;
font-size: 16px;
padding: 15px 0;
margin-top: 15px;
width: 100%;
}
Create a login button

Different types of hover and color effects have been added to the login button using the following CSS. The background color of the buttons will change when the mouse is moved or clicked on the buttons.

input[type=”button”]:hover {
background-color: #084ccd;
border: 2px solid #084ccd;
 
}
input[type=”button”]:active {
border-color: #fff;
}
input[type=”button”]:focus {
outline: none;
}
Login Form with Floating Label using HTML

Hopefully from the above tutorial, you have learned how I created this Login Form Card With a Floating label using HTML and CSS.

Earlier I shared with you many more types of label animation tutorials. If you like this article, you can follow those tutorials. You can use the download button below to download the required source code of this Login Form with Floating Label.