Dark CSS

CSS Input Field Animation on Focus

Facebook
Twitter
WhatsApp

Code preview

html Code

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title></title>
    <link rel="stylesheet" href="style.css">
</head>

<body> 
    <div class="inputbox">
        <input type="text" required="required">
        <span>Email</span>
        <i></i>
    </div>
</body>

</html>
				
			

css Code

				
					* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
    font-family: Arial, Helvetica, sans-serif;
}

html,
body {
    display: grid;
    height: 100%;
    place-items: center;
    background-color: #212121;
}

.inputbox {
    position: relative;
    width: 196px;
}

.inputbox input {
    position: relative;
    width: 100%;
    padding: 20px 10px 10px;
    background: transparent;
    outline: none;
    box-shadow: none;
    border: none;
    color: #fff;
    font-size: 1em;
    letter-spacing: 0.05em;
    transition: 0.5s;
    z-index: 10;
}

.inputbox span {
    position: absolute;
    left: 0;
    padding: 20px 10px 10px;
    font-size: 1em;
    color: #8f8f8f;
    letter-spacing: 00.05em;
    transition: 0.5s;
    pointer-events: none;
}

.inputbox i {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 2px;
    background: #c200fd;
    border-radius: 4px;
    transition: 0.5s;
    pointer-events: none;
    z-index: 9;
}

.inputbox input:valid~span,
.inputbox input:focus~span {
    color: #fff;
    transform: translateX(-10px) translateY(-36px);
    font-size: 0, 75rem;
}

.inputbox input:valid~i,
.inputbox input:focus~i {
    height: 44px;
}