Skip to content

Number Field

A numeric input with stepper buttons, units, bounds and locale formatting.

Chunks returned for each query, from 1 to 10.

hero.tsx

Usage guidelines

  • Use NumberField for a precise number the user types or nudges, such as Top K, a timeout or a token limit. Use Slider when an approximate value within a range is enough, and Input for numeric identifiers such as codes or phone numbers.
  • Put the number field in a Field with a FieldLabel; the label names the input. Without a Field, give NumberFieldInput an accessible name of its own.
  • Set min and max whenever the value has bounds. Stepping stops at them, and an out-of-range typed value is clamped when the input loses focus.
  • For whole numbers such as counts and limits, set smallStep to the step value. The default smallStep of 0.1 lets Alt + arrow keys produce decimals.
  • Show the unit with NumberFieldUnit instead of putting it in the label or the value. The unit is visual only and is not part of the input's name or description, so state the unit and the bounds in a FieldDescription as well. Use format for locale formatting such as decimals, percentages or currency.
  • Pass the same size to NumberFieldGroup, NumberFieldInput, NumberFieldUnit and the stepper buttons. medium is the default; large matches large inputs.
  • The stepper buttons are named "Increment value" and "Decrement value" by default. Pass a localized aria-label or aria-labelledby in translated products.
  • Number fields that save together belong in a real form boundary: Form or a native <form>, with a Button of type="submit".

Anatomy

tsx
tsx

NumberFieldGroup draws the input surface. NumberFieldUnit and NumberFieldControls are optional.

Examples

Sizes and units

NumberFieldUnit sits between the value and the steppers. Each FieldDescription repeats the unit and range for assistive technology. The large size uses more padding and a larger value text.

seconds

From 1 to 600 seconds.

tokens

Up to 4,096 tokens per response.

sizes.tsx

States

Set invalid on the Field when application code owns the validity, and render <FieldError match> while it is invalid; bringing the value back into range clears the error. Set disabled on Field to disable the label, input and steppers together, and readOnly on NumberField so the value stays focusable while the steppers stop.

%

Minimum match percentage, from 0 to 100%.

Use a percentage from 0 to 100.
requests/min

Workspace quota in requests per minute (read-only).

Managed by the workspace owner.

states.tsx

Step sizes and formatting

step sets the amount for the buttons and arrow keys. smallStep and largeStep set the amounts used with modifier keys. format takes Intl.NumberFormat options. The mouse wheel does not change the value unless allowWheelScrub is set, and then only while the input has focus.

From 0 to 2. Higher values make responses more varied.

steps.tsx

Validation in a form

A required number field shows its valueMissing message when the form is submitted empty. A typed value outside min and max is clamped when the input loses focus, so the field needs no range messages.

Characters per chunk, from 100 to 4000.

validation.tsx

Keyboard

KeyAction
Up arroworDown arrowIncreases or decreases the value by step, stopping at min and max.
Shift+Up arroworShift+Down arrowSteps by largeStep (10 by default).
Alt+Up arroworAlt+Down arrowSteps by smallStep (0.1 by default).
HomeorEndSets the value to min or max, when that bound is set.
TabMoves focus out of the input and commits a typed value, clamped to the bounds. The stepper buttons are not in the tab order.

API reference

NumberField

Groups all parts of a numeric input with increment and decrement controls. Renders a <div> element.

Base UI NumberField.Root docs

Data attributes
AttributeDescription
data-scrubbing

Present while scrubbing.

data-disabled

Present when the number field is disabled.

data-readonly

Present when the number field is readonly.

data-required

Present when the number field is required.

data-valid

Present when the number field is in a valid state (when wrapped in Field.Root).

data-invalid

Present when the number field is in an invalid state (when wrapped in Field.Root).

data-touched

Present when the number field has been touched (when wrapped in Field.Root).

data-dirty

Present when the number field's value has changed (when wrapped in Field.Root).

data-filled

Present when the number field is filled (when wrapped in Field.Root).

data-focused

Present when the number field is focused (when wrapped in Field.Root).

NumberFieldControls

Accepts the props of the element it renders.

NumberFieldDecrement

A stepper button that decreases the field value when clicked. Renders a <button> element.

Base UI NumberField.Decrement docs

Props
PropTypeDefaultDetails
size'large' | 'medium''medium'
Base UI NumberField.Decrement docs
Data attributes
AttributeDescription
data-scrubbing

Present while scrubbing.

data-disabled

Present when the number field is disabled.

data-readonly

Present when the number field is readonly.

data-required

Present when the number field is required.

data-valid

Present when the number field is in a valid state (when wrapped in Field.Root).

data-invalid

Present when the number field is in an invalid state (when wrapped in Field.Root).

data-touched

Present when the number field has been touched (when wrapped in Field.Root).

data-dirty

Present when the number field's value has changed (when wrapped in Field.Root).

data-filled

Present when the number field is filled (when wrapped in Field.Root).

data-focused

Present when the number field is focused (when wrapped in Field.Root).

NumberFieldGroup

Groups the input with the increment and decrement buttons. Renders a <div> element.

Base UI NumberField.Group docs

Props
PropTypeDefaultDetails
size'large' | 'medium''medium'
Base UI NumberField.Group docs
Data attributes
AttributeDescription
data-scrubbing

Present while scrubbing.

data-disabled

Present when the number field is disabled.

data-readonly

Present when the number field is readonly.

data-required

Present when the number field is required.

data-valid

Present when the number field is in a valid state (when wrapped in Field.Root).

data-invalid

Present when the number field is in an invalid state (when wrapped in Field.Root).

data-touched

Present when the number field has been touched (when wrapped in Field.Root).

data-dirty

Present when the number field's value has changed (when wrapped in Field.Root).

data-filled

Present when the number field is filled (when wrapped in Field.Root).

data-focused

Present when the number field is focused (when wrapped in Field.Root).

NumberFieldIncrement

A stepper button that increases the field value when clicked. Renders a <button> element.

Base UI NumberField.Increment docs

Props
PropTypeDefaultDetails
size'large' | 'medium''medium'
Base UI NumberField.Increment docs
Data attributes
AttributeDescription
data-scrubbing

Present while scrubbing.

data-disabled

Present when the number field is disabled.

data-readonly

Present when the number field is readonly.

data-required

Present when the number field is required.

data-valid

Present when the number field is in a valid state (when wrapped in Field.Root).

data-invalid

Present when the number field is in an invalid state (when wrapped in Field.Root).

data-touched

Present when the number field has been touched (when wrapped in Field.Root).

data-dirty

Present when the number field's value has changed (when wrapped in Field.Root).

data-filled

Present when the number field is filled (when wrapped in Field.Root).

data-focused

Present when the number field is focused (when wrapped in Field.Root).

NumberFieldInput

The native input control in the number field. Renders an <input> element.

Base UI NumberField.Input docs

Props
PropTypeDefaultDetails
size'large' | 'medium''medium'
Base UI NumberField.Input docs
Data attributes
AttributeDescription
data-scrubbing

Present while scrubbing.

data-disabled

Present when the number field is disabled.

data-readonly

Present when the number field is readonly.

data-required

Present when the number field is required.

data-valid

Present when the number field is in a valid state (when wrapped in Field.Root).

data-invalid

Present when the number field is in an invalid state (when wrapped in Field.Root).

data-touched

Present when the number field has been touched (when wrapped in Field.Root).

data-dirty

Present when the number field's value has changed (when wrapped in Field.Root).

data-filled

Present when the number field is filled (when wrapped in Field.Root).

data-focused

Present when the number field is focused (when wrapped in Field.Root).

NumberFieldUnit

Props
PropTypeDefaultDetails
size'large' | 'medium''medium'