From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/html/attributes%2Fminlength.html | 125 +++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 devdocs/html/attributes%2Fminlength.html (limited to 'devdocs/html/attributes%2Fminlength.html') diff --git a/devdocs/html/attributes%2Fminlength.html b/devdocs/html/attributes%2Fminlength.html new file mode 100644 index 00000000..485e3f77 --- /dev/null +++ b/devdocs/html/attributes%2Fminlength.html @@ -0,0 +1,125 @@ +

HTML attribute: minlength

+

The minlength attribute defines the minimum string length that the user can enter into an <input> or <textarea>. The attribute must have an integer value of 0 or higher.

The length is measured in UTF-16 code units, which (for most scripts) is equivalent to the number of characters. If no minlength is specified, or an invalid value is specified, the input has no minimum length. This value must be less than or equal to the value of maxlength, otherwise the value will never be valid, as it is impossible to meet both criteria.

The input will fail constraint validation if the length of the text value of the field is less than minlength UTF-16 code units long, with validityState.tooShort returning true. Constraint validation is only applied when the value is changed by the user. Once submission fails, some browsers will display an error message indicating the minimum length required and the current length.

+
+

Try it

+
+

Examples

+
+

By adding minlength="5", the value must either be empty or five characters or longer to be valid.

+

html

+
<label for="fruit">Enter a fruit name that is at least 5 letters long</label>
+<input type="text" minlength="5" id="fruit" />
+
+

We can use pseudoclasses to style the element based on whether the value is valid. The value will be valid as long as it is either null (empty) or five or more characters long. Lime is invalid, lemon is valid.

+

css

+
input {
+  border: 2px solid currentcolor;
+}
+input:invalid {
+  border: 2px dashed red;
+}
+input:invalid:focus {
+  background-image: linear-gradient(pink, lightgreen);
+}
+
+
+
+ + +
+
+

Specifications

+
+ + +
Specification
HTML Standard
# the-maxlength-and-minlength-attributes
+

Browser compatibility

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariWebView AndroidChrome AndroidFirefox for AndroidOpera AndroidSafari on IOSSamsung Internet
minlength401751No2710.14040512710.34.0
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariWebView AndroidChrome AndroidFirefox for AndroidOpera AndroidSafari on IOSSamsung Internet
minlength401751No2710.14040512710.34.0
+

html.elements.input.minlength

+

BCD tables only load in the browser

+

html.elements.textarea.minlength

+

BCD tables only load in the browser

+

See also

+
+

+ © 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
+ https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/minlength +

+
-- cgit v1.2.3