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.

Change font-size using JavaScript Get Font Size of any Tag using JavaScript Change Position of HTML Element using JavaScript How to Change Image on Hover with JavaScript How to Disable Button by Class Name in JavaScript How To Change Image Size with JavaScript How to change Image opacity with JavaScript How to Change image src on click with JavaScript How to get the lang attribute value in JavaScript How to Get attribute Value using JavaScript How To Check if Attribute Exists or not with JavaScript How To Count number of links on Page with JavaScript How To Scroll Page to Bottom using JavaScript How To Detect Shift Key Press with JavaScript Change Text Color On Hover with JavaScript Hide and Show div using JavaScript Get Button text with JavaScript Get textarea value with JavaScript Get table row Height with JavaScript Auto Increase width of input field with JavaScript Set Textarea maxLength with JavaScript Set Textarea Value with JavaScript JavaScript Count list items JavaScript set input field value Count Button Clicks with JavaScript Scroll Page to the Top on Click with JavaScript