Number Field
Number Fields let users enter, format, and adjust numeric values.
Number fields combine a numeric input with increment and decrement buttons. Use them for quantities, prices, percentages, and other values that users need to adjust.
Basic NumberField
The NumberField component includes a label, an input, stepper buttons, and optional helper text.
It comes with three variants: outlined (default), filled, and standard.
import Box from '@mui/material/Box';
import NumberField from '@mui/material/NumberField';
export default function BasicNumberFields() {
return (
<Box
sx={{
display: 'flex',
flexWrap: 'wrap',
gap: 3,
'& > .MuiNumberField-root': { width: '25ch' },
}}
>
<NumberField label="Outlined" defaultValue={5} />
<NumberField label="Filled" variant="filled" defaultValue={5} />
<NumberField label="Standard" variant="standard" defaultValue={5} />
</Box>
);
}
Form props
Use required, disabled, and readOnly to control interaction with the field.
The helperText prop provides context about the expected input.
Number of items to order.
import Box from '@mui/material/Box';
import NumberField from '@mui/material/NumberField';
export default function FormPropsNumberFields() {
return (
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 3 }}>
<NumberField
label="Required"
required
defaultValue={5}
helperText="Number of items to order."
/>
<NumberField label="Disabled" disabled defaultValue={5} />
<NumberField label="Read only" readOnly defaultValue={5} />
</Box>
);
}
Controlled and uncontrolled values
Use defaultValue for an uncontrolled field, or value with onValueChange for a controlled field.
Use null for a controlled empty field, or omit defaultValue to start an uncontrolled field empty.
Zero is a numeric value.
onValueChange receives the next number or null, followed by details about the interaction.
Use onValueCommitted to respond when an edit is committed.
Typing commits on blur, keyboard and wheel adjustments commit immediately, and pointer presses on the buttons and scrub area commit on release.
Both callbacks include a details.reason identifying the interaction.
Call details.cancel() in onValueChange to reject a proposed change.
Value: 0 · Last committed: 0
import * as React from 'react';
import Box from '@mui/material/Box';
import NumberField from '@mui/material/NumberField';
import Typography from '@mui/material/Typography';
export default function NumberFieldState() {
const [value, setValue] = React.useState<number | null>(0);
const [committed, setCommitted] = React.useState<number | null>(0);
return (
<div>
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 3 }}>
<NumberField
label="Controlled"
value={value}
onValueChange={setValue}
onValueCommitted={setCommitted}
/>
<NumberField label="Uncontrolled" defaultValue={5} />
</Box>
<Typography sx={{ mt: 2 }}>
Value: {String(value)} · Last committed: {String(committed)}
</Typography>
</div>
);
}
Validation
Use error to display an error state and helperText to explain how to correct the value.
The following example applies a custom validation rule to the controlled numeric value.
Order at least 10 items.
import * as React from 'react';
import NumberField from '@mui/material/NumberField';
export default function ValidationNumberField() {
const [value, setValue] = React.useState<number | null>(5);
const error = value === null || value < 10;
return (
<NumberField
label="Order quantity"
value={value}
onValueChange={setValue}
min={0}
required
error={error}
helperText={error ? 'Order at least 10 items.' : 'Your quantity is valid.'}
/>
);
}
Minimum and maximum values
Use min and max to limit the value.
The increment and decrement buttons become disabled at their respective bounds.
The displayed text is clamped when the input loses focus.
Numeric values reported by onValueChange are clamped while editing.
Set allowOutOfRange to keep typed values outside the range.
Stepping with the buttons or keyboard still respects the bounds.
Type 11, then leave the field.
Typed values outside 1–10 are kept.
import Box from '@mui/material/Box';
import NumberField from '@mui/material/NumberField';
export default function NumberFieldConstraints() {
return (
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 3 }}>
<NumberField
label="Clamped to range"
defaultValue={5}
min={1}
max={10}
helperText="Type 11, then leave the field."
/>
<NumberField
label="Allow out of range"
defaultValue={5}
min={1}
max={10}
allowOutOfRange
helperText="Typed values outside 1–10 are kept."
/>
</Box>
);
}
Stepping
Use step to set the amount added or subtracted by the buttons and the Arrow Up and Arrow Down keys.
The default step is 1.
Use smallStep and largeStep to set the step while holding Alt (Option on macOS) and Shift, respectively.
Their defaults are 0.1 and 10.
When bounds are set, Home moves to min and End moves to max.
Set snapOnStep to snap to step intervals starting at min, or 0 if min is omitted.
Adjust by 0.25.
Hold Alt for 0.25 or Shift for 5.
Stepping snaps to a multiple of 2.
Mouse wheel
Set allowWheelScrub to adjust the value with the mouse wheel while the input is focused and hovered.
Wheel stepping is disabled by default.
<NumberField label="Quantity" defaultValue={5} allowWheelScrub />
Formatting and localization
Use format to display currencies, percentages, units, or a specific number of decimal places.
It accepts the options supported by Intl.NumberFormat.
Use locale to control formatting and parsing independently of the browser's locale.
The value and value callbacks use unformatted numbers or null, regardless of the display format.
For example, a value of 0.125 is displayed as 12.5% with percent formatting.
Control placement
Set controlsPosition to end (default), split, or stacked to change the control layout.
Start and end follow the text direction.
Use false to render no buttons at all.
Use slots.controls or slotProps.controls to customize the button groups.
With split controls, the same slot renders on both sides; use the callback's ownerState.position ('start' or 'end') to customize each side.
Scrubbing
Set scrubAreaPosition to "start" or "end" to add a handle that users can drag to adjust the value.
The default is false, which hides the handle.
Its position is independent of controlsPosition.
import Box from '@mui/material/Box';
import NumberField from '@mui/material/NumberField';
export default function NumberFieldScrubAreaPlacement() {
return (
<Box
sx={{
display: 'flex',
flexWrap: 'wrap',
gap: 3,
'& > .MuiNumberField-root': { width: '25ch' },
}}
>
<NumberField label="Start handle" defaultValue={5} scrubAreaPosition="start" />
<NumberField
label="End handle"
defaultValue={5}
scrubAreaPosition="end"
controlsPosition="stacked"
/>
</Box>
);
}
Slot-prop callbacks receive the live boolean ownerState.scrubbing.
The root has the MuiNumberField-scrubbing class while the user drags the handle.
Direction and sensitivity
Dragging adjusts the value horizontally by default.
Set slotProps.scrubArea.direction to "vertical" for up/down dragging.
Increase slotProps.scrubArea.pixelSensitivity to require more pointer movement before the value changes.
Use slotProps.scrubArea.teleportDistance to set how far the cursor can move from the handle's center before wrapping back around.
Move at least 8 pixels to change the value.
Drag vertically to change the value.
import Box from '@mui/material/Box';
import NumberField from '@mui/material/NumberField';
export default function NumberFieldScrubAreaOptions() {
return (
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 3 }}>
<NumberField
label="Horizontal dragging"
defaultValue={5}
scrubAreaPosition="start"
helperText="Move at least 8 pixels to change the value."
slotProps={{ scrubArea: { pixelSensitivity: 8 } }}
/>
<NumberField
label="Vertical dragging"
defaultValue={5}
scrubAreaPosition="start"
helperText="Drag vertically to change the value."
slotProps={{ scrubArea: { direction: 'vertical' } }}
/>
</Box>
);
}
Custom handle and cursor
Use slotProps.scrubArea to customize the handle and slotProps.scrubAreaCursor to customize the cursor displayed during dragging.
Both slots support custom content through children and styles through sx.
The example uses ownerState.scrubbing in slotProps.scrubArea to highlight the handle during a drag.
The custom cursor appears during mouse dragging when pointer lock is available.
It is not shown in Safari or during touch interactions.
Input adornments
Use startAdornment or endAdornment to place text, an icon, or a button next to the input.
Pass the content directly, as in startAdornment="$" and endAdornment="/hr" for an hourly rate.
When the same side also has a scrub handle or stepper buttons, the adornment sits closest to the input.
Adornments sit outside the editable value. To format the value itself according to the locale, use the format prop.
$
/hr
Sizes
Use size="small" for a more compact field.
The size applies to the input and both stepper buttons.
Color
The color prop changes the highlight color when the field is focused.
import Box from '@mui/material/Box';
import NumberField from '@mui/material/NumberField';
export default function NumberFieldColors() {
return (
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 3 }}>
<NumberField label="Secondary" color="secondary" defaultValue={5} focused />
<NumberField label="Success" color="success" defaultValue={5} focused />
</Box>
);
}
Full width
Use fullWidth to fill the width of the field's container.
import Box from '@mui/material/Box';
import NumberField from '@mui/material/NumberField';
export default function FullWidthNumberField() {
return (
<Box sx={{ width: 500, maxWidth: '100%' }}>
<NumberField label="Quantity" defaultValue={5} fullWidth />
</Box>
);
}
Form submission
Set name directly on NumberField to include its numeric value in form submission.
The submitted value is the unformatted number, even when the input displays a currency or another format.
Use form to associate a field with a form outside its DOM ancestry.
Uncontrolled fields do not yet support native form reset. See Base UI issue #1346.
The example below uses a controlled value and restores it in onReset so the Reset button returns the field to its initial value.
Controlling the input
Use slotProps.htmlInput for native input attributes, event handlers, and refs.
Use slotProps.input to customize the Material input wrapper, such as its styles or the outlined variant's notchedOutline slot.
NumberField displays its formatted value in a single-line text input.
Set value or defaultValue on NumberField itself.
<NumberField
label="Quantity"
slotProps={{
input: { sx: { borderRadius: 2 } },
htmlInput: { enterKeyHint: 'done' },
}}
/>
To handle an arrow key yourself, call event.preventBaseUIHandler() in slotProps.htmlInput.onKeyDown to skip NumberField's default step for that key.
The field's resolved disabled, readOnly, and required states take precedence over conflicting slot props.
The forwarded ref points to the root element.
Use inputRef to access or focus the visible input.
Customization
Rendering custom elements
Use render to change the root element while preserving Material styling and the default FormControl context.
Other slots accept render through slotProps, such as slotProps.htmlInput.render or slotProps.formHelperText.render.
The prop accepts a React element or a callback receiving the generated props and live Base UI state. Spread the generated props onto the rendered element to preserve its ref, event handlers, styles, and accessibility attributes. Custom components must forward the ref to their DOM element.
The following example renders the root as a <section> and uses the helper text's render callback to show the current value:
Tickets selected: 2
For a button rendered as an element other than <button>, also set that slot's nativeButton prop to false.
Use slots to replace a Material component and provide your own styling.
A slots replacement takes precedence over render for the same slot.
If you replace slots.root, forward its props and ref to a FormControl so the label shrinks on focus and both the label and helper text reflect the field's error state.
See the API reference for the available slots.
Use slotProps.input.render to change the Material input's root element.
That element also provides Base UI's NumberField Group semantics with role="group".
Theme overrides
Use MuiNumberField in the theme to set default props and override slot styles.
In styleOverrides.root, use & .MuiNumberField-htmlInput to style the native input and &.MuiNumberField-scrubbing to style the root during a drag.
The following example sets small, stacked controls and a scrub handle as theme defaults. It gives the buttons different colors and adds an outline while scrubbing.
Drag the handle to see the active outline.
See themed components for more details.
Data attributes
NumberField exposes Base UI's state attributes on the following slots.
Import the corresponding constants from @mui/material/NumberField to use them in selectors or tests.
| Slot | Export |
|---|---|
root |
NumberFieldRootDataAttributes |
input |
NumberFieldGroupDataAttributes |
htmlInput |
NumberFieldInputDataAttributes |
incrementButton |
NumberFieldIncrementDataAttributes |
decrementButton |
NumberFieldDecrementDataAttributes |
scrubArea |
NumberFieldScrubAreaDataAttributes |
scrubAreaCursor |
NumberFieldScrubAreaCursorDataAttributes |
Each namespace includes data-scrubbing, data-disabled, data-readonly, and data-required.
When wrapped in Base UI's Field.Root, the slots can also expose data-valid, data-invalid, data-touched, data-dirty, data-filled, and data-focused.
For example, NumberFieldRootDataAttributes.scrubbing is the attribute name data-scrubbing, which is present while the user drags the scrub handle.
Anatomy
NumberField combines Material UI components with Base UI's numeric input behavior. The following shows its slots with a scrub handle at the start and controls at the end:
root (FormControl)
├── inputLabel (InputLabel, optional)
├── input (OutlinedInput, FilledInput, or Input)
│ ├── scrubArea (span, optional)
│ ├── startAdornment content (InputAdornment, optional)
│ ├── htmlInput (input)
│ ├── endAdornment content (InputAdornment, optional)
│ └── controls (InputAdornment, optional)
│ ├── decrementButton (IconButton)
│ └── incrementButton (IconButton)
└── formHelperText (FormHelperText, optional)
The Material input root also serves as Base UI's Group, without an extra wrapper.
With split controls, the controls slot renders once on each side of the input.
The scrubAreaCursor slot renders in a portal while scrubbing.
A visually hidden native input follows the root slot as a sibling in the DOM.
To space adjacent fields, use gap on their flex or grid container.
Accessibility
NumberField renders a native text input with the implicit textbox role.
Provide a label to name the input.
NumberField links the label and helper text to the input automatically and generates an ID when id is omitted.
For a field without a visible label, provide an accessible name through slotProps.htmlInput:
<NumberField slotProps={{ htmlInput: { 'aria-label': 'Quantity' } }} />
The stepper buttons use tabIndex={-1} by default to avoid redundant tab stops.
Keyboard users can adjust the value from the input with the keyboard shortcuts described above.
The buttons remain exposed to screen readers, including on touch devices.
NumberField uses Base UI for numeric input behavior and Material UI components for its appearance.
API
See the documentation below for a complete reference to all of the props and classes available to the components mentioned here.