How to Create Awesome Toggle Password Visibility in HTML

 

How to Create Awesome Toggle Password Visibility in HTML





This tutorial will guide you through creating a Awesome Toggle Password Visibility 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 Awesome Toggle Password Visibility


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Awesome Toggle Password Visibility</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="password-holder">
        <input type="password" name="password" class="password-box" id="passwordBox" placeholder="Enter Your Password...">
        <span id="light"></span>

        <img src="./img/flashlight-off.png" alt="flashlight-off" onclick="lighton()" class="flashlight" id="flashlight">
    </div>

    <script src="index.js"></script>
</body>
</html>
    


CSS


CSS Code for Awesome Toggle Password Visibility

    
*,body{
    margin: 0;
    padding: 0;
    font-family: sans-serif;
}
input{
    background: transparent;
}
.password-holder{
    width: 100%;
    height: 100vh;
    background: #0a0a0a;
    display: flex;
    justify-content: center;
    align-items: center;
}
.password-box{
    z-index: 1;
    position: relative;
    padding: 10px 120px 10px 20px;
    width: 500px;
    height: 40px;
    background-color: transparent;
    border: 2px solid white;
    border-radius: 10px;
    color: #fff;
    font-size: 20px;
    outline: none;
}
.flashlight{
    width: 45px;
    height: 45px;
    z-index: 1;
    position: relative;
    background: none;
    border: none;
    margin-left: -70px;
    transition: 0.5s ease;
    cursor: pointer;
}
#light{
    position: absolute;
    width: 600px;
    height: 120px;
    background: none;
    clip-path: polygon(0% 0%, 100% 40%, 100% 60%, 0% 100%);
    margin-left: -75px;
}
    


JavaScript


JavaScript code for Awesome Toggle Password Visibility

            
function lighton() {
    let spanElement = document.getElementById("light");
    let passwordBox = document.getElementById("passwordBox");
    let flashlight = document.getElementById("flashlight");

    if (spanElement.style.background === "none") {
        spanElement.style.background = "linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.5), white)";
        passwordBox.type = "text";
        flashlight.src = "./img/flashlight-on.png"
    } else{
        spanElement.style.background = "none";
        passwordBox.type = "password";
        flashlight.src = "./img/flashlight-off.png";
    }
}
    






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.