Skip to main content

Show and Hide Password using Javascript

Show and Hide Password is a JavaScript project that is currently widely used. This allows you to hide the password or text in an input box.

 Currently, we see such systems in almost all types of social media and website login forms. Even when we turn on the window, we see the Show and Hide Password option in the Password Input Place.

 In this article, we are going to learn how to create a Show and Hide password system using JavaScript programming code. This type of system is used in a variety of login and registration forms. Earlier I designed many types of login forms but did not add the option to hide passwords and show. But in this article, I have shown that.

This type of design is used where passwords are input. When you input the password, it is seen in bullet format. In that place, you will see a small button or icon which, when clicked, will turn the bullet marks into characters.

Video Tutorial of Show and Hide Password

 If you have difficulty understanding then you can watch the video tutorial below. In the video tutorial below you will learn how I made this design very easily using JavaScript code.




Hopefully, the video tutorial above has helped you to know how I made this design. As you can see in the video above, I made a small box on the first web page. 

In that box, I created an input place to input. If you input a password in the input field, it will appear in bullet format. When you click on the icon to the right of that place, those bullet formats will become characters. When you click on that icon again, the passwords will be converted to bullet format again.

See related design:

Login Form With Password Validation
Login & Registration Form using JavaScript
Random Password generator javascript
Popup Contact Form

Show and Hide Password using Javascript [Source Code]

 For your convenience, I have given below the necessary source code. If you want, you can copy those codes and use them in your own project. First of all, you create an HTML and CSS file.

 Be sure to attach your CSS file to the HTML file. In this case, you must add the font awesome CDN link in the head section of your HTML file to implement the icon I used.

Use HTML code to build its structure

The following programming codes are the HTML programming codes that helped build the structure of this design. You copy the following HTML code and then paste it into the body tag (<body> </body>) of your HTML file.

 <!DOCTYPE html>
<!-- Design by rajtemplate.com -->
<html>
<head>
<!--font awesome icon cdn link-->
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css'>
 
<link rel="stylesheet" href="css.css">
</head>
<body>
<div class="container">
  
  <div class="second">
   <input class="active" type="password" id="pass">
   <div class="group2">
    <i id="icon" class="fa fa-eye-slash"></i>
   </div>
  </div>
  
</div>
<script src="javascript.js"></script>
</body>
</html>



Design it using CSS code

Now let's design the HTML code added above using CSS code. For this, you copy the following CSS codes then paste them into your CSS file. If you do not create a CSS file, you can paste these codes into the HTML file using the style tag.


* {
 margin0;
 padding0;
 box-sizingborder-box
}

body {
 background#1da1f2;  /* webpage background color */
}

.container {
 width340px;    /* box width */
 height90px;
 background#fff;  /* box background color */
 border-radius5px;
 margin30px auto 0;
 padding-top22px;
 border1px solid #c5c4c4;
}

.container>div {
 width100%;
 height25%;
 text-aligncenter
}
 
.container>div input[type='password'],
input[type='text'] {
 width88%;
 height45px;   /* input place height */
 backgroundwhite;
 font-familysans-serif;
 border2px solid #1da1f2;  /* input border */
 outline: nfirst;
 border-radius3px;
 margin1px auto 0;
 padding5px 40px 5px 10px;
 displayblock;
 font-size22px;
 colorblack;
}
 
.container>div .group2 {
 padding-left70px;
 padding-top10px;
 font22px sans-serif;
 positionrelative;
 displayblock;
 height40px;
 text-alignleft;
 top0;
 left0;
}

.container>div .group2>i {
 positionabsolute;
 right32px;  /* icon position */
 bottom51px;
 cursorpointer

}


Activate it using JavaScript code

JavaScript plays a vital role in implementing this program (Show and Hide Password using Javascript). In this case, very little JavaScript is used. You copy the JavaScript code below and paste it into your HTML file using the script tag (<script> </script>).


 

var inputPass = document.getElementById('pass'),
    icon = document.getElementById('icon');
 
   icon.onclick = function () {
 
     if(inputPass.className == 'active') {
        inputPass.setAttribute('type''text');
        icon.className = 'fa fa-eye';
       inputPass.className = '';
 
     } else {
        inputPass.setAttribute('type''password');
        icon.className = 'fa fa-eye-slash';
       inputPass.className = 'active';
    }
 
   }
  


 I hope you have made this Show and Hide Password system. If you want to know how it works then check out the demo below 👇👇👇


See the Pen by Raj Template (@RajTemplate) on CodePen.

Comments

Popular Posts

Animated Progress Bar using Only HTML and CSS

Animated progress bar is mainly used in various business and personal web sites. css progress bar helps to organize your knowledge in a beautiful way. In this article, I am going to show you how to create an animated progress bar using only HTML and CSS code. I have made many other types of Progress Bar before but in that case, I have used JavaScript.  I have not used any JavaScript or external JavaScript library for this design. I created this Animated Progress Bar design using Pure HTML and CSS code. Skill bars are used on various websites to streamline the amount of experience, education, etc. with the help of animations. First of all, I have given the background-color: # 30336b of a web page. Then I made a small box here. I used four CSS Progress Bar in that box. The value of this bar will be zero when opening the page then gradually it will reach the pre-determined meaning. Video Tutorial of Pure CSS Progress Bar If you want to know how to make it better then you...

Sidebar Menu Using Only HTML and CSS

This article shows you how to create sidebar menus using HTML and CSS code only. I have previously created many types of sidebars and navigation menubars using only HTML and CSS code so you can see those designs if you want.  Side Menubar A popular web element is currently used in the sidebar along with menubars on various websites. Undoubtedly the side menu bar is much more attractive and for this, the quality and beauty of the website are greatly enhanced. Under normal circumstances, I have completely hidden the menu bar on the web page.  There is a menu button that can be clicked to view the entire menu bar. There is also a cancel button which, when clicked, will completely hide the sidebar. In the sidebar, I have added links to various menu items, profile names, profile images, social media platforms.  First I gave the profile image and below that, I gave the profile name. Then I added some menu items here and added icons to each menu item. Then I created the...

Responsive Navigation Menu Bar using only HTML & CSS

Responsive navigation menu bar plays an important role for every website. The navigation menu bar creates user satisfaction with the beauty of the website. The user needs a responsive navbar so that he can easily find the topic of his choice.  I have designed many more types of menubars before. But in that case, I used JavaScript code to execute the menu button. I have not used any JavaScript or external JavaScript library for this design. I have created this Responsive Navigation menu bar using pure CSS and HTML code. I only used CSS code to make it responsive. I have made it responsive using only the  @media function of CSS code. Here I have basically used a logo and used five menu items . I have used the hover effect on the menu links. The background color will change when you click on those items or move the mouse. Video Tutorial of Responsive Navigation Menu Bar You can watch the video tutorial below to know how it works and how to make it. How T...

Automatic Image Slider using Only HTML & CSS

In this article, I am going to show you how to create an automatic image slider using only HTML and CSS code. We know that an image slider is a simple web element that is used to organize different images of the website in one place.  There are different types of image sliders and the most automatic image slider is used. This type of slider is mainly used in the hero section of the homepage of various websites. In addition, different types of services or portfolio websites are used to decorate the images of many types of projects.  Basically, this type of design has no navigation buttons which means there is no way to change the image manually. The images here will continue to change automatically from time to time. You can set this time in advance.  First of all, I set the background of a web page to black. Then I arranged all the images nicely there. In this case, I did not use any JavaScript code . It was created using effects in the animation of css3. ...

3D Image Slideshow using Only HTML and CSS

3D Image Slideshow is a type of image gallery that is currently used on a variety of websites. It helps to keep many types of images neatly arranged together. This not only enhances the beauty of the website but also user satisfaction.  I have already created many types of image sliders and image galleries but it is a little different. Basically, we use JQuery or JavaScript to change the image in other designs. However, I did not use any JavaScript in this case. In this case, I made it using only HTML and css3 . Yeah Al that sounds pretty crap to me, Looks like css3 just got used to the modern animation effect .  In this case, no button was created to change the image. It tends to change from time to time by itself. This means that it is an automatic 3d image slider built with HTML and CSS code only. This 3D image slider is like a square box. At certain intervals, this box rotates from right to left. I have used four images around this box. When the box is rotated, e...