Coding Hubs School of AI – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 8448811540
Back to HTML Notes
Topic #708

Number Input

<input type="number"> collects a value meant for actual arithmetic — with spinner arrows and min/max/step constraints — and is easy to reach for incorrectly on data that only looks numeric.

Syntax

<input type="number" name="quantity" min="1" max="10" step="1">

Basic Example

<label for="quantity">Quantity</label>
<input type="number" id="quantity" name="quantity" min="1" max="5" value="1">

Browser output: a text field with small up/down spinner arrows, letting the user click to increment or decrement, in addition to typing directly.

How It Works

The browser enforces that the value is a valid number and, if set, falls within min/max, stepping by step (default 1). On mobile, it typically brings up a numeric keypad.

Important Attributes

AttributePurpose
min / maxValid value range — see min-max
stepThe increment size (e.g. step="0.5" for half-steps)

Real-World Example

<label for="course-count">Number of courses to enroll in</label>
<input type="number" id="course-count" name="course-count" min="1" max="3" step="1">

A genuine numeric quantity — one where addition, comparison, and the spinner arrows are all actually meaningful actions on the value.

Common Mistakes

  • Using type="number" for phone numbers, postal/zip codes, or credit card numbers — these aren't used for math, can lose meaningful leading zeros, and the spinner arrows make no sense on them
  • Forgetting that a number input can still be left completely empty unless required is also added

Best Practices

  • Reserve type="number" strictly for values genuinely used in calculations or comparisons (quantity, age, price)
  • For identifier-like digit strings (phone, postal code), use type="text" with inputmode="numeric" and a pattern instead — this still gives a numeric mobile keyboard without the inappropriate spinner behavior

Accessibility Considerations

The spinner arrows can be small and fiddly for users with motor impairments — always allow direct typing as a reliable alternative, which native number inputs already do.

SEO Considerations

No direct ranking effect.

Browser & Modern HTML Notes

Spinner arrow styling varies noticeably by browser and operating system — a detail worth checking across your actual target browsers if the exact appearance matters to your design.

Mini Practice

  1. Build a quantity selector limited between 1 and 10.
  2. Identify why a phone number field should not use type="number", and describe the better alternative.

Related HTML Notes

Want to go beyond the notes?

Join Coding Hubs School of AI's HTML course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →