Welcome Here And Thanks For Visiting. Like Us On Facebook...

EXEIdeas – Let's Your Mind Rock » HTML-CSS-PHP-JavaScript / JavaScript Codes » How To Add Password Eye Icon In Password Input Form Field?

How To Add Password Eye Icon In Password Input Form Field?

This Vanilla JavaScript code snippet helps you to create a password visibility eye icon toggle button to show/hide passwords. It gets the password input field and changes its type from password to text to show the entered password.

The snippet uses Font Awesome eye icon inside the password input field and Bootstrap CSS for basic input design. However, you can integrate it with Bootstrap 4/5 or with your custom-designed login/signup form.

There are many code snippets available online or on many other blogs and websites, but everyone cannot optimize your blog or website, so you need some optimized code snippets. So now checkout out the code snippet for your blog and website that will give you all features for your desired code. Now grab the ready-to-use code and paste it where you want.


  1. Light Weight.
  2. Pure JavaScript.
  3. Cross Browser.
  4. No JQuery Files.
  5. Fully Customizable.
  6. Responsive.

How To How To Add Password Eye Icon In Password Input Form Field??

There are a few easy and understandable steps to achieve your desired functionality that we are gonna share below. Follow each step perfectly.

Recommended For You:
How To Use HTML5 Local Storage In Your Web Page?


<link rel="stylesheet" href="" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"/>
<link rel="stylesheet" href=""/>


<div class="form-wrapper">
<form id="form_id" class="form-class">
<p class="input-group">
<input id="passInput" class="form-control" placeholder="Your Password" name="password" type="password" size="30" aria-required="false">
<span class="input-group-addon" role="button" title="veiw password" id="passBtn">
<i class="fa fa-eye fa-fw" aria-hidden="true"></i>


<script type="text/javascript">
const PassBtn = document.querySelector('#passBtn');
PassBtn.addEventListener('click', () => {
const input = document.querySelector('#passInput');
input.getAttribute('type') === 'password' ? input.setAttribute('type', 'text') : input.setAttribute('type', 'password');

if (input.getAttribute('type') === 'text'){
PassBtn.innerHTML = '<i class="fa fa-eye-slash"></i>';
} else{
PassBtn.innerHTML = '<i class="fa fa-eye fa-fw" aria-hidden="true"></i>';



No need to customize it. Just copy-paste. Rest edit the code as per comments and need.

Troubleshooting the Errors:

Do it with concentration and patience. Check your all steps again and all codes or scripts. If you find any error you can contact us anytime via comment or better via email, We are always here to help you.

Final Words:

That’s all we have. We hope that you liked this article. If you have any problem with this code in your template then feel free to contact us with a full explanation of your problem. We will reply to you as time allows us If you have any doubts or problems please comment below. We are happy to help you! If you liked this article, Don’t forget to share this with your friends so they can also take benefit from it and leave.

Recommended For You:
How To Set Or Specify Referring Page Using Pure JavaScript?

You Like It, Please Share This Recipe With Your Friends Using...

Be the first to write a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *