DEV Community

Cover image for Make your text input look like a password input
Oumayma JavaScript Developer
Oumayma JavaScript Developer

Posted on

3 1

Make your text input look like a password input

Ever wondered why password inputs look like ****** ,
turns out it's because of -webkit-text-security property.
Here's how to make a simple text input look like a password input:



input.pw {
  -webkit-text-security: disc;
}

input.pw2 {
  -webkit-text-security: circle;
}

input.pw3 {
  -webkit-text-security: square;
}



Enter fullscreen mode Exit fullscreen mode


<input type="text" class="pw" value="secret"/>
<input type="text" class="pw2" value="secret"/>
<input type="text" class="pw3" value="secret"/>



Enter fullscreen mode Exit fullscreen mode

result :
inputs result

Top comments (6)

Collapse
 
zoppatorsk profile image
Zoppatorsk
Collapse
 
oumaymasghayer profile image
Oumayma JavaScript Developer

Yes, just in case you can't use type="password".

Collapse
 
zoppatorsk profile image
Zoppatorsk

Then it is still a bad idea cuz you are using a webkit specific CSS-property. Won't work on all browsers. I mean, wont even work on Firefox. Would have to use some polyfill or some creative way to achieve the same result. .

Type password also have some other benefits, think it's easier for password managers and stuff to detect that it is a password box and auto fills the password.

Thread Thread
 
oumaymasghayer profile image
Oumayma JavaScript Developer

-webkit-text-security , -mox-text-security, text-security, for all browser support.

Thread Thread
 
zoppatorsk profile image
Zoppatorsk

Naah.. that won't work... even if typing -moz instead of -mox ;)

firefox_dev_tools
Wld have to use some alternative solution like below where use a font for it.

@font-face {
    font-family: text-security-disc;
    src: url('https://raw.githubusercontent.com/noppa/text-security/master/dist/text-security-disc.woff');
}

input {
    font-family: text-security-disc;
    -webkit-text-security: disc;
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
sghribi profile image
soufieneghribi

Quick and clear!

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay