HTMLInputElement: minLength property - Web APIs | MDN

Value

A number representing the element's minlength if present or -1.

Example

Given the following HTML:

html

<p>
  <label for="password">Your password</label>
  <input id="password" type="password" minlength="8" maxlength="20" />
</p>

You can use the minLength property to retrieve or set the <input>'s minlength attribute value:

js

const inputElement = document.querySelector("#password");
console.log(`Element's minLength: ${inputElement.minLength}`); // "Element's minlength: 8"
inputElement.minLength = 12; // updates the element's minlength attribute value

Specifications

Specification
HTML
# dom-input-minlength

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.