Input API
API reference docs for the React Input component. Learn about the props, CSS, and other APIs of this exported module.
Demos
Import
import Input from '@mui/material/Input';
// or
import { Input } from '@mui/material';
Learn about the difference by reading this guide on minimizing bundle size.
Props of the InputBase component are also available.
Name | Type | Default | Description |
---|---|---|---|
autoComplete | string | - | This prop helps users to fill forms faster, especially on mobile devices. The name can be confusing, as it's more like an autofill. You can learn more about it following the specification. |
autoFocus | bool | - | If |
classes | object | - | Override or extend the styles applied to the component. See CSS classes API below for more details. |
color | 'primary' | 'secondary' | string | - | The color of the component. It supports both default and custom theme colors, which can be added as shown in the palette customization guide. The prop defaults to the value ( |
components | { Input?: elementType, Root?: elementType } | {} | The components used for each slot inside. |
componentsProps | { input?: object, root?: object } | {} | The extra props for the slot components. You can override the existing props or add new ones. |
defaultValue | any | - | The default value. Use when the component is not controlled. |
disabled | bool | - | If |
disableUnderline | bool | false | If |
endAdornment | node | - | End |
error | bool | - | If |
fullWidth | bool | false | If |
id | string | - | The id of the |
inputComponent | elementType | 'input' | The component used for the |
inputProps | object | {} | Attributes applied to the |
inputRef | ref | - | Pass a ref to the |
margin | 'dense' | 'none' | - | If |
maxRows | number | string | - | Maximum number of rows to display when multiline option is set to true. |
minRows | number | string | - | Minimum number of rows to display when multiline option is set to true. |
multiline | bool | false | If |
name | string | - | Name attribute of the |
onChange | func | - | Callback fired when the value is changed. Signature: function(event: React.ChangeEvent
|
placeholder | string | - | The short hint displayed in the |
readOnly | bool | - | It prevents the user from changing the value of the field (not from interacting with the field). |
required | bool | - | If |
rows | number | string | - | Number of rows to display when multiline option is set to true. |
slotProps | { input?: object, root?: object } | {} | The extra props for the slot components. You can override the existing props or add new ones. |
slots | { input?: elementType, root?: elementType } | {} | The components used for each slot inside. |
startAdornment | node | - | Start |
sx | Array<func | object | bool> | func | object | - | The system prop that allows defining system overrides as well as additional CSS styles. See the `sx` page for more details. |
type | string | 'text' | Type of the |
value | any | - | The value of the |
ref
is forwarded to the root element.Inheritance
While not explicitly documented above, the props of the InputBase component are also available in Input. You can take advantage of this to target nested components.
Theme default props
You can use MuiInput
to change the default props of this component with the theme.
These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.
Class name | Rule name | Description |
---|---|---|
.Mui-disabled | Styles applied to the root element if disabled={true} . | |
.Mui-error | State class applied to the root element if error={true} . | |
.Mui-focused | Styles applied to the root element if the component is focused. | |
.MuiInput-colorSecondary | colorSecondary | Styles applied to the root element if color secondary. |
.MuiInput-formControl | formControl | Styles applied to the root element if the component is a descendant of FormControl . |
.MuiInput-fullWidth | fullWidth | Styles applied to the root element if fullWidth={true} . |
.MuiInput-input | input | Styles applied to the input element. |
.MuiInput-inputAdornedEnd | inputAdornedEnd | Styles applied to the input element if endAdornment is provided. |
.MuiInput-inputAdornedStart | inputAdornedStart | Styles applied to the input element if startAdornment is provided. |
.MuiInput-inputMultiline | inputMultiline | Styles applied to the input element if multiline={true} . |
.MuiInput-inputSizeSmall | inputSizeSmall | Styles applied to the input element if size="small" . |
.MuiInput-inputTypeSearch | inputTypeSearch | Styles applied to the input element if type="search" . |
.MuiInput-multiline | multiline | Styles applied to the root element if multiline={true} . |
.MuiInput-root | root | Styles applied to the root element. |
.MuiInput-sizeSmall | sizeSmall | Styles applied to the input element if size="small" . |
.MuiInput-underline | underline | Styles applied to the root element unless disableUnderline={true} . |
You can override the style of the component using one of these customization options:
- With a global class name.
- With a rule name as part of the component's
styleOverrides
property in a custom theme.