Password Hide and Show with Toggle Emoji Button using JavaScript

In this tutorial we will see how to make Password Field Hide and Show with Toggle Emoji Button using JavaScript. We have used monkey emoji for this purpose, CSS and JavaScript code is given.

HTML Code

Take a look at the HTML code given below.

<div class="input-group">
    <input type="password" id="password" class="input">
    <span class="btn" id="btn" onclick="pass(this)">
    🙈
    </span>
</div> 

CSS Code

CSS code is given below.

<style>      
body
{
    background-color: #bbb;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
.input-group
{
    padding: 0px 10px;
    border: 2px solid #000;
    background-color: #fff;
    border-radius: 10px;
    display: flex;
}
.input
{
    padding: 15px 5px;
    border:0px;
    outline: none;
    font-size: 30px;
}
.btn
{
    font-size: 40px;
    padding: 15px 5px;
    cursor: pointer;
}
</style>           

JavaScript Code

Take a look at the Pure JavaScript Code given below, in this code we have used innerHTML property to change the emoji on every click. While .type property is used to change the type of input field from text to password and vice versa.

<script>
var a =0;
function pass()
{

if(a==0)
{
document.getElementById('btn').innerHTML='🙊';
document.getElementById('password').type='text';    
a=1;    
}
    
else
{
document.getElementById('btn').innerHTML='🙈';
document.getElementById('password').type='password'; a=0;    
}    
  
}
</script>

Demo

Video Tutorial

Watch our video tutorial on Password Hide and Show with Toggle Emoji Button using JavaScript.

Password Show Hide with Eye Icon using JavaScript Change Background Color using Dropdown menu with JavaScript Get Select Tag value onchange in JavaScript Check If Class Exists JavaScript Add Event Listener To all Elements of Class JavaScript getElementsByTagName Event Listener JavaScript Change type attribute of Input Element With JavaScript Password Hide and Show with Toggle Emoji Button using JavaScript Hide and Show Navbar On Scroll With JavaScript Empty an Array in JavaScript Get Last Element Of Array Without Removing It Remove Last Element From Array JavaScript Remove First Element From Array in JavaScript Tic Tac Toe Game in JavaScript Remove Class from HTML Tag OnClick JavaScript JavaScript Select li Tag By Index Display JavaScript Variable In HTML Insert HTML Code anywhere With JavaScript JavaScript Date Difference in Days JavaScript Hide Button After Click Simple Click and Hold Effect Using JavaScript Remove Class From All Elements in JavaScript JavaScript Select All HTML Elements Whose ID Start With Same String