Hello guys! Today we will learn how to create an Input field animation using CSS.

[ays_quiz id=’1′]

Step 1 – HTML

First, we will write some HTML code in the index.html file

<!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" />
    <link rel="stylesheet" href="style.css" />
    <title>Input field animation</title>
    <div class="input-group">
      <input type="email" name="name" id="email" class="input" required />
      <label for="email" class="input-label">Email address</label>

Step 2 – CSS

Now, we will write CSS in the style.css file

body {
  padding: 0;
  margin: 0;
body {
  background-color: #242329;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: system-ui;
.input-group {
  position: relative;
.input {
  padding: 10px;
  border: none;
  border-radius: 4px;
  color: #fff;
  background-color: transparent;
  outline: 2px solid #fff;
.input-label {
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(10px, 10px) scale(1);
  transition: transform 0.25s;
  color: #fff;
  background-color: #242329;
  padding-inline: 5px;
.input:focus + .input-label,
.input:valid + .input-label {
  transform: translate(10px, -14px) scale(0.8);

That’s it for today.

Oh, hi there 👋 It’s nice to meet you.

Sign up to receive awesome content in your inbox, every week.

We don’t spam! Read our privacy policy for more info.

Leave a Reply