How to make Password Generator Using HTML, CSS, & JavaScript

How to make Password Generator Using HTML, CSS, & JavaScript

How to make Password Generator Using HTML, CSS, & JavaScript

Hello everyone. Welcome to today’s tutorial on Codewithrandom. This project will help to create a random password that will contain all characters and symbols mixed and complex. In Today’s session, We will use HTML, CSS, and JavaScript to complete this Project. The HTML (Hypertext Markup Language) will help us to create the structure for the list with some necessary attributes and elements.

Then we will use CSS (Cascading Stylesheet) which will help us to style or design the project with suitable padding and alignment. At last, we will use JS (JavaScript) which will add logic to make the project responsive from the user end.

In this article, we present How to make Password Generator Using HTML, CSS, &JavaScript with complete source code for you so you can copy and paste it into your project.

I hope you have got an idea about the project.

HTML Code for Password Generator

<html lang="en">
    <title>Random Password Generator</title>
    <!--Fontawesome Icons-->
    <link rel="stylesheet" href="">
    <!--Google Font-->
    <link rel="preconnect" href="">
    <link href="" rel="stylesheet">
    <link rel="stylesheet" href="style.css">
    <div class="container">
        <input type="text" id="output">
            <i class="fas fa-random" onclick="genPassword()"></i>
            <i class="far fa-copy" onclick="copyClipboard()"></i>
        <input type="range" id="length" min="8" max="20" value="8" oninput="genPassword()">
        <h3 id="length-val">8</h3>

<script src="script.js"></script>

First, we’ll start with creating the structure of the Random Password Generator project for that as you can see in the above code we have used all the necessary elements & attributes. We have used a button and range bar so that it is an indicator of the password length. Let us know code the CSS part to add styling and aligned the tags.

How To Create OTP Input Field Using HTML, CSS,&Javascript

CSS Code for Password Generator

    padding: 0;
    margin: 0;
    box-sizing: border-box;
    outline: none;
    height: 100vh;
    background: linear-gradient(
    width: 40%;
    min-width: 450px;
    background-color: #1c1e21;
    padding: 80px 30px;
    position: absolute;
    transform: translate(-50%,-50%);
    top: 50%;
    left: 50%;
    border-radius: 8px;
    box-shadow: 0 15px 20px rgba(0,0,0,0.15);
    background-color: transparent;
    border-bottom: 2px solid #e2e2e2;
    width: 75%;
    height: 35px;
    padding: 20px 5px;
    font-family: 'Roboto Mono', monospace;
    color: #f5f5f5;
    font-size: 18px;
    letter-spacing: 1px;
    width: 11%;
    height: 38px;
    background-color: transparent;
    border: none;
    color: #ffffff;
    font-size: 18px;
    float: right;
    text-align: right;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    width: 85%;
    height: 3.5px;
    margin-top: 80px;
    background-color: #e2e2e2;
    border-radius: 3.5px;
    -webkit-appearance: none;
    appearance: none;
    height: 20px;
    width: 20px;
    background-color: #008bfd;
    border-radius: 50%;
    font-family: 'Roboto Mono',sans-serif;
    display: inline-block;
    width: 10%;
    color: #1c1e21;
    background-color: #ffffff;
    text-align: center;
    padding: 5px 0;
    margin-left: 3%;
    border-radius: 3px;
    font-size: 18px;

Second, comes the CSS code which we have styled for the structure we have padded as well as aligned the Random Password Generator project so that it is properly situated and doesn’t get messy with suitable CSS elements. Now, let’s code the JavaScript part to make it responsive.

Quiz App with Timer using HTML, CSS, &JavaScript

JavaScript Code for Password Generator

const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!\"$%&/()=?@~`\\.\';:+=^*_-0123456789';
let output = document.getElementById("output");

function randomValue(value){
    return Math.floor(Math.random()*value);

function genPassword(){
    let length = document.getElementById('length').value;
    document.getElementById("length-val").textContent = length;
    let str = '';

    for(let i=0; i<length ; i++){
        let random = randomValue(characters.length);
        str += characters.charAt(random);
    output.value = str;


function copyClipboard(){;
    alert("Password Copied!");

Last stage of the project the JavaScript which we added the logic and coded as per the requirement with some conditions. Then we created a logic to randomize the character while providing the password. Let us see the Final Output of the project on how to make a Password Generator Using HTML, CSS, &JavaScript.

Final Output Of Password Generator Using HTML, CSS, & JavaScript

We have successfully created our How to make Password Generator Using HTML, CSS, &JavaScript.  You can use this project for your personal needs and the respective lines of code are given with the code pen link mentioned above.

If you find out this Blog helpful, then make sure to search codewithrandom on google for Front End Projects with Source codes and make sure to Follow the Code with Random Instagram page.

Thank You And Happy Learning!!!

Code Idea – codingartist

Written By – Harsh Sawant

Code By – @harshh9

Leave a Reply