Přejít k hlavnímu obsahu
← 📄 HTML & the platform·Modul A3 · Lekce 3
ÚkolBuild a product form: <input name='quantity' type='number' min='1' max='99' step='1'> and <input name='price' type='number' min='0' step='0.01'>.

<typ vstupu=číslo>: min, max, krok

75 XP6 min
Teorie

Numeric inputs in HTML

<input type="number" name="age" min="13" max="120" step="1" />
<input type="number" name="price" min="0" step="0.01" />
<input type="range" name="volume" min="0" max="100" step="5" value="50" />
  • type="number" — text-style input with up/down spinners. Decimal allowed with step="0.01" (or any fractional step).
  • type="range" — a slider. No text typing. Good for "set volume" / "pick a year between 1900-2026."

Pydantic parallel

class SignupForm(BaseModel):
    age: int = Field(ge=13, le=120)   # >= 13, <= 120
    price: Decimal = Field(ge=0)

Your HTML min="13" max="120" mirrors the Pydantic ge=13 le=120. Same validation, two layers: browser blocks bad input, backend re-validates. Never trust browser-only — XSS can submit anything.

Negative numbers

min="-100" works. step="any" allows arbitrary precision.

Why not type="text" + pattern="\d+"?

You could. But type="number" gives you:

  1. Number-pad keyboard on mobile (matters more than you think).
  2. Up/down arrow spinners on desktop.
  3. Native validation tooltip in the user's language.

type="text" would give you none of these.

🔒

Zaregistruj se a začni programovat

Teorie je otevřená pro každého. Editor, živý náhled a check se odemknou s 7denní zkušební verzí zdarma — karta vyžadována, zrušíš kdykoli.

Registrace — zkušební verze zdarma →

Prvních 10 lekcí v každé trase je zdarma. Karta není potřeba.

← PředchozíDalší lekce →

Jeden tip k Pythonu nebo webu denně — e-mailem

Krátké, ručně psané, žádný spam. Odhlásit jedním klikem.