Responsive Login & Registration Form Using HTML, CSS & JavaScript code

Features

  • Smooth sliding animation between Login and Register
  • Fully responsive on mobile and desktop.
  • Clean UI inspired by modern web design trends
  • Uses vanilla JS for simplicity
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title>Login & Registration Form</title> <link rel="stylesheet" href="style.css" /> </head> <body> <div class="container" id="container"> <!-- Login Form --> <div class="form-container sign-in"> <form id="loginForm"> <h1>Login</h1> <input type="email" placeholder="Email" required /> <input type="password" placeholder="Password" required /> <button type="submit">Sign In</button> <p>Don't have an account? <a href="#" onclick="toggleForms()">Register</a></p> </form> </div> <!-- Register Form --> <div class="form-container sign-up"> <form id="registerForm"> <h1>Create Account</h1> <input type="text" placeholder="Name" required /> <input type="email" placeholder="Email" required /> <input type="password" placeholder="Password" required /> <button type="submit">Sign Up</button> <p>Already have an account? <a href="#" onclick="toggleForms()">Login</a></p> </form> </div> <!-- Toggle Button --> <div class="toggle-container"> <div class="toggle"> <div class="toggle-panel toggle-left"> <h1>Welcome Back!</h1> <p>To keep connected please login with your personal info</p> <button class="hidden" id="signIn" onclick="toggleForms()">Sign In</button> </div> <div class="toggle-panel toggle-right"> <h1>Hello, Friend!</h1> <p>Enter your personal details and start your journey with us</p> <button class="hidden" id="signUp" onclick="toggleForms()">Sign Up</button> </div> </div> </div> </div> <script src="script.js"></script> </body> </html>
CSS provides style to an HTML page. To make the page attractive create a CSS file with the name style.css and remember that you have to make a file with a .css extension.


* {
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #f6f5f7;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  margin: 0;
}

.container {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
  position: relative;
  overflow: hidden;
  width: 768px;
  max-width: 100%;
  min-height: 480px;
}

.form-container {
  position: absolute;
  top: 0;
  height: 100%;
  transition: all 0.6s ease-in-out;
}

.sign-in {
  left: 0;
  width: 50%;
  z-index: 2;
}

.sign-up {
  left: 0;
  width: 50%;
  opacity: 0;
  z-index: 1;
}

.container.right-panel-active .sign-in {
  transform: translateX(100%);
}

.container.right-panel-active .sign-up {
  transform: translateX(100%);
  opacity: 1;
  z-index: 5;
}

form {
  background: #ffffff;
  display: flex;
  flex-direction: column;
  padding: 0 50px;
  height: 100%;
  justify-content: center;
  align-items: center;
  text-align: center;
}

input {
  background: #eee;
  border: none;
  padding: 12px 15px;
  margin: 8px 0;
  width: 100%;
}

button {
  border-radius: 20px;
  border: 1px solid #ff4b2b;
  background: #ff4b2b;
  color: #ffffff;
  font-size: 12px;
  padding: 10px 40px;
  letter-spacing: 1px;
  text-transform: uppercase;
  transition: transform 80ms ease-in;
  cursor: pointer;
  margin-top: 10px;
}

button:hover {
  background-color: #e94e2d;
}

button:active {
  transform: scale(0.95);
}

button:focus {
  outline: none;
}

hr {
  border: none;
  height: 1px;
  background: #eee;
  margin: 20px 0;
}

.toggle-container {
  position: absolute;
  top: 0;
  left: 50%;
  width: 50%;
  height: 100%;
  overflow: hidden;
  transition: transform 0.6s ease-in-out;
  z-index: 1000;
}

.container.right-panel-active .toggle-container {
  transform: translateX(-100%);
}

.toggle {
  background: #ff4b2b;
  height: 100%;
  color: #fff;
  position: relative;
  left: -100%;
  height: 100%;
  width: 200%;
  transform: translateX(0);
  transition: transform 0.6s ease-in-out;
}

.container.right-panel-active .toggle {
  transform: translateX(50%);
}

.toggle-panel {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 40px;
  text-align: center;
  top: 0;
  height: 100%;
  width: 50%;
  transform: translateX(0);
  transition: all 0.6s ease-in-out;
}

.toggle-left {
  transform: translateX(-200%);
}

.container.right-panel-active .toggle-left {
  transform: translateX(0);
}

.toggle-right {
  right: 0;
  transform: translateX(0);
}

.container.right-panel-active .toggle-right {
  transform: translateX(200%);
}

@media (max-width: 768px) {
  .container {
    width: 100vw;
    min-height: 100vh;
  }

  .form-container {
    width: 100%;
  }

  .toggle-container {
    display: none;
  }
}
JavaScript makes the page work functionally. At last, create a JavaScript file with the name of script.js, and remember that you've got to make a file with a .js extension.


const container = document.getElementById("container");

function toggleForms() {
  container.classList.toggle("right-panel-active");
}
We hope you Like this Post Thanks for coming Here

Thank you
Learning robo team

Post a Comment

Thank you
Learning robo team

Post a Comment (0)

Previous Post Next Post
Learning Robo says...
code copied