Create an Animated Login Form Using HTML & CSS | Step-by-Step Guide



A well-designed login form can enhance user experience and make your website look more professional. In this tutorial, we will create a modern animated login form using only HTML and CSS. This form will feature smooth animations, a stylish UI, and a responsive layout.


Why Use an Animated Login Form?

An animated login form adds a modern touch to your website while improving user engagement. Here are a few reasons why animated login forms are beneficial:

  • Enhances User Experience – Smooth animations make the login process visually appealing.
  • Professional Look – A well-designed UI leaves a great first impression.
  • Better Engagement – Interactive elements keep users engaged with your site.

Features of This Login Form

✅ Fully responsive design
✅ Smooth input field animations
✅ Stylish and modern UI
✅ Pure HTML & CSS (No JavaScript required)


HTML Code for the Animated Login Form

Below is the HTML structure for the login form:


<head>
   <meta charset="UTF-8" />
   <meta name="viewport" content="width=device-width, initial-scale=1.0" />
   <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
   <title>Login Page</title>
   <link rel="stylesheet" href="style.css" />
 </head>
 <body>
   <div class="box">
     <form action="" class="form" method="post">
       <h2>Sign in</h2>
       <div class="inputBox">
         <input type="text" name="username" required="required" />
         <span>Username</span>
         <i></i>
       </div>
       <div class="inputBox">
         <input type="password" name="password" required="required" />
         <span>Password</span>
         <i></i>
       </div>
       <div class="links">
         <a href="#">Forgot Password?</a>
         <a href="#">SignUp</a>
       </div>
       <input type="submit" value="Login" />
     </form>
   </div>
 </body>
</html>

CSS Code for the Animated Login Form

Now, let's style our form using CSS to add animations and make it visually appealing:


@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@100&family=Reem+Kufi+Fun:wght@500&display=swap");
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Reem Kufi Fun", sans-serif;
}
body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: #191825;
}
.box {
  position: relative;
  width: 380px;
  height: 420px;
  background: #1c1c1c;
  border-radius: 8px;
  overflow: hidden;
}
.box::after {
  content: "";
  position: absolute;
  top: -50%;
  left: -50%;
  width: 380px;
  height: 420px;
  background: linear-gradient(0deg, transparent, transparent, #7F66FF, #7F66FF);
  z-index: 1;
  transform-origin: bottom right;
  animation: animate 6s linear infinite;
}
.box::before {
  content: "";
  position: absolute;
  top: -50%;
  left: -50%;
  width: 380px;
  height: 420px;
  background: linear-gradient(0deg, transparent, transparent, #7F66FF, #7F66FF);
  z-index: 1;
  transform-origin: bottom right;
  animation: animate 6s linear infinite;
  animation-delay: -3s;
}
@keyframes animate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
.form {
  position: absolute;
  inset: 2px;
  border-radius: 8px;
  background: #28292d;
  z-index: 10;
  padding: 50px 40px;
  display: flex;
  flex-direction: column;
}
.form h2 {
  color: #7F66FF;
  font-weight: 500;
  text-align: center;
  letter-spacing: 0.1em;
}
.inputBox {
  position: relative;
  width: 300px;
  margin-top: 35px;
}
.inputBox input {
  position: relative;
  width: 100%;
  padding: 20px 10px 10px;
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  font-size: 1em;
  letter-spacing: 0.05em;
  z-index: 10;
}
.inputBox span {
  position: absolute;
  left: 0;
  padding: 20px 0px 10px;
  font-size: 1em;
  color: #8f8f8f;
  pointer-events: none;
  letter-spacing: 0.05em;
  transition: 0.5s;
}
.inputBox input:valid ~ span,
.inputBox input:focus ~ span {
  color: #7F66FF;
  transform: translateX(0px) translateY(-34px);
  font-size: 0.75em;
}
.inputBox i {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 2px;
  background: #7F66FF;
  border-radius: 4px;
  transition: 0.5s;
  pointer-events: none;
  z-index: 9;
}
.inputBox input:valid ~ i,
.inputBox input:focus ~ i {
  height: 44px;
}
.links {
  display: flex;
  justify-content: space-between;
}
.links a {
  margin: 10px 0;
  font-size: 0.8em;
  color: #8f8f8f;
  text-decoration: none;
}
.links a:hover,
.links a:nth-child(2) {
  color: #7F66FF;
}
input[type="submit"] {
  border: none;
  outline: none;
  background: #7F66FF;
  padding: 11px 25px;
  width: 100px;
  color: #fff;
  margin-top: 10px;
  border-radius: 4px;
  font-weight: 500;
  cursor: pointer;
  transition: 0.5s ease;
}
input[type="submit"]:hover {
  background: #3240E1;
}

How to Use This Login Form?

  1. Copy and paste the HTML and CSS code into your project.
  2. Save the file and open it in a web browser.
  3. Customize the styles to match your website’s theme.

Final Thoughts

Creating an animated login form using HTML & CSS is simple yet effective in improving your website’s design. With the right animations and styling, you can enhance user interaction and make your login page stand out.

💡 Want More Cool UI Designs? Subscribe to our YouTube channel for more web design tutorials!

Comments