# Number Input

URL: https://ark-ui.com/docs/react/components/number-input
Markdown: https://ark-ui.com/docs/react/components/number-input.md

A field that allows user input of numeric values.

---

---
id: number-input
title: Number Input
description: A field that allows user input of numeric values.
---



## Anatomy



```tsx
<NumberInput.Root>
  <NumberInput.Label />
  <NumberInput.Scrubber />
  <NumberInput.Control>
    <NumberInput.Input />
    <NumberInput.IncrementTrigger />
    <NumberInput.DecrementTrigger />
  </NumberInput.Control>
</NumberInput.Root>
```

## Examples

```tsx
import { NumberInput } from '@ark-ui/react/number-input'
import { ChevronDownIcon, ChevronUpIcon } from 'lucide-react'
import styles from 'styles/number-input.module.css'

export const Basic = () => (
  <NumberInput.Root className={styles.Root}>
    <NumberInput.Label className={styles.Label}>Label</NumberInput.Label>
    <NumberInput.Control className={styles.Control}>
      <NumberInput.Input className={styles.Input} />
      <div className={styles.TriggerGroup}>
        <NumberInput.IncrementTrigger className={styles.IncrementTrigger}>
          <ChevronUpIcon />
        </NumberInput.IncrementTrigger>
        <NumberInput.DecrementTrigger className={styles.DecrementTrigger}>
          <ChevronDownIcon />
        </NumberInput.DecrementTrigger>
      </div>
    </NumberInput.Control>
  </NumberInput.Root>
)
```

### Min and Max

Set `min` and `max` to limit the value. The input clamps the value to that range.

```tsx
import { NumberInput } from '@ark-ui/react/number-input'
import { ChevronDownIcon, ChevronUpIcon } from 'lucide-react'
import styles from 'styles/number-input.module.css'

export const MinMax = () => (
  <NumberInput.Root className={styles.Root} min={0} max={10}>
    <NumberInput.Label className={styles.Label}>Label</NumberInput.Label>
    <NumberInput.Control className={styles.Control}>
      <NumberInput.Input className={styles.Input} />
      <div className={styles.TriggerGroup}>
        <NumberInput.IncrementTrigger className={styles.IncrementTrigger}>
          <ChevronUpIcon />
        </NumberInput.IncrementTrigger>
        <NumberInput.DecrementTrigger className={styles.DecrementTrigger}>
          <ChevronDownIcon />
        </NumberInput.DecrementTrigger>
      </div>
    </NumberInput.Control>
  </NumberInput.Root>
)
```

> To allow values outside the min/max range, set `clampValueOnBlur` to `false`.

### Precision

To round to fixed decimals, pass `Intl.NumberFormatOptions` like `maximumFractionDigits` or `minimumFractionDigits` to
`formatOptions`.

```tsx
import { NumberInput } from '@ark-ui/react/number-input'
import { ChevronDownIcon, ChevronUpIcon } from 'lucide-react'
import styles from 'styles/number-input.module.css'

export const FractionDigits = () => (
  <NumberInput.Root
    className={styles.Root}
    formatOptions={{ minimumFractionDigits: 2, maximumFractionDigits: 3 }}
    defaultValue={1}
  >
    <NumberInput.Label className={styles.Label}>Label</NumberInput.Label>
    <NumberInput.Control className={styles.Control}>
      <NumberInput.Input className={styles.Input} />
      <div className={styles.TriggerGroup}>
        <NumberInput.IncrementTrigger className={styles.IncrementTrigger}>
          <ChevronUpIcon />
        </NumberInput.IncrementTrigger>
        <NumberInput.DecrementTrigger className={styles.DecrementTrigger}>
          <ChevronDownIcon />
        </NumberInput.DecrementTrigger>
      </div>
    </NumberInput.Control>
  </NumberInput.Root>
)
```

### Scrubbing

Render `NumberInput.Scrubber` to change the value by dragging. It uses the Pointer Lock API to track movement and
renders a virtual cursor.

```tsx
import { NumberInput } from '@ark-ui/react/number-input'
import { ChevronDownIcon, ChevronUpIcon, ArrowLeftRightIcon } from 'lucide-react'
import styles from 'styles/number-input.module.css'

export const Scrubber = () => (
  <NumberInput.Root className={styles.Root} defaultValue={32}>
    <NumberInput.Label className={styles.Label}>Label</NumberInput.Label>
    <NumberInput.Control className={styles.Control}>
      <NumberInput.Scrubber className={styles.Scrubber}>
        <ArrowLeftRightIcon />
      </NumberInput.Scrubber>
      <NumberInput.Input className={styles.Input} data-has-scrubber />
      <div className={styles.TriggerGroup}>
        <NumberInput.IncrementTrigger className={styles.IncrementTrigger}>
          <ChevronUpIcon />
        </NumberInput.IncrementTrigger>
        <NumberInput.DecrementTrigger className={styles.DecrementTrigger}>
          <ChevronDownIcon />
        </NumberInput.DecrementTrigger>
      </div>
    </NumberInput.Control>
  </NumberInput.Root>
)
```

### Mouse Wheel

Set `allowMouseWheel` to increment or decrement with the mouse wheel.

```tsx
import { NumberInput } from '@ark-ui/react/number-input'
import { ChevronDownIcon, ChevronUpIcon } from 'lucide-react'
import styles from 'styles/number-input.module.css'

export const MouseWheel = () => (
  <NumberInput.Root className={styles.Root} allowMouseWheel>
    <NumberInput.Label className={styles.Label}>Label</NumberInput.Label>
    <NumberInput.Control className={styles.Control}>
      <NumberInput.Input className={styles.Input} />
      <div className={styles.TriggerGroup}>
        <NumberInput.IncrementTrigger className={styles.IncrementTrigger}>
          <ChevronUpIcon />
        </NumberInput.IncrementTrigger>
        <NumberInput.DecrementTrigger className={styles.DecrementTrigger}>
          <ChevronDownIcon />
        </NumberInput.DecrementTrigger>
      </div>
    </NumberInput.Control>
  </NumberInput.Root>
)
```

### Formatting

Pass `Intl.NumberFormatOptions` like `style` and `currency` to `formatOptions`.

```tsx
import { NumberInput } from '@ark-ui/react/number-input'
import { ChevronDownIcon, ChevronUpIcon } from 'lucide-react'
import styles from 'styles/number-input.module.css'

export const Formatting = () => (
  <NumberInput.Root
    className={styles.Root}
    formatOptions={{
      style: 'currency',
      currency: 'USD',
    }}
  >
    <NumberInput.Label className={styles.Label}>Label</NumberInput.Label>
    <NumberInput.Control className={styles.Control}>
      <NumberInput.Input className={styles.Input} />
      <div className={styles.TriggerGroup}>
        <NumberInput.IncrementTrigger className={styles.IncrementTrigger}>
          <ChevronUpIcon />
        </NumberInput.IncrementTrigger>
        <NumberInput.DecrementTrigger className={styles.DecrementTrigger}>
          <ChevronDownIcon />
        </NumberInput.DecrementTrigger>
      </div>
    </NumberInput.Control>
  </NumberInput.Root>
)
```

### Field

`Field` wires up the label, helper text, error text and their ARIA attributes.

```tsx
import { Field } from '@ark-ui/react/field'
import { NumberInput } from '@ark-ui/react/number-input'
import { ChevronDownIcon, ChevronUpIcon } from 'lucide-react'
import field from 'styles/field.module.css'
import styles from 'styles/number-input.module.css'

export const WithField = () => (
  <Field.Root className={field.Root}>
    <NumberInput.Root className={styles.Root}>
      <NumberInput.Label className={styles.Label}>Label</NumberInput.Label>
      <NumberInput.Control className={styles.Control}>
        <NumberInput.Input className={styles.Input} />
        <div className={styles.TriggerGroup}>
          <NumberInput.IncrementTrigger className={styles.IncrementTrigger}>
            <ChevronUpIcon />
          </NumberInput.IncrementTrigger>
          <NumberInput.DecrementTrigger className={styles.DecrementTrigger}>
            <ChevronDownIcon />
          </NumberInput.DecrementTrigger>
        </div>
      </NumberInput.Control>
    </NumberInput.Root>
    <Field.HelperText className={field.HelperText}>Additional Info</Field.HelperText>
    <Field.ErrorText className={field.ErrorText}>Error Info</Field.ErrorText>
  </Field.Root>
)
```

### Root Provider

Use `RootProvider` with the `useNumberInput` hook to access the state and methods from outside the component.

```tsx
import { NumberInput, useNumberInput } from '@ark-ui/react/number-input'
import { ChevronDownIcon, ChevronUpIcon } from 'lucide-react'
import styles from 'styles/number-input.module.css'

export const RootProvider = () => {
  const numberInput = useNumberInput()
  return (
    <div className="stack">
      <output>value: {numberInput.value}</output>
      <NumberInput.RootProvider className={styles.Root} value={numberInput}>
        <NumberInput.Label className={styles.Label}>Label</NumberInput.Label>
        <NumberInput.Control className={styles.Control}>
          <NumberInput.Input className={styles.Input} />
          <div className={styles.TriggerGroup}>
            <NumberInput.IncrementTrigger className={styles.IncrementTrigger}>
              <ChevronUpIcon />
            </NumberInput.IncrementTrigger>
            <NumberInput.DecrementTrigger className={styles.DecrementTrigger}>
              <ChevronDownIcon />
            </NumberInput.DecrementTrigger>
          </div>
        </NumberInput.Control>
      </NumberInput.RootProvider>
    </div>
  )
}
```

## Guides

### Scrubber

`NumberInput.Scrubber` is a `<div>` users drag to change the value. It shows a custom cursor while scrubbing and uses
the [Pointer Lock API](https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API).

> **Note:** Browsers may show a notification when pointer lock activates. The scrubber is disabled in Safari to prevent
> layout shifts.

### Controlled

Keep the controlled value as a string, not a number. This matters most with `formatOptions` for currency or locales.

```tsx
const [value, setValue] = useState('0')

<NumberInput.Root value={value} onValueChange={(details) => setValue(details.value)}>
  {/* ... */}
</NumberInput.Root>
```

Converting to numbers breaks locale formats with different decimal and thousands separators (e.g., `1.523,30` vs
`1,523.30`). Strings keep the formatting intact.

To submit a numeric value, add a hidden input that reads `value` from `NumberInput.Context`:

```tsx
<NumberInput.Root value={value} onValueChange={(details) => setValue(details.value)}>
  <NumberInput.Input />
  <NumberInput.Context>
    {(context) => <input type="hidden" name="amount" value={context.value ?? ''} />}
  </NumberInput.Context>
</NumberInput.Root>
```

## API Reference

### Props

### Root

#### Props

**`allowMouseWheel`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Whether to allow mouse wheel to change the value

**`allowOutOfRange`**
Type: `boolean`
Required: false
Default Value: `false`
Description: Whether a typed value can stay outside the min/max range instead of being clamped on blur or Enter.
The value is then reported as invalid. Stepping always stays within the range.

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`defaultValue`**
Type: `number`
Required: false
Default Value: `undefined`
Description: The initial value when rendered.
Use when you don't need to control the value.

**`disabled`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Whether the number input is disabled.

**`focusInputOnChange`**
Type: `boolean`
Required: false
Default Value: `true`
Description: Whether to focus input when the value changes

**`form`**
Type: `string`
Required: false
Default Value: `undefined`
Description: The associate form of the input element.

**`formatOptions`**
Type: `NumberFormatOptions`
Required: false
Default Value: `undefined`
Description: The options to pass to the `Intl.NumberFormat` constructor

**`id`**
Type: `string`
Required: false
Default Value: `undefined`
Description: The unique identifier of the machine.

**`ids`**
Type: `Partial<{
  root: string
  label: string
  input: string
  incrementTrigger: string
  decrementTrigger: string
  scrubber: string
  scrubberCursor: string
  hiddenInput: string
}>`
Required: false
Default Value: `undefined`
Description: The ids of the elements in the number input. Useful for composition.

**`inputMode`**
Type: `InputMode`
Required: false
Default Value: `undefined`
Description: Hints at the type of data that might be entered by the user. It also determines
the type of keyboard shown to the user on mobile devices.
Defaults to `"text"` on iPhone when negatives are allowed, otherwise `"decimal"`.

**`invalid`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Whether the number input value is invalid.

**`largeStep`**
Type: `number`
Required: false
Default Value: `step * 10`
Description: Step value when Shift key is held (large increments).

**`locale`**
Type: `string`
Required: false
Default Value: `"en-US"`
Description: The current locale. Based on the BCP 47 definition.

**`max`**
Type: `number`
Required: false
Default Value: `undefined`
Description: The maximum value of the number input

**`min`**
Type: `number`
Required: false
Default Value: `undefined`
Description: The minimum value of the number input

**`name`**
Type: `string`
Required: false
Default Value: `undefined`
Description: The name attribute of the number input. Useful for form submission.

**`onFocusChange`**
Type: `(details: FocusChangeDetails) => void`
Required: false
Default Value: `undefined`
Description: Function invoked when the number input is focused

**`onValueChange`**
Type: `(details: ValueChangeDetails) => void`
Required: false
Default Value: `undefined`
Description: Function invoked when the value changes

**`onValueCommit`**
Type: `(details: ValueChangeDetails) => void`
Required: false
Default Value: `undefined`
Description: Function invoked when the value settles: the input is blurred or `Enter` is pressed, a stepper
or scrub gesture ends, or a key or wheel step completes.

**`onValueInvalid`**
Type: `(details: ValueInvalidDetails) => void`
Required: false
Default Value: `undefined`
Description: Function invoked when the value overflows or underflows the min/max range

**`pattern`**
Type: `string`
Required: false
Default Value: `"-?[0-9]*(.[0-9]+)?"`
Description: The pattern used to check the <input> element's value against

**`readOnly`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Whether the number input is readonly

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<NumberInputRootState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

**`required`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Whether the number input is required

**`scrubberDirection`**
Type: `'horizontal' | 'vertical'`
Required: false
Default Value: `"horizontal"`
Description: The direction of scrubbing.

**`scrubberPixelSensitivity`**
Type: `number`
Required: false
Default Value: `2`
Description: How many pixels the pointer must move to change the value by one step.
Higher values mean more precise control. Lower values mean more sensitivity.

**`scrubberTeleportDistance`**
Type: `number`
Required: false
Default Value: `undefined`
Description: Distance in pixels before the virtual cursor wraps around.
When not set, the viewport bounds are used (default behavior).

**`smallStep`**
Type: `number`
Required: false
Default Value: `step * 0.1`
Description: Step value when Alt/Option key is held (fine control).

**`snapOnStep`**
Type: `boolean`
Required: false
Default Value: `false`
Description: Whether values snap to step multiples when scrubbing.

**`spinOnPress`**
Type: `boolean`
Required: false
Default Value: `true`
Description: Whether to spin the value when the increment/decrement button is pressed

**`step`**
Type: `number`
Required: false
Default Value: `1`
Description: The amount to increment or decrement the value by

**`translations`**
Type: `IntlTranslations`
Required: false
Default Value: `undefined`
Description: Specifies the localized strings that identifies the accessibility elements and their states

**`value`**
Type: `number`
Required: false
Default Value: `undefined`
Description: The controlled value. Use `null` for an empty input.

#### Data Attributes

**`data-number-input-root`**: <uid>
**`data-disabled`**: Present when disabled
**`data-focus`**: Present when focused
**`data-invalid`**: Present when invalid
**`data-scrubbing`**: 

### Control

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

#### Data Attributes

**`data-number-input-control`**: <uid>
**`data-focus`**: Present when focused
**`data-disabled`**: Present when disabled
**`data-invalid`**: Present when invalid
**`data-scrubbing`**: 

### DecrementTrigger

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `type ONLY_FOR_FORMAT =
  ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<NumberInputDecrementTriggerState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

#### Data Attributes

**`data-number-input-decrement-trigger`**: <uid>
**`data-disabled`**: Present when disabled
**`data-scrubbing`**: 

### IncrementTrigger

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `type ONLY_FOR_FORMAT =
  ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<NumberInputIncrementTriggerState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

#### Data Attributes

**`data-number-input-increment-trigger`**: <uid>
**`data-disabled`**: Present when disabled
**`data-scrubbing`**: 

### Input

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<NumberInputInputState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

#### Data Attributes

**`data-number-input-input`**: <uid>
**`data-invalid`**: Present when invalid
**`data-disabled`**: Present when disabled
**`data-scrubbing`**: 

### Label

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

#### Data Attributes

**`data-number-input-label`**: <uid>
**`data-disabled`**: Present when disabled
**`data-focus`**: Present when focused
**`data-invalid`**: Present when invalid
**`data-required`**: Present when required
**`data-scrubbing`**: 

### RootProvider

#### Props

**`value`**
Type: `UseNumberInputReturn`
Required: true
Default Value: `undefined`
Description: undefined

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `type ONLY_FOR_FORMAT =
  ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<NumberInputRootProviderState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

### Scrubber

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

#### Data Attributes

**`data-number-input-scrubber`**: <uid>
**`data-disabled`**: Present when disabled
**`data-scrubbing`**: 

### ValueText

#### Props

**`asChild`**
Type: `boolean`
Required: false
Default Value: `undefined`
Description: Use the provided child element as the default rendered element, combining their props and behavior.

Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`.

**`render`**
Type: `ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>`
Required: false
Default Value: `undefined`
Description: Render the part as a custom element, combining their props and behavior.

Pass an element to have the part's props merged into it, or a function to control the merge
yourself and read the part's state.

#### Data Attributes

**`data-number-input-value-text`**: <uid>
**`data-disabled`**: Present when disabled
**`data-invalid`**: Present when invalid
**`data-focus`**: Present when focused
**`data-scrubbing`**: 

### Context

**API:**

| Property | Type | Description |
|----------|------|-------------|
| `focused` | `boolean` | Whether the input is focused. |
| `scrubbing` | `boolean` | Whether the input is being scrubbed. |
| `invalid` | `boolean` | Whether the input is invalid. |
| `empty` | `boolean` | Whether the input value is empty. |
| `value` | `number | null` | The number, or `null` when the input is empty. |
| `formattedValue` | `string` | The value as shown in the input. |
| `setValue` | `(value: number) => void` | Function to set the value of the input. |
| `clearValue` | `VoidFunction` | Function to clear the value of the input. |
| `increment` | `VoidFunction` | Function to increment the value of the input by the step. |
| `decrement` | `VoidFunction` | Function to decrement the value of the input by the step. |
| `setToMax` | `VoidFunction` | Function to set the value of the input to the max. |
| `setToMin` | `VoidFunction` | Function to set the value of the input to the min. |
| `focus` | `VoidFunction` | Function to focus the input. |
| `getRootState` | `() => RootState` | Returns the state of the root. |
| `getInputState` | `() => InputState` | Returns the state of the input. |
| `getDecrementTriggerState` | `() => DecrementTriggerState` | Returns the state of the decrement trigger. |
| `getIncrementTriggerState` | `() => IncrementTriggerState` | Returns the state of the increment trigger. |


## Accessibility

Complies with the [Spinbutton WAI-ARIA design pattern](https://www.w3.org/WAI/ARIA/apg/patterns/spinbutton/).

### Keyboard Support

**`ArrowUp`**
Description: Increments the value of the number input by a predefined step.

**`ArrowDown`**
Description: Decrements the value of the number input by a predefined step.

**`Shift + ArrowUp`**
Description: Increments the value of the number input by the `largeStep` amount.

**`Shift + ArrowDown`**
Description: Decrements the value of the number input by the `largeStep` amount.

**`Alt + ArrowUp`**
Description: Increments the value of the number input by the `smallStep` amount.

**`Alt + ArrowDown`**
Description: Decrements the value of the number input by the `smallStep` amount.

**`Home`**
Description: Sets the value of the number input to its minimum allowed value.

**`End`**
Description: Sets the value of the number input to its maximum allowed value.

**`Enter`**
Description: Submits the value entered in the number input.
