Password Reveal

Joined
Aug 16, 2022
Messages
61
Reaction score
2
Hi Everybody,

I've seen some password input boxes that look like this:
password.jpg

How could I make my password inputs behave the same way?
 
Joined
Jul 4, 2023
Messages
591
Reaction score
78
Have you tried something like this?
HTML:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">

<style>
  .password-container {
    position: relative;
    display: inline-block;
  }

  .password-container input {
    padding-right: 1.6rem;
  }

  .toggle-password {
    position: absolute;
    right: .35rem;
    top: 55%;
    transform: translateY(-50%);
    cursor: pointer;
    font-size: 1rem;
    color: gray;
  }
</style>

<div class="password-container">
  <input type="password" id="password" value="PaSsWoRd_ExAmPlE">
  <i class="fa-solid fa-eye toggle-password"></i>
</div>

<script>
  document.querySelector('.toggle-password')
    .addEventListener('click', function () {
    const password_input = document.querySelector('#password');
    const icon = this;

    if (password_input.type === 'password') {
      password_input.type = 'text';
      icon.classList.remove('fa-eye');
      icon.classList.add('fa-eye-slash');
    } else {
      password_input.type = 'password';
      icon.classList.remove('fa-eye-slash');
      icon.classList.add('fa-eye');
    }
  });
</script>
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top