HTML minlength Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The minlength attribute sets the minimum number of characters a user can enter in a text-like <input> or a <textarea>. The value must be an integer of 0 or higher. Length is measured in UTF-16 code units (often the same as character count, but not always).

Supported input types: text, search, url, tel, email, and password. Pair with maxlength for an upper cap, and use min instead when you need a numeric or date/time floor. It does not imply required — an empty field can still submit unless you add that too.

Baseline · Widely available.

Not deprecated and not experimental. Stable across modern browsers since about July 2015.

Client validation only.

Browsers report tooShort when the value is too short after the user edits it. Always check length on the server.

HTML Syntax

syntax.html
<input type="text" minlength=" number">
<textarea minlength=" number"></textarea>

number is a non-negative integer. If the attribute is missing or invalid, there is no minimum length.

Attribute Values

One value type — a non-negative integer representing the minimum length:

ValueDescriptionTry it
numberInteger ≥ 0. Minimum UTF-16 code units (e.g. 8, 10)Try it
0Same as no useful minimum — empty or any length is fineTry it
Omitted / invalidNo minimum length is enforced by HTMLTry it
With maxlengthminlength must be ≤ maxlength when both are validTry it

Live Preview

Change minlength, then type. The note shows length and whether the field is valid.

Empty is still valid unless the field is also required. Type a short value to see tooShort.

Text input

0 / min 5 — empty (valid without required)

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Text Input Minimum Length

Require at least five characters once the user types something.

HTML
<label for="fruit">Fruit name (at least 5 letters):</label>
<input type="text" id="fruit" name="fruit" minlength="5">
Try It Yourself

How It Works

  1. minlength="5" sets the floor for non-empty values.
  2. Empty still submits unless you also add required.
  3. tooShort becomes true when the user enters 1–4 characters.
  4. Label the rule so users know the minimum before submit.

Example 2 — Password Minimum Length

Combine minlength with required for a simple password floor.

HTML
<label for="password">Password (min 8 characters):</label>
<input
  type="password"
  id="password"
  name="password"
  minlength="8"
  required>
Try It Yourself

How It Works

  1. required blocks an empty password.
  2. minlength="8" blocks values shorter than eight characters.
  3. Client hint only — enforce the same rule on the server.
  4. Add pattern if you also need complexity rules (letters, digits, and so on).

Example 3 — minlength + maxlength Together

Define an allowed length range for a name and a short description.

HTML
<label for="name">Product name:</label>
<input
  id="name"
  name="name"
  type="text"
  minlength="3"
  maxlength="20"
  required>

<label for="description">Product description:</label>
<textarea
  id="description"
  name="description"
  minlength="10"
  maxlength="40"
  required></textarea>
Try It Yourself

How It Works

  1. minlength is the floor; maxlength is the ceiling.
  2. Keep the order. minlength must be ≤ maxlength.
  3. Works on both single-line inputs and <textarea>.
  4. required ensures empty values are rejected as well.

Edge Cases & Pitfalls

Most surprises come from assuming empty fields are invalid, or mixing up min and minlength.

required

minlength does not imply required

An empty string is allowed unless you also set required. The minimum applies after the user enters a value.

compare

Do not confuse with min

minlength counts characters. min limits numeric or date/time values.

bounds

Keep minlength ≤ maxlength

If the floor is higher than the ceiling, no value can satisfy both constraints.

counting

UTF-16 code units

Some emoji use two units, so visible glyphs may not match value.length one-to-one.

security

Always re-check on the server

HTML length rules are UX helpers. Attackers can submit shorter strings without your form UI.

Browser Support

minlength is an HTML attribute for text inputs and textarea in the browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

minlength

Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support minlength on text-like inputs and textarea.

96% Global support (approx.)
Google Chrome 40+
Full support
Mozilla Firefox 51+
Full support
Apple Safari 10.1+
Full support
Microsoft Edge 17+
Full support
Opera 27+
Full support
Samsung Internet 4+
Full support
Internet Explorer No
Not supported
minlength Widely supported

Bottom line: Safe to use in modern browsers for character floors. Pair with required when empty values must also be rejected, and always validate on the server.

Key Takeaways

  • Role: require a minimum number of UTF-16 code units.
  • Elements: text-like <input> types and <textarea>.
  • Empty OK: add required if blank must also fail.
  • Not min: use min for number/date floors, not character count.

One line: minlength is the floor for typed text — empty still passes unless you add required.

Frequently Asked Questions

It sets the minimum number of characters a user can enter in a text-like input or a textarea. Length is measured in UTF-16 code units. Values that are too short fail constraint validation (tooShort).
input types text, search, url, tel, email, and password, plus textarea. It does not apply to number or date — use min for those.
No. minlength caps character count on text fields. min limits numeric or date/time values.
No. An empty field can still be submitted unless you also set required. minlength only applies once the user has entered a value.
Together they define a length range. minlength must be less than or equal to maxlength, or the value can never be valid.
No. It is client-side only. Always check string length on the server.

Next: multiple

Allow more than one value on email, file, and select controls.

multiple tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful