JSFiddle - React, Tailwind, and code Playground

by Anav02

HTML

<!DOCTYPE html>
<html>
<head>
    <title>Fancy Text Input</title>
</head>
<body>
<section >
        <div class="box">
            <input type="text"  required> 
            <span>Username</span>
            <i></i>
        </div>
    </section>
</body>
</html>

CSS

* {
    padding: 0;
    margin: 0;
    outline: none;
}

body {
    background-color: #282a30;
}

section {
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;

}  
input {
  width: 150px;
    margin: auto;
    padding: 12px;
    font-size: 1rem;
    transition: all .3s ease;
    outline: none;
    position: relative;
    background: transparent;
    border: none;
    caret-color: white;
    color: white;
    z-index: 1;
}
.box {
    width: 150px;
    margin: auto;
    position: relative;
}

 span {
   z-index: 99;
    color: #38B6FF;
    position: absolute;
    font-size: 1rem;
    position: absolute;
    top: 75%;
    padding: 20px;
    transform: translateY(-50%);
    pointer-events: none;
    transition: all .3s ease;
}

 input:valid ~ i ,  input:focus ~ i {
    height: 100%;
}

 i {
    margin: auto;
    position: absolute;
    bottom: 0;
    height: 2px;
    width: 200px;
    background: #38B6FF;
    z-index: -1;
    transition: all .3s ease;
    border-radius: 10px;
    pointer-events: none;
}

 input:valid ~ span,  input:focus ~ span {
    transform: translate(-20px, -70px);

}

 input::selection {
    background-color: white;
    color: #38B6FF;
}