Input Password readOnly attribute

Definition and usage

readOnly Set or return whether the password field is read-only.

The read-only field cannot be modified. However, users can select, highlight it, and copy text from it.

Tip:To prevent users from interacting with the field, use disabled attribute.

See also:

HTML Reference Manual:HTML <input> readonly Attribute

Example

Example 1

Set the password field to read-only:

document.getElementById("myPsw").readOnly = true;

Try it yourself

Example 2

Check if the password field is read-only:

var x = document.getElementById("myPsw").readOnly;

Try it yourself

Syntax

Return the readOnly property:

passwordObject.readOnly

Set the readOnly property:

passwordObject.readOnly = true|false

Attribute value

Value Description
true|false

The password field should be read-only.

  • true - The password field is read-only
  • false - Default. The password field is changeable

Technical Details

Return value: Boolean value, returned if the password field is read-only true; otherwise return false.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support 10.0 Support Support Support