splitforms.com

HTML · INPUT TYPE

HTML input type number: min, max, step and when not to use it

An <input type="number"> is for real amounts and counts, like a quantity or a price. The browser blocks text that isn't a number and checks min, max and step before the form submits. Don't use it for phone numbers, ZIP codes or card numbers: those are digits, not numbers you do math with. Always check the value again on the server.

  • 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

number-input-example.html
<label for="quantity">Quantity</label>
<input type="number" id="quantity" name="quantity" min="1" max="10" step="1">

Want this form to email you its submissions? Point it at a free splitforms endpoint, with no server to build. Get a free access key →

Copy-paste code

HTML Input Type Number 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.

input-type-number.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" autocomplete="name" required>

  <label for="quantity">Quantity</label>
  <input type="number" id="quantity" name="quantity"
         min="1" max="10" step="1" required>

  <!-- step="0.01" allows cents; inputmode shows a decimal keypad -->
  <label for="budget">Budget (USD)</label>
  <input type="number" id="budget" name="budget"
         min="0" step="0.01" inputmode="decimal" placeholder="250.00">

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

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

Key facts

How does a number input behave?

A number input only accepts a valid number, checks it against min, max and step, and sends it as a string. The default step is 1, so decimals fail unless you change it.

How does a number input behave?
FactDetail
Mobile keyboardA numeric keyboard. Add inputmode="decimal" to make sure a decimal point key shows.
Built-in validationbadInput when the text isn't a number, rangeUnderflow below min, rangeOverflow above max, and stepMismatch when the value doesn't fit step.
Submitted valueA number string such as 2.5. It is empty when the field is left blank.
Default stepThe default step is 1, so 2.5 fails. Use step="0.01" for money or step="any" for any decimal.
Scroll wheel and arrow keysThe up and down arrow keys, the spinner and, in some browsers, the scroll wheel change the value by one step.
maxlengthIgnored on number inputs. Use max to limit the value.
Letters you can still typee, E, +, - and . are allowed because 1e3 and -2.5 are valid numbers. Other text is rejected or flagged as badInput, and the value reads as an empty string.
Decimal separatorThe submitted value always uses a dot, such as 2.5. Whether people can type a comma depends on the browser and its language setting.
valueAsNumber (JavaScript)The value as a real number, or NaN when the field is empty or invalid. value is always a string.

Sources: WHATWG HTML Standard: Number state (type=number) · MDN: <input type="number">

Attributes · <input type="number">

Which HTML Input Type Number attributes matter?

These attributes decide how the <input type="number"> behaves and what actually gets emailed to your inbox when someone submits.

HTML Input Type Number attributes and what each one does
AttributeWhat it doesDocs
nameThe key the value is sent under, such as quantity. Without a name, the field is never sent.
minThe lowest value allowed. Lower values fail with rangeUnderflow.MDN
maxThe highest value allowed. Higher values fail with rangeOverflow.MDN
stepThe size of each step. The default is 1. Use 0.01 for cents or any for any decimal.MDN
requiredBlocks submit while the field is empty.MDN
inputmodeinputmode="decimal" asks phones for a keypad with a decimal point; numeric asks for digits only.
placeholderAn example value, like 250.00. It disappears on typing, so it is not a label.

Common mistakes

HTML Input Type Number not working? Here's why.

Most broken forms come down to a few small mistakes with the <input type="number">. Check these before you ship, then forward every submission to Slack or a webhook.

  1. Decimals fail with the default step

    The default step is 1, so a value like 2.5 fails with stepMismatch. Add step="0.01" for money or step="any" for any decimal.

  2. Don't use it for phone numbers, ZIP codes or card numbers

    These are strings of digits, not quantities. The arrows and arrow keys change them (01234 becomes 1235), code that parses them as numbers drops leading zeros, and long card numbers lose precision. Use input type=tel for phone numbers, and type="text" with inputmode="numeric" for ZIP codes, postal codes and card numbers.

  3. maxlength does nothing

    Browsers ignore maxlength on a number input. Use max to set the highest value allowed.

  4. The value is still a string on the server

    The form sends text like "2.5", and anyone can send any value without your form. Parse it as a number on the server and check min, max and step again.

Sources: WHATWG HTML Standard: <input type="number"> · MDN: <input type="number">

step + inputmode

How do I accept whole numbers only?

Keep the default step of 1 (or write step="1") and add inputmode="numeric" for a digits-only keypad on phones. People can still type 2.5 or 1e3, but the browser blocks the submit with a step or range error. min="0" rules out negative numbers.

whole-numbers.html
<label for="guests">Number of guests</label>
<input type="number" id="guests" name="guests"
       min="1" max="20" step="1" inputmode="numeric" required>

max or pattern

How do I limit the number of digits?

maxlength does nothing on type="number", so cap the value instead: max="9999" allows up to four digits. When the digits are an identifier rather than an amount, such as a PIN or a postal code, use a text input with pattern and inputmode="numeric". Then maxlength works, and leading zeros are kept.

limit-digits.html
<!-- An amount: up to 4 digits -->
<input type="number" name="quantity" min="0" max="9999">

<!-- An identifier: exactly 4 digits, leading zeros kept -->
<input type="text" name="pin" inputmode="numeric"
       pattern="[0-9]{4}" maxlength="4" autocomplete="one-time-code">

CSS

How do I hide the number input arrows?

Chrome, Edge and Safari draw the arrows with ::-webkit-inner-spin-button and ::-webkit-outer-spin-button; Firefox follows appearance. Hiding them removes a click target, but the up and down arrow keys still change the value.

hide-spinner.css
/* Chrome, Edge, Safari */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Firefox */
input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

valueAsNumber

How do I read the number in JavaScript?

input.value is always a string, so "2" + 1 gives "21". Use input.valueAsNumber, which returns a number, or NaN when the field is empty or holds an invalid entry. Check Number.isNaN before doing math with it.

read-number.js
const qty = document.querySelector('input[name="quantity"]');
const total = document.getElementById("total");

qty.addEventListener("input", () => {
  const n = qty.valueAsNumber;        // 3, not "3"
  if (Number.isNaN(n)) return;        // empty or invalid
  total.textContent = (n * 19.99).toFixed(2);
});

Key benefits

Copy-paste ready

The HTML Input Type Number 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 input type number 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 <input type="number"> form actually sends data to a free splitforms backend, with spam filtering built in.

How it works

How to add HTML Input Type Number to any page.

Copy the html input type number example, drop in your free access key, and paste it into any page — submissions start landing in your dashboard.

  1. Copy the code

    Copy the HTML Input Type Number example below.

  2. Add your access key

    Replace YOUR_ACCESS_KEY with a free splitforms key from the dashboard.

  3. Paste into your site

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

Questions

HTML Input Type Number questions, answered.

Anything missing? Email us, we read every message.

A person reading answers to common questions
How do I allow decimals in a number input?

Set the step attribute. The default step is 1, so only whole numbers pass. Use step="0.01" for money with cents, or step="any" to allow any decimal.

How do I set a min and max on a number input?

Add min and max attributes, for example min="1" max="10". The browser blocks submit when the value is below min or above max, and the spinner stays inside that range.

Why doesn't maxlength work on a number input?

The maxlength attribute only applies to text-like inputs, so browsers ignore it on type=number. Use max to limit the value instead, for example max="999" for up to three digits.

Why can I type the letter e in a number input?

Because e is part of scientific notation: 1e3 is a valid number (1000), so the browser allows e, E, +, - and the decimal point. Other letters are blocked or make the value invalid. If e shouldn't be allowed, use a text input with inputmode="numeric" and pattern="[0-9]*".

How do I allow only numbers in an HTML input?

For amounts and counts, use type="number" with min, max and step. For digit strings such as PINs, postal codes or card numbers, use type="text" with inputmode="numeric" and pattern="[0-9]*", which keeps leading zeros and lets maxlength work. Check the value again on the server either way.

Can a number input use a comma as the decimal separator?

The submitted value always uses a dot, such as 2.5. Whether people can type 2,5 depends on the browser and its language setting, so for prices in comma-decimal countries a text input with inputmode="decimal" and your own parsing is more predictable.

Show 1 more questions
How do I hide the number input spinner arrows?

Use CSS. In Chrome, Edge and Safari, set -webkit-appearance: none and margin: 0 on the ::-webkit-inner-spin-button and ::-webkit-outer-spin-button pseudo-elements. In Firefox, set appearance: textfield on the input.

View all FAQs

Make this form actually submit.

Point your form at splitforms. 500 free submissions a month, spam filtering, webhooks on paid plans — no server.

  • No credit card required
  • 500 free submissions
  • Setup in minutes
Two people celebrating a working contact form