Input
An input is a UI element that accepts text data from the user.
Introduction
The Input component replaces the native HTML <input>
tag, and offers expanded customization and accessibility features.
<Input />
Playground
Customization
Variants
The input component supports the four global variants: solid (default), soft, outlined, and plain.
Note that using the color
prop with danger as value gets the same result:
<Input color="danger" />
Decorators
Use the startDecorator
and/or endDecorator
props to add supporting icons or elements to the input.
It's usually more common to see input components using decorators at the top and bottom.
Inner HTML input
To pass any props to the inner HTML <input>
, use slotProps={{ input: { ...props } }}
.
CSS variables
Play around with all the CSS variables available in the input component to see how the design changes.
You can use those to customize the component on both the sx
prop and the theme.
<Input
startDecorator={<MailIcon />}
endDecorator={<Button>Message</Button>}
>
CSS Variables
Accessibility
In order for the input to be accessible, it should be linked to a label.
The FormControl
automatically generates a unique id that links the input with the FormLabel
and FormHelperText
components:
This is a helper text.
Alternatively, you can do it manually by targeting the input slot:
<label htmlFor="unique-id">Label</label>
<Input
slotProps={{
input: {
id: 'unique-id',
}
}}
/>
Anatomy
The Input component is composed of a root <div>
with an input <input>
nested inside.
<div class="JoyInput-root">
<input class="JoyInput-input" />
</div>