Skip to content

Input

The Input component facilitates the entry of text data from the user.

Introduction

The Input component enhances the functionality of the native HTML <input> tag by providing expanded customization options and accessibility features.

<Input />

Playground

Basics

<span class="token keyword">import</span> Input <span class="token keyword">from</span> <span class="token string">'@mui/joy/Input'</span><span class="token punctuation">;</span>

The Input component provides a customizable input field that can be used to collect user information, such as name, email, password, or other types of data.

Press Enter to start editing

Customization

Variants

The Input component supports Joy UI's four global variants: solid (default), soft, outlined, and plain.

Press Enter to start editing

Sizes

The input component comes in three sizes: sm, md (default), and lg:

Press Enter to start editing

Colors

Every palette included in the theme is available via the color prop.

Press Enter to start editing

Form props

You can add standard form attributes such as required and disabled to the Input component:

Press Enter to start editing

Focused ring

Provide these CSS variables to sx prop to control the focused ring appearance:

  • --Input-focusedInset: the focused ring's position, either inside(inset) or outside(var(--any, )) of the Input.
  • --Input-focusedThickness: the size of the focused ring.
  • --Input-focusedHighlight: the color of the focused ring.
Press Enter to start editing

Debugging the focus ring

To display the Input's focus ring by simulating user's focus, inspect the Input element and toggle the pseudostate panel.

  • If you inspect the Input's root element, with .MuiInput-root class, you have to toggle on the :focus-within state.
  • If you inspect the <input> element, you can toggle with either :focus or :focus-within states.

Triggering the focus ring

To trigger the focus ring programmatically, set the CSS variable --Input-focused: 1.

Press Enter to start editing

Validation

Use the error prop to toggle the error state:

Press Enter to start editing

Decorators

The startDecorator and endDecorator props can be used to add supporting icons or elements to the input. With inputs, decorators are typically located at the top and/or bottom of the input field.

$

Inner HTML input

If you need to pass props to the inner HTML <input>, use slotProps={{ input: { ...props } }}. These props may include HTML attributes such as ref, min, max, and autocomplete.

Common examples

Focus outline

This example shows how to replace the default focus ring (using ::before) with CSS outline.

Press Enter to start editing

Floating label

To create a floating label input, a custom component (combination of <input> and <label>) is required to replace the default input slot.

Press Enter to start editing

Underline input

Newsletter Subscription

Password meter

Very weak

CSS variable playground

Play around with the CSS variables available to the Input component to see how the design changes. You can use these to customize the component with both the sx prop and the theme.

<Input
  startDecorator={<MailIcon />}
  endDecorator={<Button>Message</Button>}
>

CSS Variables

px

px

px

px

px

px

Accessibility

All inputs should have a descriptive label linked to help users understand its purpose.

The Form Control component automatically generates a unique ID that links the Input with the Form Label and Form Helper Text components:

This is a helper text.
Press Enter to start editing

Alternatively, you can do this manually by targeting the input slot—see inner HTML input for details:

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>label</span> <span class="token attr-name">htmlFor</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>unique-id<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>Label<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>label</span><span class="token punctuation">></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span><span class="token class-name">Input</span></span>
  <span class="token attr-name">slotProps</span><span class="token script language-javascript"><span class="token script-punctuation punctuation">=</span><span class="token punctuation">{</span><span class="token punctuation">{</span>
    <span class="token literal-property property">input</span><span class="token operator">:</span> <span class="token punctuation">{</span>
      <span class="token literal-property property">id</span><span class="token operator">:</span> <span class="token string">'unique-id'</span><span class="token punctuation">,</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">}</span></span>
<span class="token punctuation">/></span></span>

Anatomy

The Input component is composed of a root <div> with an <input> nested inside:

<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>MuiInput-root<span class="token punctuation">"</span></span><span class="token punctuation">></span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>MuiInput-input<span class="token punctuation">"</span></span> <span class="token punctuation">/></span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>div</span><span class="token punctuation">></span></span>

Unstyled

API

See the documentation below for a complete reference to all of the props and classes available to the components mentioned here.