splitforms.com

HTML · INPUT ATTRIBUTE

HTML maxlength and minlength: limit input length

Last reviewed

maxlength caps how many characters a visitor can type into a text-like <input> or <textarea>. minlength makes the browser block a submit when a non-empty value is too short. Neither works on type="number" (use min and max there). Always check length on the server too.

  • Live, editable example
  • Copy-paste snippet
  • Attributes & common mistakes
Live demo · nothing is sent

What gets submitted

Fill in the form above and press its button. The demo stops the request and lists every name=value pair the browser would send, plus the controls it leaves out.

With a free access key in the form, these fields land in your splitforms dashboard; access_key and botcheck are read by splitforms, not stored as lead data.

Edit the HTML and re-run it
Runs in a sandbox. Nothing is sent.

Minimal snippet

maxlength-example.html
<textarea name="message" minlength="10" maxlength="500"></textarea>

Copy-paste code

HTML maxlength & minlength code you can paste today.

Replace YOUR_ACCESS_KEY with a key from your free splitforms dashboard. The form posts to one endpoint — submissions land in your inbox and dashboard with spam filtering built in.

Get free access key
maxlength.html
<form action="https://splitforms.com/api/submit" method="POST">
  <input type="hidden" name="access_key" value="YOUR_ACCESS_KEY">

  <label for="name">Name</label>
  <input type="text" id="name" name="name" maxlength="80" autocomplete="name">

  <label for="email">Email</label>
  <input type="email" id="email" name="email" autocomplete="email" required>

  <label for="message">Message</label>
  <textarea id="message" name="message" rows="5" minlength="10" maxlength="1000" required></textarea>
  <output id="count" for="message">0 / 1000</output>

  <!-- Honeypot: hidden from people, bots fill it in -->
  <input type="checkbox" name="botcheck" style="display:none">

  <button type="submit">Send</button>
</form>

<script>
  // Optional: a live character counter, no libraries needed
  const field = document.getElementById("message");
  const count = document.getElementById("count");
  field.addEventListener("input", () => {
    count.value = field.value.length + " / 1000";
  });
</script>

Key facts

How do maxlength and minlength behave?

maxlength stops typing at a set number of characters and minlength blocks a short, edited value on submit. Both only apply to text-like inputs and <textarea>.

How do maxlength and minlength behave?
FactDetail
Where it worksOn <input> types text, search, url, tel, email and password, and on <textarea>. It is ignored on number, date, range and other types, which use min and max instead.
Typing and pastingmaxlength stops further typing once the limit is reached, and pasted text is cut off at the limit.
Script and default valuesA value set by script or by the value attribute is NOT cut short. It can be longer than maxlength, and the browser won't trim it.
When minlength failsOnly when the value is non-empty and was edited by the user. An empty field passes unless it also has required.
How characters are countedIn UTF-16 code units, so some emoji and rare characters count as 2.
Validity flagsA value that breaks the limits sets validity.tooLong or validity.tooShort.

Sources: WHATWG HTML Standard: the maxlength and minlength attributes · MDN: HTML attribute maxlength

Attributes · maxlength

Which attributes go with maxlength?

maxlength and minlength set the length limits. required and min / max cover the cases they don't.

HTML maxlength & minlength attributes and what each one does
AttributeWhat it does
maxlengthThe most characters the field accepts, like maxlength="80". Typing stops at the limit.
minlengthThe fewest characters a non-empty value may have. A shorter edited value blocks the submit.
requiredMakes the field mandatory. Pair it with minlength so an empty field can't slip through.
min / maxThe limits for number, date and range inputs, which ignore maxlength and minlength.

Common mistakes

maxlength mistakes to avoid

Most length bugs come from the wrong input type or from trusting the browser alone.

  1. maxlength does nothing on type="number"

    Number inputs ignore maxlength and minlength. Use min and max for the value range, or a text input with inputmode="numeric" if you need a digit count.

  2. minlength without required lets an empty field through

    minlength only checks a value that isn't empty. Add required if the field must be filled in.

  3. Client limits are easy to bypass

    Anyone can remove the attribute or send the request directly. Always enforce length on the server too.

  4. Emoji and some characters count as 2

    Length is counted in UTF-16 code units, so an emoji like 😀 uses two of the allowed characters.

Sources: WHATWG HTML Standard: the maxlength and minlength attributes · MDN: HTML attribute maxlength · MDN: HTML attribute minlength

Copy-paste ready

The HTML maxlength & minlength example below is a complete, working form — paste it into any HTML page and it submits, no edits to the markup required.

No backend to build

Your html maxlength & minlength form posts to one endpoint. No server, PHP, or API route — accepted submissions are saved to your dashboard before owner notification email is attempted; delivery time and inbox placement depend on provider and recipient settings.

A form that really submits

Unlike a static reference snippet, this maxlength form actually sends data to a free splitforms backend, with spam filtering built in.

How it works

How to add HTML maxlength & minlength to any page.

Copy the html maxlength & minlength example, drop in your free access key, and paste it into any page — submissions start landing in your dashboard.

Copy the code

Copy the HTML maxlength & minlength example below.

Add your access key

Replace YOUR_ACCESS_KEY with a free splitforms key from the dashboard.

Paste into your site

Drop the form into any HTML page. Submissions arrive in your dashboard.

How SplitForms works

What happens after someone submits your form?

splitforms receives the submission, filters spam, saves it to your dashboard and emails you — then, on paid plans, sends it on to your webhooks and integrations. No backend infrastructure to build.

A SplitForms contact form submission launching straight to your inbox

Add your endpoint

Point your form to your unique SplitForms endpoint. That's it.

HTML form pointing at a SplitForms submit endpoint

Receive submissions

We instantly capture and organize every submission in your inbox.

Submissions inbox with searchable leads and status pills

Route anywhere

Send data to email, spreadsheets, CRMs, webhooks, and 7,000+ apps.

Generic integration tiles for email, sheets, chat, CRM, automate, and webhook

No credit card required. Set up in under 60 seconds.

Connect & automate

Where can submissions go besides email?

On paid plans, submissions can also go to Slack, Discord, Google Sheets, Notion, Airtable, Zapier or any signed webhook — and splitforms works on the platforms you build on, from WordPress and Shopify to Next.js. With Stripe connected, your forms can take payments too.

Connect your SplitForms form to Slack, Google Sheets, Mailchimp, Zapier and more
NewTake payments on your formsDeposits, bookings, order forms — submitters check out through Stripe and the money goes straight to your Stripe account. Included on every paid plan.See payment forms →Need time slots? Online booking →

Setup guides for the stacks you use

Questions

HTML maxlength & minlength questions, answered.

View all FAQs
Why doesn't maxlength work on a number input?

maxlength and minlength only apply to text-like inputs and textareas. A type="number" input ignores them. Use min and max to limit the value, or a text input with inputmode="numeric" if you need a fixed number of digits.

Does minlength make a field required?

No. minlength only checks a field that has a value, so an empty field still passes. Add the required attribute as well if the field must be filled in.

How do I show a character counter?

Listen for the field's input event and write the current length into an <output>, for example `count.value = field.value.length + " / 1000"`. The example on this page uses that pattern.

Does maxlength count spaces and line breaks?

Yes. Every character counts, including spaces. In a textarea, a line break counts as one character while typing.

Simple pricing

How much does splitforms cost?

Free gives you 500 submissions for $0 — no card, no time limit. Pro is $5/month for 5,000 submissions a month, and Annual is $49/year for 15,000 a month with every Pro feature.

Free

$0— 500 submissions
 

No card, no time limit

Best for testing

For side projects and indie devs.

  • 500 free submissions
  • Unlimited forms
  • Email notifications included
  • Smart spam filtering
  • Submissions dashboard
  • Redirect after submit
  • MCP server included

Annual

$49/ year
About $4.08 per month, billed yearly
Best value

Every Pro feature with triple the volume — $0.27 per 1,000 at full use.

  • 15,000 submissions per month
  • Unlimited forms
  • Everything in Pro
  • File uploads with 5 GB storage
  • 3 team seats
  • Priority email support

No credit card required on Free • Cancel anytime • Full pricing and FAQ