Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    How to create Netflix Intro Animation using HTML and CSS

    29 June 2025

    How to create Order Confirm Animation using HTML CSS and JS

    27 June 2025

    How to create Social media popup hover menu using HTML and CSS

    25 June 2025
    Facebook X (Twitter) Instagram YouTube Telegram Threads
    Coding StellaCoding Stella
    • Home
    • Blog
    • HTML & CSS
      • Login Form
    • JavaScript
    • Hire us!
    Coding StellaCoding Stella
    Home - JavaScript - How to make Password Generator in HTML CSS & JavaScript
    JavaScript

    How to make Password Generator in HTML CSS & JavaScript

    Coding StellaBy Coding Stella16 February 2024Updated:13 June 2025No Comments6 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Email WhatsApp Copy Link

    Let’s make a Password Generator using HTML, CSS, and JavaScript. This project is great for beginners and will help you learn how to create a useful tool.

    We’ll use HTML to set up the basic structure, CSS to make it look nice, and JavaScript to make the generator work. No need for anything fancy – just simple coding!

    Let’s start building this Password Generator. It’s perfect for anyone who wants to learn coding or needs a handy tool. Let’s begin and make generating passwords easy!

    HTML :

    The provided code is an HTML document for a password generator interface. It includes a container with a heading, input fields, a password strength indicator, length options, and checkboxes for password settings. There’s also a button to generate passwords. The document links to an external CSS file for styling and an external JavaScript file for functionality. The fonts “Material Symbols Rounded” and “Montserrat” are imported from Google Fonts.

    <!DOCTYPE html>
    <html lang="en" >
    <head>
      <meta charset="UTF-8">
      <title>Password Generator</title>
      <link rel='stylesheet' href='https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200'>
    <link rel='stylesheet' href='https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500&amp;display=swap'><link rel="stylesheet" href="./style.css">
    
    </head>
    <body>
    <!-- partial:index.partial.html -->
    <div class="container">
      <h2>Password Generator</h2>
      <div class="wrapper">
        <div class="input-box">
          <input type="text" disabled>
          <span class="material-symbols-rounded">copy_all</span>
        </div>
        <div class="pass-indicator"></div>
        <div class="pass-length">
          <div class="details">
            <label class="title">Password Length</label>
            <span></span>
          </div>
          <input type="range" min="1" max="30" value="15" step="1">
        </div>
        <div class="pass-settings">
          <label class="title">Password Settings</label>
          <ul class="options">
            <li class="option">
              <input type="checkbox" id="lowercase" checked>
              <label for="lowercase">Lowercase (a-z)</label>
            </li>
            <li class="option">
              <input type="checkbox" id="uppercase">
              <label for="uppercase">Uppercase (A-Z)</label>
            </li>
            <li class="option">
              <input type="checkbox" id="numbers">
              <label for="numbers">Numbers (0-9)</label>
            </li>
            <li class="option">
              <input type="checkbox" id="symbols">
              <label for="symbols">Symbols (!-$^+)</label>
            </li>
            <li class="option">
              <input type="checkbox" id="exc-duplicate">
              <label for="exc-duplicate">Exclude Duplicate</label>
            </li>
            <li class="option">
              <input type="checkbox" id="spaces">
              <label for="spaces">Include Spaces</label>
            </li>
          </ul>
        </div>
        <button class="generate-btn">Generate Password</button>
      </div>
    </div>
    <!-- partial -->
      <script  src="./script.js"></script>
    
    </body>
    </html>

    CSS :

    This CSS code styles a password generator interface with a modern look. It uses the “Montserrat” font and a gradient background. Input fields, a password strength indicator, length options, and checkboxes for settings are styled. The generate button has hover and active effects. The design is responsive for smaller screens.

    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
      font-family: "Montserrat", sans-serif;
      color: #fff;
    }
    
    body {
      display: flex;
      align-items: center;
      justify-content: center;
      min-height: 100vh;
      background: linear-gradient(180deg, #070807 50%, #dca314 50%);
    }
    
    .container {
      width: 430px;
      background: #222;
      border-radius: 7px;
      box-shadow: 0 10px 20px rgba(0, 0, 0, 0.05);
    }
    
    .container h2 {
      font-weight: 600;
      font-size: 21px;
      padding: 16px 30px;
      border-bottom: 1px solid #444;
      text-align: center;
    }
    
    .wrapper {
      margin: 20px 30px;
    }
    
    .input-box {
      position: relative;
    }
    
    .input-box input {
      width: 100%;
      height: 53px;
      color: #fff;
      background: none;
      font-size: 17px;
      font-weight: 500;
      border-radius: 4px;
      letter-spacing: 1.4px;
      border: 1px solid #555;
      padding: 0 48px 0 16px;
    }
    
    .input-box span {
      position: absolute;
      right: 13px;
      cursor: pointer;
      line-height: 53px;
      color: #aaa;
    }
    
    .input-box span:hover {
      color: #4285f4 !important;
    }
    
    .pass-indicator {
      width: 100%;
      height: 4px;
      position: relative;
      background: #333;
      margin-top: 12px;
      border-radius: 25px;
    }
    
    .pass-indicator::before {
      position: absolute;
      content: "";
      height: 100%;
      width: 0;
      border-radius: inherit;
      transition: width 0.3s ease;
    }
    
    .pass-indicator#weak::before {
      width: 20%;
      background: #e64a4a;
    }
    
    .pass-indicator#medium::before {
      width: 50%;
      background: #f1c80b;
    }
    
    .pass-indicator#strong::before {
      width: 100%;
      background: #27c468;
    }
    
    .pass-length {
      margin: 25px 0 20px;
    }
    
    .pass-length .details {
      display: flex;
      justify-content: space-between;
    }
    
    .pass-length input {
      width: 100%;
      height: 5px;
    }
    
    .pass-settings .options {
      display: flex;
      list-style: none;
      flex-wrap: wrap;
      margin-top: 20px;
    }
    
    .pass-settings .options .option {
      display: flex;
      align-items: center;
      margin-bottom: 20px;
      width: 50%;
    }
    
    .options .option:first-child {
      pointer-events: none;
    }
    
    .options .option:first-child input {
      opacity: 0.7;
    }
    
    .options .option input {
      height: 16px;
      width: 16px;
      cursor: pointer;
    }
    
    .options .option label {
      cursor: pointer;
      color: #aaa;
      padding-left: 16px;
    }
    
    .generate-btn {
      width: 100%;
      color: #fff;
      border: none;
      outline: none;
      cursor: pointer;
      background: #444;
      font-size: 17px;
      padding: 15px 0;
      border-radius: 5px;
      text-transform: uppercase;
      margin: 15px 0 20px;
      transition: background 0.3s ease, transform 0.2s ease;
    }
    
    .generate-btn:hover {
      background: #333;
    }
    
    .generate-btn:active {
      transform: scale(0.95);
    }
    
    @media (max-width: 768px) {
      .container {
        width: 90%;
      }
    }

    JavaScript:

    The provided code is a JavaScript code snippet that creates a password generator functionality. It includes event listeners, functions, and variables to generate a random password based on user-selected options.

    The event listeners are set up to trigger the corresponding functions when certain events occur, such as clicking the copy icon, changing the password length slider, or clicking the generate button.

    Overall, this code provides a functional password generator interface with options for customizing the password length and character types.

    const lengthSlider = document.querySelector(".pass-length input"),
      options = document.querySelectorAll(".option input"),
      copyIcon = document.querySelector(".input-box span"),
      passwordInput = document.querySelector(".input-box input"),
      passIndicator = document.querySelector(".pass-indicator"),
      generateBtn = document.querySelector(".generate-btn");
    
    const characters = {
      lowercase: "abcdefghijklmnopqrstuvwxyz",
      uppercase: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
      numbers: "0123456789",
      symbols: "^!$%&|[](){}:;.,*+-#@<>~"
    };
    
    const generatePassword = () => {
      let staticPassword = "",
        randomPassword = "",
        excludeDuplicate = false,
        passLength = lengthSlider.value;
    
      options.forEach((option) => {
        if (option.checked) {
          if (option.id !== "exc-duplicate" && option.id !== "spaces") {
            staticPassword += characters[option.id];
          } else if (option.id === "spaces") {
            staticPassword += `  ${staticPassword}  `;
          } else {
            excludeDuplicate = true;
          }
        }
      });
    
      for (let i = 0; i < passLength; i++) {
        let randomChar =
          staticPassword[Math.floor(Math.random() * staticPassword.length)];
        if (excludeDuplicate) {
          !randomPassword.includes(randomChar) || randomChar == " "
            ? (randomPassword += randomChar)
            : i--;
        } else {
          randomPassword += randomChar;
        }
      }
      passwordInput.value = randomPassword;
    };
    
    const updatePassIndicator = () => {
      passIndicator.id =
        lengthSlider.value <= 8
          ? "weak"
          : lengthSlider.value <= 16
          ? "medium"
          : "strong";
    };
    
    const updateSlider = () => {
      document.querySelector(".pass-length span").innerText = lengthSlider.value;
      generatePassword();
      updatePassIndicator();
    };
    updateSlider();
    
    const copyPassword = () => {
      navigator.clipboard.writeText(passwordInput.value);
      copyIcon.innerText = "check";
      copyIcon.style.color = "#4285F4";
      setTimeout(() => {
        copyIcon.innerText = "copy_all";
        copyIcon.style.color = "#707070";
      }, 1500);
    };
    
    copyIcon.addEventListener("click", copyPassword);
    lengthSlider.addEventListener("input", updateSlider);
    generateBtn.addEventListener("click", generatePassword);

    In conclusion, creating a Password Generator using HTML, CSS, and JavaScript is a fantastic way to learn coding while building a useful tool. By using simple words and basic coding techniques, beginners can easily follow along and gain valuable skills.

    If your project has problems, don’t worry. Just click to download the source code and face your coding challenges with excitement. Have fun coding!

    Password Generator
    Share. Copy Link Twitter Facebook LinkedIn Email WhatsApp
    Previous ArticleHow to make Alarm App in HTML CSS & JavaScript
    Next Article Backend Developer Skills: Definition, Languages & Examples
    Coding Stella
    • Website

    Related Posts

    JavaScript

    How to create Order Confirm Animation using HTML CSS and JS

    27 June 2025
    JavaScript

    How to create Valentine’s Love Button Animation using HTML CSS and JS

    23 June 2025
    JavaScript

    How to create Magic Indicator Menu using HTML CSS and JS

    20 June 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Trending Post

    Master Frontend in 100 Days Ebook

    2 March 202420K Views

    How to make Modern Login Form using HTML & CSS | Glassmorphism

    11 January 202418K Views

    How to make I love you Animation in HTML CSS & JavaScript

    14 February 202416K Views

    How to make Valentine’s Day Card using HTML & CSS

    13 February 202412K Views
    Follow Us
    • Instagram
    • Facebook
    • YouTube
    • Twitter
    ads
    Featured Post

    Learn CSS By Playing Games

    26 January 2024

    How to make Sort the bubble clock using HTML CSS & JavaScript

    20 July 2024

    Best Programming Languages for Web Development

    25 January 2024

    5 Simple Ways to Center a Div in CSS

    24 January 2024
    Latest Post

    How to create Netflix Intro Animation using HTML and CSS

    29 June 2025

    How to create Order Confirm Animation using HTML CSS and JS

    27 June 2025

    How to create Social media popup hover menu using HTML and CSS

    25 June 2025

    How to create Valentine’s Love Button Animation using HTML CSS and JS

    23 June 2025
    Facebook X (Twitter) Instagram YouTube
    • About Us
    • Privacy Policy
    • Return and Refund Policy
    • Terms and Conditions
    • Contact Us
    • Buy me a coffee
    © 2025 Coding Stella. Made with 💙 by @coding.stella

    Type above and press Enter to search. Press Esc to cancel.

    Ad Blocker Enabled!
    Ad Blocker Enabled!
    Looks like you're using an ad blocker. We rely on advertising to help fund our site.
    Okay! I understood