How to Create Advance Password Generator in HTML
This tutorial will guide you through creating a Advance Password Generator using HTML, CSS & JavaScript. Follow all the given step :
Step 1 : Create Index.html and add given html code on it.
Step 2 : Create style.css and add given css code on it.
Step 3 : Create index.js and add given JavaScript code on it.
HTML
HTML Code for Advance Password Generator
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Password Generator</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>Password Generator</h1>
<div class="pss">
<input type="text" id="password" readonly>
<button onclick="copyPassword()" id="copy-button" style="display: none;">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="currentColor" class="bi bi-copy" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M4 2a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2zm2-1a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1zM2 5a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1v-1h1v1a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h1v1z"/>
</svg>
</button>
<div class="message" id="copy-message">Password copied to clipboard!</div>
</div>
<br><br>
<div class="content">
<input type="checkbox" id="uppercase" style="display: none;">
<label for="uppercase" class="check">
<svg width="18px" height="18px" viewBox="0 0 18 18">
<path d="M1,9 L1,3.5 C1,2 2,1 3.5,1 L14.5,1 C16,1 17,2 17,3.5 L17,14.5 C17,16 16,17 14.5,17 L3.5,17 C2,17 1,16 1,14.5 L1,9 Z"></path>
<polyline points="1 9 7 14 15 4"></polyline>
</svg> UpperCase Letters
</label>
</div>
<div class="content">
<input type="checkbox" id="lowercase" style="display: none;">
<label for="lowercase" class="check">
<svg width="18px" height="18px" viewBox="0 0 18 18">
<path d="M1,9 L1,3.5 C1,2 2,1 3.5,1 L14.5,1 C16,1 17,2 17,3.5 L17,14.5 C17,16 16,17 14.5,17 L3.5,17 C2,17 1,16 1,14.5 L1,9 Z"></path>
<polyline points="1 9 7 14 15 4"></polyline>
</svg> LowerCase Letters
</label>
</div>
<div class="content">
<input type="checkbox" id="numbers" style="display: none;">
<label for="numbers" class="check">
<svg width="18px" height="18px" viewBox="0 0 18 18">
<path d="M1,9 L1,3.5 C1,2 2,1 3.5,1 L14.5,1 C16,1 17,2 17,3.5 L17,14.5 C17,16 16,17 14.5,17 L3.5,17 C2,17 1,16 1,14.5 L1,9 Z"></path>
<polyline points="1 9 7 14 15 4"></polyline>
</svg> Numbers
</label>
</div>
<div class="content">
<input type="checkbox" id="symbols" style="display: none;">
<label for="symbols" class="check">
<svg width="18px" height="18px" viewBox="0 0 18 18">
<path d="M1,9 L1,3.5 C1,2 2,1 3.5,1 L14.5,1 C16,1 17,2 17,3.5 L17,14.5 C17,16 16,17 14.5,17 L3.5,17 C2,17 1,16 1,14.5 L1,9 Z"></path>
<polyline points="1 9 7 14 15 4"></polyline>
</svg> Symbols
</label>
</div>
<div class="content">
<label for="password-length">Password Length:</label>
</div>
<div class="content2">
<input type="range" id="password-length" min="4" max="20" value="8">
<span id="length-value">8</span>
</div>
<button onclick="generatePassword()">Generate Password</button>
</div>
<script src="index.js"></script>
</body>
</html>
CSS
CSS Code for Advance Password Generator
body{
font-family: Arial, Helvetica, sans-serif;
text-align: center;
background: #252525;
}
.container{
background: #ffffff;
height: 520px;
width: 450px;
padding: 10px;
border-radius: 10px;
margin: 70px auto;
}
#password{
padding: 10px;
width: 60%;
height: 20px;
outline: none;
border-radius: 50px;
border: 1px solid #000;
}
button{
margin-top: 30px;
padding: 12px 30px;
background-color: #5bd55b;
color: #2b2b2b;
border: none;
border-radius: 25px;
cursor: pointer;
}
button:hover{
background: #4af566;
}
#password-length{
width: 250px;
margin-top: 20px;
}
#copy-button{
background: transparent;
margin-left: -60px;
top: 130px;
position: absolute;
color: #000;
display: none;
}
.message{
display: none;
margin-top: 10px;
color: green;
margin-bottom: -25px;
}
.content{
display: flex;
padding: 10px;
width: 300px;
margin: 0 auto;
margin-top: 5px;
}
#length-value{
background: #92f092;
padding: 10px;
border-radius: 5px;
font-size: 14px;
}
.check{
cursor: pointer;
}
.check svg{
position: relative;
z-index: 1;
fill: none;
stroke-linecap: round;
stroke-linejoin: round;
stroke: #0055ff;
margin-bottom: -3px;
stroke-width: 1.5;
transform: translate3d(0, 0, 0);
transition: all 0.2s ease;
}
.check svg path{
stroke-dasharray: 60;
stroke-dashoffset: 0;
}
.check svg polyline{
stroke-dashoffset: 66;
stroke-dasharray: 22;
}
.check:hover::before{
opacity: 1;
}
.check:hover svg{
stroke: #4285f4;
}
#uppercase:checked + .check svg{
stroke: #4285f4;
}
#uppercase:checked + .check svg path{
stroke-dashoffset: 60;
transition: all 0.3s linear;
}
#uppercase:checked + .check svg polyline{
stroke-dashoffset: 42;
transition: all 0.2s linear;
transition-delay: 0.15s;
}
#lowercase:checked + .check svg{
stroke: #4285f4;
}
#lowercase:checked + .check svg path{
stroke-dashoffset: 60;
transition: all 0.3s linear;
}
#lowercase:checked + .check svg polyline{
stroke-dashoffset: 42;
transition: all 0.2s linear;
transition-delay: 0.15s;
}
#numbers:checked + .check svg{
stroke: #4285f4;
}
#numbers:checked + .check svg path{
stroke-dashoffset: 60;
transition: all 0.3s linear;
}
#numbers:checked + .check svg polyline{
stroke-dashoffset: 42;
transition: all 0.2s linear;
transition-delay: 0.15s;
}
#symbols:checked + .check svg{
stroke: #4285f4;
}
#symbols:checked + .check svg path{
stroke-dashoffset: 60;
transition: all 0.3s linear;
}
#symbols:checked + .check svg polyline{
stroke-dashoffset: 42;
transition: all 0.2s linear;
transition-delay: 0.15s;
}
JavaScript
JavaScript code for Advance Password Generator
function generatePassword() {
var length = document.getElementById("password-length").value;
var uppercase = document.getElementById("uppercase").checked;
var lowercase = document.getElementById("lowercase").checked;
var numbers = document.getElementById("numbers").checked;
var symbols = document.getElementById("symbols").checked;
var charset = "";
if (uppercase) charset += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if (lowercase) charset += "abcdefghijklmnopqrstuvwxyz";
if (numbers) charset += "0123456789";
if (symbols) charset += "!@#$%^&*()_+[]{}|;:,.<>?";
var password = "";
for (var i = 0; i < length; i++) {
var randomIndex = Math.floor(Math.random() * charset.length);
password += charset.charAt(randomIndex);
}
document.getElementById("password").value = password;
document.getElementById("copy-button").style.display = "inline-block";
document.getElementById("copy-message").style.display = "none";
}
function copyPassword() {
var passwordText = document.getElementById("password").value;
navigator.clipboard.writeText(passwordText).then(function() {
document.getElementById("copy-message").style.display = "block";
}, function() {
alert("Failed to copy password.");
});
}
document.getElementById("password-length").addEventListener("input", function() {
document.getElementById("length-value").textContent = this.value;
});
What is HTML
HTML, or HyperText Markup Language, is the standard markup language used to create and design documents on the World Wide Web. It's essentially the backbone of web pages, providing the structure and content that web browsers interpret and display.
HTML consists of a series of elements, which are enclosed by tags to define their purpose and function on a webpage. These elements can include headings, paragraphs, images, links, lists, forms, and more. By using a combination of HTML elements, web developers can organize and present information in a structured and visually appealing manner.
HTML is not a programming language but rather a markup language. This means it doesn't have the capability to perform calculations or execute complex logic like programming languages do. Instead, HTML focuses on describing the structure and content of a document, leaving the presentation and functionality to other technologies like CSS (Cascading Style Sheets) for styling and JavaScript for interactivity.
In summary, HTML serves as the foundation for building web pages, providing the structure and content necessary for browsers to render and display information to users on the internet.
What is CSS
CSS, or Cascading Style Sheets, is a language used to style the presentation of web documents written in HTML and XML. It provides a way to control the layout, colors, fonts, and other visual aspects of a webpage, enabling developers to create attractive and responsive designs. By separating content from presentation, CSS promotes cleaner code, easier maintenance, and greater flexibility in website design. With CSS, developers can achieve consistent branding, improved user experience, and better accessibility across various devices and screen sizes.
What is JavaScript
JavaScript is a versatile programming language used for creating dynamic and interactive web content. It enables developers to manipulate HTML elements, respond to user actions, and build seamless web applications. With its extensive ecosystem of libraries and frameworks, JavaScript powers both client-side and server-side development, making it an essential tool for modern web development.