---
title: "Number Input"
description: "Number Input component - increment/decrement controls with native input[type=number]."
slug: "number-input"
---

import { DocPage, PageHeader, SkillPanel, Example, ExampleLabel, ExampleHint, ExampleCode, SourceFiles, SourceNote, StatesSection, CodeBlock, Demo, DemoCode, ChangelogEntries, ArchBody, StatsClaim, StatsCards, PageOverlay, DocText, DocLink, H2, SkillField, SkillText, SkillRow, SkillGrid, Variant, ApiPill, Dim, CodeCard, TableCard, ApiSection } from "../../lib/components/index";

<DocPage meta={meta}>

<PageHeader slug="number-input" title="Number Input" component="number-input">
  A numeric input with increment/decrement buttons. Built on <code>&lt;input type="number"&gt;</code> with custom stepper controls.
</PageHeader>

<SkillPanel component="number-input">
  <SkillField label="Native basis">
<SkillText><code>&lt;input type="number"&gt;</code> with custom increment/decrement buttons.</SkillText>
  </SkillField>

  <SkillField label="Web Platform APIs">
<SkillRow>
    <ApiPill href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number" title="native number input with built-in validation and step increment"><code>&lt;input type="number"&gt;</code></ApiPill>
  </SkillRow>
  </SkillField>

  <SkillField label="Classes">
<SkillRow>
    <code>.number-input</code>
    <code>.number-input-unit</code>
  </SkillRow>
  </SkillField>

  <SkillField label="Data attributes">
<SkillText dense>• <code>data-action</code> - <code>decrement</code> / <code>increment</code> on the stepper buttons</SkillText>
  <SkillText dense>• <code>data-decimals</code> - fixed fraction digits on the wrapper (19 → 19.0)</SkillText>
  <SkillText dense>• <code>data-currency</code> / <code>data-locale</code> / <code>data-currency-display</code> - locale-aware money mask (Intl.NumberFormat)</SkillText>
  <SkillText>• <code>data-number-output</code> - hidden field receiving the machine value (1234.5)</SkillText>
  </SkillField>

  <SkillField label="Notes">
<SkillText dense>• A unit is a <code>&lt;label class="number-input-unit" for&gt;</code> before or after the input - it joins the accessible name.</SkillText>
  <SkillText dense>• Native spinner buttons are hidden with <code>::-webkit-inner-spin-button</code>.</SkillText>
  <SkillText dense>• Use <code>min</code>, <code>max</code>, and <code>step</code> for range constraints.</SkillText>
  <p class="text-muted-foreground m-0">• Keyboard: arrow keys increment/decrement by step value.</p>
  </SkillField>
</SkillPanel>

```html example label="Default" hint="Number input with +/- buttons."
<div>
  <label class="label" for="d-qty">Quantity</label>
  <div class="number-input">
    <button data-action="decrement" aria-label="Decrease">−</button>
    <input type="number" id="d-qty" value="1" min="0" max="99" step="1" />
    <button data-action="increment" aria-label="Increase">+</button>
  </div>
</div>
```

```html example label="Unit and fixed decimals" hint="A temperature wants both: data-decimals='1' keeps one fraction digit (19 shows as 19.0, a step from 19.5 lands on 20.0) and a .number-input-unit label after the input shows °C. The unit is a second label for the input - clicking it focuses the field and screen readers announce 'Temperature °C'."
<div>
  <label class="label" for="d-temp">Temperature</label>
  <div class="number-input" data-decimals="1">
    <button data-action="decrement" aria-label="Decrease">−</button>
    <input type="number" id="d-temp" value="19" min="-40" max="60" step="0.5" />
    <label class="number-input-unit" for="d-temp">°C</label>
    <button data-action="increment" aria-label="Increase">+</button>
  </div>
</div>
```

```html example label="Units" hint="Any unit, before or after the value: % for a discount, kg with one decimal, hours in quarter steps, € in front with cents - even an emoji. The value aligns toward its unit so the pair reads as one, and the unit is part of the text (it is copied along with the number)."
<div class="grid grid-cols-auto gap-4" style="--layout-min: 11rem">
  <div>
    <label class="label" for="u-discount">Discount</label>
    <div class="number-input">
      <button data-action="decrement" aria-label="Decrease">−</button>
      <input type="number" id="u-discount" value="15" min="0" max="100" step="5" />
      <label class="number-input-unit" for="u-discount">%</label>
      <button data-action="increment" aria-label="Increase">+</button>
    </div>
  </div>
  <div>
    <label class="label" for="u-weight">Weight</label>
    <div class="number-input" data-decimals="1">
      <button data-action="decrement" aria-label="Decrease">−</button>
      <input type="number" id="u-weight" value="72.5" min="0" max="300" step="0.5" />
      <label class="number-input-unit" for="u-weight">kg</label>
      <button data-action="increment" aria-label="Increase">+</button>
    </div>
  </div>
  <div>
    <label class="label" for="u-hours">Duration</label>
    <div class="number-input" data-decimals="2">
      <button data-action="decrement" aria-label="Decrease">−</button>
      <input type="number" id="u-hours" value="1.5" min="0" max="24" step="0.25" />
      <label class="number-input-unit" for="u-hours">h</label>
      <button data-action="increment" aria-label="Increase">+</button>
    </div>
  </div>
  <div>
    <label class="label" for="u-budget">Budget</label>
    <div class="number-input" data-decimals="2">
      <button data-action="decrement" aria-label="Decrease">−</button>
      <label class="number-input-unit" for="u-budget">€</label>
      <input type="number" id="u-budget" value="250" min="0" step="10" />
      <button data-action="increment" aria-label="Increase">+</button>
    </div>
  </div>
  <div>
    <label class="label" for="u-coffee">Coffee</label>
    <div class="number-input">
      <button data-action="decrement" aria-label="Decrease">−</button>
      <input type="number" id="u-coffee" value="2" min="0" max="12" step="1" />
      <label class="number-input-unit" for="u-coffee">☕ cups</label>
      <button data-action="increment" aria-label="Increase">+</button>
    </div>
  </div>
</div>
```

```html example label="Currency" hint="data-currency turns the field into a masked money input driven by Intl.NumberFormat: the locale (data-locale, else the page's lang) decides the decimal and group separators, the currency symbol and its side, and the minor unit (EUR 2 digits, JPY none). Typing is masked live - letters are dropped, groups appear as you type, the caret stays put - and blur pads the cents. An input[data-number-output] submits the plain machine value (1234.5)."
<div class="grid grid-cols-auto gap-4" style="--layout-min: 13rem">
  <div>
    <label class="label" for="c-price">Price (de-DE, EUR)</label>
    <div class="number-input w-full" data-currency="EUR" data-locale="de-DE">
      <input type="text" id="c-price" value="1234.5" />
      <input type="hidden" name="price" data-number-output />
    </div>
  </div>
  <div>
    <label class="label" for="c-donation">Donation (en-US, USD)</label>
    <div class="number-input w-full" data-currency="USD" data-locale="en-US">
      <button data-action="decrement" aria-label="Decrease by 5">−</button>
      <input type="text" id="c-donation" value="25" data-step="5" data-min="5" />
      <button data-action="increment" aria-label="Increase by 5">+</button>
    </div>
  </div>
  <div>
    <label class="label" for="c-budget">Budget (ja-JP, JPY)</label>
    <div class="number-input w-full" data-currency="JPY" data-locale="ja-JP">
      <input type="text" id="c-budget" value="150000" />
    </div>
  </div>
</div>
<p class="text-sm text-muted-foreground" style="margin: 0.75rem 0 0"
  >Price submits <code>price=<output id="c-price-out">1234.5</output></code></p
>
<script>
  document.querySelector('[name="price"]').addEventListener('change', (e) => {
    document.getElementById('c-price-out').textContent = e.target.value;
  });
</script>
```

```html example label="Currency per locale" hint="Change the locale and the SAME amount re-renders: separators, symbol, symbol side and grouping all come from the platform (Intl.NumberFormat) - including Indian lakh grouping (12,34,567.80) and Swiss apostrophes. Set data-locale / data-currency at any time; data-currency-display switches between symbol, narrowSymbol, code and name."
<div style="display: flex; gap: 1rem; align-items: end; flex-wrap: wrap">
  <div>
    <label class="label" for="c-any">Amount</label>
    <div class="number-input" data-currency="EUR" data-locale="de-DE" id="c-any-field">
      <input type="text" id="c-any" value="1234567.8" />
    </div>
  </div>
  <div>
    <label class="label" for="c-any-locale">Locale · currency</label>
    <select class="select" id="c-any-locale">
      <option value="de-DE|EUR">de-DE · EUR</option>
      <option value="en-US|USD">en-US · USD</option>
      <option value="en-GB|GBP">en-GB · GBP</option>
      <option value="fr-FR|EUR">fr-FR · EUR</option>
      <option value="de-CH|CHF">de-CH · CHF</option>
      <option value="en-IN|INR">en-IN · INR</option>
      <option value="ja-JP|JPY">ja-JP · JPY</option>
    </select>
  </div>
</div>
<script>
  document.getElementById('c-any-locale').addEventListener('change', (e) => {
    const [locale, currency] = e.target.value.split('|');
    const field = document.getElementById('c-any-field');
    field.dataset.locale = locale;
    field.dataset.currency = currency;
  });
</script>
```

```html example label="Sizes" hint="The stepper follows the shared input ladder via data-size - md is 2.25rem like every other form control."
<div class="flex items-center gap-4 mb-3">
  <span class="demo-label demo-label-w5">Extra small</span>
  <div class="number-input" data-size="xs"
    ><button data-action="decrement" aria-label="Decrease">−</button
    ><input type="number" value="1" min="0" max="99" step="1" aria-label="Quantity xs" /><button
      data-action="increment"
      aria-label="Increase"
      >+</button
    ></div
  >
</div>
<div class="flex items-center gap-4 mb-3">
  <span class="demo-label demo-label-w5">Small</span>
  <div class="number-input" data-size="sm"
    ><button data-action="decrement" aria-label="Decrease">−</button
    ><input type="number" value="1" min="0" max="99" step="1" aria-label="Quantity sm" /><button
      data-action="increment"
      aria-label="Increase"
      >+</button
    ></div
  >
</div>
<div class="flex items-center gap-4 mb-3">
  <span class="demo-label demo-label-w5">Medium</span>
  <div class="number-input" data-size="md"
    ><button data-action="decrement" aria-label="Decrease">−</button
    ><input type="number" value="1" min="0" max="99" step="1" aria-label="Quantity md" /><button
      data-action="increment"
      aria-label="Increase"
      >+</button
    ></div
  >
</div>
<div class="flex items-center gap-4 mb-3">
  <span class="demo-label demo-label-w5">Large</span>
  <div class="number-input" data-size="lg"
    ><button data-action="decrement" aria-label="Decrease">−</button
    ><input type="number" value="1" min="0" max="99" step="1" aria-label="Quantity lg" /><button
      data-action="increment"
      aria-label="Increase"
      >+</button
    ></div
  >
</div>
<div class="flex items-center gap-4 mb-3">
  <span class="demo-label demo-label-w5">Extra large</span>
  <div class="number-input" data-size="xl"
    ><button data-action="decrement" aria-label="Decrease">−</button
    ><input type="number" value="1" min="0" max="99" step="1" aria-label="Quantity xl" /><button
      data-action="increment"
      aria-label="Increase"
      >+</button
    ></div
  >
</div>
```

<StatesSection>
  <p class="text-sm text-muted-foreground m-0 mb-3">Named states via the shared State API, driven per instance through the bound <code>api</code>:</p>
  <ul class="text-sm text-muted-foreground m-0 mb-3 ps-5">
    <li><code>default</code> - enabled; <code>setState('default', \{ value \})</code> presets the number through the native input (events fire), and <code>getState().config.value</code> reports the live value</li>
  </ul>
  <p class="text-sm text-muted-foreground">The demo element carries <code>data-state-demo</code>; <code>bun run screenshots</code> drives it via <code>el.api.setState(name)</code> and captures <code>screenshots/\{mode\}/number-input-\{state\}.png</code>.</p>

Machine contract - verified against <a class="link" href="../schemas/number-input.schema.json"><code>number-input.schema.json</code></a> by <code>bun run verify</code>:

```states
| State | Type | Values | Default | Description |
| --- | --- | --- | --- | --- |
| `value` | `number` | `—` | `3` | Current value - step buttons, typing, and the panel all drive the native input. |
```

</StatesSection>

<ApiSection component="number-input" />

<SourceFiles component="number-input" section="css" />

<SourceFiles component="number-input" section="js">
  <SourceNote for="js">Number Input</SourceNote>
</SourceFiles>

</DocPage>
