Number Input Generator

Create numeric fields with min, max, and step for precise validation.

Number input on iPhone

Input configuration

Preview & code

Tip: Tweak attributes to see the preview and code update instantly.

HTML number input: precise, accessible numeric fields

The HTML <input type="number"> specializes in numeric entry. It enables spinner controls in many desktop browsers and numeric keyboards on mobile, reducing transcription mistakes and speeding completion. With a few attributes you can constrain the domain of acceptable values, preventing impossible entries at the source. This guide covers practical configuration, validation, and accessibility patterns for numeric fields such as prices, quantities, ages, and measurements.

Define a realistic domain

Three attributes establish the numeric range and granularity: min, max, and step. Choose values that reflect your business rules. For a quantity selector, min="1" and step="1" may be appropriate; for currency, consider step="0.01"; for duration in minutes, step="5" might match UI expectations. Avoid arbitrary extremes—overly wide ranges make spinners useless and increase error risk.

  • Use integers for counts; decimals for prices, weights, and ratings.
  • When decimals are allowed, clearly indicate the required precision.
  • If values must be multiples (e.g., packs of 6), set step="6".

Keyboard & inputmode

Most mobile browsers show a numeric keypad for number inputs. To broaden support and help older browsers, you can add inputmode="numeric" or decimal. Keep the field type as number to retain native validation and semantics.

Validation UX

Combine native constraints with clear messages. Never block typing (e.g., preventing a minus sign before users complete the value). Validate on blur or submit; highlight errors next to the field with concise language such as “Enter a value from 1 to 10.”

  • Style :out-of-range and :invalid to guide attention.
  • Use setCustomValidity() for bespoke messages when needed.

Accessibility checklist

  • Provide a visible label that names the unit (e.g., “Quantity”).
  • Include units in helper text, not in the value (e.g., “kg”, “USD”).
  • Ensure spinner buttons are keyboard reachable and have sufficient contrast.

Edge cases & security

Users can still paste non‑numeric text or bypass client constraints. Always validate and coerce on the server. Normalize decimal separators for international audiences; some locales use commas. Protect downstream calculations from floating‑point surprises by using integer math where feasible (e.g., store cents).

Copy‑ready patterns

  • Quantity: min="1", step="1", helper text for stock limits.
  • Price: step="0.01", currency indicated in label or adjacent text.
  • Rating: min="0", max="5", step="0.5".

Configured thoughtfully, number inputs prevent bad data before it starts, improving both user experience and data quality. Use realistic ranges, accessible labels, and server‑side validation to keep your numeric fields fast, forgiving, and accurate.