Home > Web Front-end > CSS Tutorial > How to Create a Password-Like Input with Asterisks Using Only CSS?

How to Create a Password-Like Input with Asterisks Using Only CSS?

DDD
Release: 2024-10-26 21:32:03
Original
214 people have browsed it

How to Create a Password-Like Input with Asterisks Using Only CSS?

Style Input Type=Text Like Type=Password

Question:

How can you modify an input element with type=text to display asterisks like a password input using only CSS?

Solution:

Despite the presentation-only nature of this issue, CSS alone can achieve this effect for modern browsers:

<code class="css">input.pw {
  -webkit-text-security: disc; /* Older Safari/Chrome */
  text-security: disc; /* W3C */
}</code>
Copy after login

Apply this CSS to the input element with class "pw":

<code class="html"><input type="text" class="pw" value="abcd">

<!-- Button to toggle asterisk display -->
<button onclick="this.previousElementSibling.classList.toggle('pw')">Toggle '•'</button></code>
Copy after login

The above is the detailed content of How to Create a Password-Like Input with Asterisks Using Only CSS?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template