- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Environmental Science
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- articles and Answers
- Effective Resume Writing
- HR Interview articles
- Computer Glossary
- Who is Who
Create Beautiful Login Page Using HTML and JS
Hello Friend, In this tutorial we will learn to create beautiful login page using HTML and JavaScript:
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Beautiful Login Page</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="container">
<form class="login-form" action="" method="post">
<h2>Login</h2>
<div class="input-group">
<label for="username">Username</label>
<input type="text" id="username" name="username" required>
</div>
<div class="input-group">
<label for="password">Password</label>
<input type="password" id="password" name="password" required>
</div>
<button type="submit">Login</button>
<p class="message">Not registered? <a href="#">Create an account</a></p>
</form>
</div>
<script src="script.js"></script>
</body>
</html>
CSS:
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
background-color: #f2f2f2;
}
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.login-form {
background-color: #fff;
border-radius: 5px;
box-shadow: 0px 0px 10px rgba(0,0,0,0.1);
padding: 40px;
width: 400px;
}
h2 {
margin-top: 0;
}
.input-group {
margin-bottom: 20px;
}
label {
display: block;
font-weight: bold;
margin-bottom: 5px;
}
input[type="text"],
input[type="password"] {
padding: 10px;
width: 100%;
border-radius: 3px;
border: none;
box-shadow: 0px 0px 5px rgba(0,0,0,0.1);
}
button[type="submit"] {
background-color: #4CAF50;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 3px;
cursor: pointer;
}
button[type="submit"]:hover {
background-color: #3e8e41;
}
.message {
margin-top: 20px;
font-size: 14px;
text-align: center;
}
.message a {
color: #4CAF50;
text-decoration: none;
}
JavaScript:
const form = document.querySelector(".login-form");
const usernameInput = document.getElementById("username");
const passwordInput = document.getElementById("password");
form.addEventListener("submit", (event) => {
event.preventDefault();
const usernameValue = usernameInput.value.trim();
const passwordValue = passwordInput.value.trim();
if (usernameValue === "" || passwordValue === "") {
alert("Please enter a username and password.");
} else {
// Login logic goes here
}
});
Note: This is just an example, you can modify the code to fit your specific requirements and design preferences.
Advertisements
ads