---
title: Number Input
description: A compact numeric input with stacked increment and decrement buttons.
links:
  doc: https://base-ui.com/react/components/number-field
  anatomy: https://base-ui.com/react/components/number-field#anatomy
  api: https://base-ui.com/react/components/number-field#api-reference
---

```tsx
import { NumberInput } from "@/components/ui/number-input";

export function NumberInputDemo() {
  return (
    <div>
      <label htmlFor="number-input" className="mb-2 inline-block font-medium">
        Number Input
      </label>
      <NumberInput id="number-input" placeholder="Enter a number" />
    </div>
  );
}
```

## Installation

<CodeTabs>

<TabsList>
  <TabsTab value="cli">CLI</TabsTab>
  <TabsTab value="manual">Manual</TabsTab>
</TabsList>
<TabsPanel value="cli">

```bash
npx @zbmui/cli@latest add number-input
```

</TabsPanel>
<TabsPanel value="manual">

<Steps>

<Step>Install the following dependencies:</Step>

```bash
npm install @base-ui/react @tabler/icons-react
```

<Step>Copy and paste the following code into your project.</Step>

<ComponentSource name="number-input" title="components/ui/number-input.tsx" />

<Step>Update the import paths to match your project setup.</Step>

</Steps>
</TabsPanel>

</CodeTabs>

## Usage

```tsx
import { NumberInput } from "@/components/ui/number-input";
```

```tsx
<NumberInput />
```

## Example

### Sizes

Pass the `size` prop to set the size of the NumberInput. Available sizes are `xs`, `sm`, `default`, `lg`, and `xl`.

```tsx
import { NumberInput } from "@/components/ui/number-input";

export function NumberInputDemo() {
  return (
    <div className="flex flex-col gap-4">
      <NumberInput placeholder="Enter a number" size="xs" />
      <NumberInput placeholder="Enter a number" size="sm" />
      <NumberInput placeholder="Enter a number" size="default" />
      <NumberInput placeholder="Enter a number" size="lg" />
      <NumberInput placeholder="Enter a number" size="xl" />
    </div>
  );
}
```

### Controlled

Use `value` and `onValueChange` to control the input from state. The value is `null` when the input is empty.

```tsx
"use client";

import { useState } from "react";

import { NumberInput } from "@/components/ui/number-input";

export function NumberInputDemo() {
  const [age, setAge] = useState<number | null>(null);

  return (
    <div>
      <label htmlFor="age" className="mb-2 inline-block font-medium">
        Enter your age
      </label>
      <NumberInput id="age" min={0} max={200} value={age} onValueChange={setAge} />
      <p className="mt-2 text-muted-foreground text-sm">Your age is: {age ?? "null"}</p>
    </div>
  );
}
```

### Minimum and maximum value

Pass the `min` prop or `max` prop to set an upper and lower limit for the input. By default, the input will restrict the value to stay within the specified range.

```tsx
function NumberInputDemo() {
  return <NumberInput min={0} max={10} />;
}
```

## API Reference

### NumberInput Props


| Prop           | Type                                             | Default     | Description                                                               |
| -------------- | ------------------------------------------------ | ----------- | ------------------------------------------------------------------------- |
| `size`?        | `'xs' \| 'sm' \| 'default' \| 'lg' \| 'xl'`      | `'default'` | The size of the input component.                                          |
| `placeholder`? | `string`                                         | -           | The placeholder text to display when the input is empty.                  |
| `inputProps`?  | `React.ComponentProps<typeof NumberField.Input>` | -           | Props forwarded to the underlying input element, including its className. |

