ADVERTISEMENT

Show and Hide Password With Eye Icon using HTML & JavaScript

Telegram Group Join Now

ADVERTISEMENT

Show and Hide Password With Eye Icon using HTML & JavaScript

Show and Hide Password With Eye Icon using HTML & JavaScript
Show and Hide Password With Eye Icon using HTML & JavaScript

 

ADVERTISEMENT

ADVERTISEMENT

Welcome to the Codewithrandom blog. In this blog, We learn how to create Show and Hide Password With Eye Icon. We use HTML, CSS, and JavaScript for this Show and Hide Password With Eye Icon.

I hope you enjoy our blog so let’s start with a basic html structure for a Show and Hide Password With Eye Icon.

ADVERTISEMENT

first, create your html file and add this font awesome CDN link in your html file or you can just paste this code in html head section. We need font awesome CDN for eye icon in input for show hide password.

ADVERTISEMENT

CDN link with Link Tag

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" integrity="sha512-Fo3rlrZj/k7ujTnHg4CGR2D7kSs0v4LLanw2qksYuRlEzO+tcaEPQogQ0KaoGN26/zrn20ImR1DfuLWnOo7aBA==" crossorigin="anonymous" referrerpolicy="no-referrer" />

HTML Code

<div class="password-field">
<input type="password" id="fakePassword" placeholder="Enter Password" />
<span><i id="toggler"class="far fa-eye"></i></span>
</div>

There is all the html code for the Show and Hide Password With Eye Icon. Now, you can see output without Css and JavaScript. then we write Css for styling and add javascript code for the show to hide the password.

Restaurant Website Using HTML and CSS

output

ADVERTISEMENT

 

Show and Hide Password With Eye Icon using HTML & JavaScript

 

CSS Code

* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
width: 100%;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: #f4f4f4;
flex-direction: column;
}
body .password-field {
position: relative;
}
body .password-field input {
width: 30rem;
height: 4em;
padding: 1em;
border: 0;
border-radius: 10px;
box-shadow: 0px 10px 40px rgba(0, 0, 0, 0.5);
font-size: 1rem;
letter-spacing: 1px;
}
body .password-field input::placeholder {
color: #000;
font-weight: bold;
}
body .password-field #toggler {
position: absolute;
right: 20px;
top: 50%;
transform: translateY(-50%);
cursor: pointer;
}

Now we have completed our Styling Of Input and eye icon. Here is our updated output HTML+ CSS.

ADVERTISEMENT

Portfolio Website using HTML and CSS (Source Code)

ADVERTISEMENT

Output

Show and Hide Password With Eye Icon using HTML & JavaScript

 

Show and Hide Password With Eye Icon using HTML & JavaScript

Ecommerce Website Using HTML, CSS, & JavaScript (Source Code)

Now add JavaScript to toggle Show and Hide Password On Click Eye Icon.

Javascript Code

var password = document.getElementById('fakePassword');
var toggler = document.getElementById('toggler');
showHidePassword = () => {
if (password.type == 'password') {
password.setAttribute('type', 'text');
toggler.classList.add('fa-eye-slash');
} else {
toggler.classList.remove('fa-eye-slash');
password.setAttribute('type', 'password');
}
};
toggler.addEventListener('click', showHidePassword);

Final Output Of Show and Hide Password With Eye Icon

ADVERTISEMENT

 

ADVERTISEMENT

Show and Hide Password With Eye Icon using HTML & JavaScript

 

ADVERTISEMENT

Show and Hide Password With Eye Icon using HTML & JavaScript
Show and Hide Password With Eye Icon using HTML & JavaScript

100+ JavaScript Projects With Source Code ( Beginners to Advanced)

ADVERTISEMENT

Now we have completed our Show and Hide Password With Eye Icon. Here is our updated output with Html, Css, and JavaScript. Hope you like the Project. you can see the output video and project screenshots. See our other blogs and gain knowledge in front-end development.

ADVERTISEMENT

Thank you!

In this post, we learn how to create a Show and Hide Password With Eye Icon using HTML & JavaScript. If we made a mistake or any confusion, please drop a comment to reply or help you in easy learning.

Written by – Code With Random/Anki 

ADVERTISEMENT

Telegram Group Join Now

Share on:

Leave a Comment

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT