HomeOthersBeginnersFloating Label CSS

Floating Label CSS

Floating Label CSS

Hello everyone! In this blog post, we will learn how to make a floating label CSS. In the realm of web development, user interface design plays a crucial role in shaping user experiences. Among the many elements that contribute to intuitive and user-friendly interfaces, floating labels have emerged as a popular technique for improving form usability and aesthetics. By seamlessly integrating floating labels into HTML forms using CSS, developers can create visually appealing and functional input fields that enhance the overall user experience.

At its core, a floating label is a form label that transitions from its initial position above the input field to a floating position within the field when the user interacts with it. This dynamic behavior provides users with context and guidance as they input data, making the form-filling process more intuitive and efficient.

To implement floating labels, developers leverage the power of HTML and CSS. HTML provides the structure for creating form elements such as text fields, checkboxes, and radio buttons, while CSS is used to style and animate these elements, including the floating labels.

One of the key benefits of floating labels is their ability to conserve screen space while maintaining clarity and usability. Unlike traditional static labels that occupy space even when the input field is empty, floating labels move out of the way when users focus on the input field, maximizing available space and reducing visual clutter.

From a design perspective, floating labels offer a modern and sleek aesthetic that aligns with contemporary web design trends. The smooth transition of the label from its resting position to a floating state adds a touch of elegance to the form, enhancing the overall visual appeal of the interface.

Moreover, floating labels provide valuable feedback to users, indicating which input field they are interacting with and helping them understand the expected input format. This proactive guidance reduces the likelihood of input errors and improves the overall usability of the form.

Implementing floating labels using HTML and CSS is relatively straightforward. Developers use CSS positioning and transition properties to achieve the floating effect, ensuring that the labels smoothly transition from their initial position to a floating state when the input field gains focus.

While floating labels offer many benefits, it’s essential to use them judiciously and considerately. Overusing floating labels or implementing them inappropriately can lead to confusion and frustration for users. Developers should carefully evaluate the context and purpose of each form field before deciding whether to use floating labels.

Source Files – Floating Label CSS


<!DOCTYPE html>
<html lang="en">

    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Floating Label HTML CSS | Codehal</title>
    <link rel="stylesheet" href="style.css">


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



CSS Code

@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    flex-direction: column;
    background: #01003f;

.input-group {
    position: relative;
    margin: 20px 0;

.input-group label {
    position: absolute;
    top: 50%;
    left: 15px;
    transform: translateY(-50%);
    font-size: 16px;
    color: #0ef;
    padding: 0 5px;
    pointer-events: none;
    transition: .5s;

.input-group input {
    width: 360px;
    height: 60px;
    font-size: 16px;
    color: #fff;
    padding: 0 15px;
    background: transparent;
    border: 1.2px solid #0ef;
    outline: none;
    border-radius: 5px;

.input-group input:focus~label,
.input-group input:valid~label {
    top: 0;
    font-size: 14px;
    background: #01003f;


In conclusion, floating labels represent a valuable technique for improving form usability and aesthetics in web development. By leveraging HTML and CSS, developers can create visually appealing and functional input fields that enhance the overall user experience. When implemented thoughtfully and responsibly, floating labels can elevate form design, making it more intuitive, efficient, and visually engaging.

Previous article

Most Popular