Tailwind CSS Input - React

Easily create Input with different statuses and sizes using our components based on Tailwind CSS and React.

Input fields are an essential user interface design element, providing users with the means to enter non-standardized responses.

See below our Input component examples. It comes in different styles and colors, so you can adapt it easily to your needs.


Input Demo

Here's how to implement a simple and responsive Input component. It is perfect for forms requiring text input, such as user registration, login forms, or any form where users need to input a username.

"use client";

import { Input } from "@material-tailwind/react";

export function InputDemo() {
return (
<div className="w-72">
<Input placeholder="Input" />
</div>
);
}
"use client";

import { Input } from "@material-tailwind/react";

export function InputDemo() {
return (
<div className="w-72">
<Input placeholder="Input" />
</div>
);
}

Input Sizes

We provide different input sizes like sm, md, and lg so you can adapt it easily to your needs. You can simply use the size prop to change the input size.

In the example below, we've showcased the different input sizes that you can use in your project.

"use client";

import { Input } from "@material-tailwind/react";

export function InputSizes() {
return (
<div className="w-72 space-y-4">
<Input size="sm" placeholder="Input Small" />
<Input size="md" placeholder="Input Medium" />
<Input size="lg" placeholder="Input Large" />
</div>
);
}
"use client";

import { Input } from "@material-tailwind/react";

export function InputSizes() {
return (
<div className="w-72 space-y-4">
<Input size="sm" placeholder="Input Small" />
<Input size="md" placeholder="Input Medium" />
<Input size="lg" placeholder="Input Large" />
</div>
);
}

Input Color

We provide different input colors like primary, secondary, info, success, warning, and error so you can adapt it easily to your needs. You can simply use the color prop to change the input color.

In the example below, we've showcased the different input colors that you can use in your project.

"use client";

import { Input } from "@material-tailwind/react";

export function InputColors() {
return (
<div className="w-72 space-y-4">
<Input color="primary" placeholder="Input Primary" />
<Input color="secondary" placeholder="Input Secondary" />
<Input color="info" placeholder="Input Info" />
<Input color="success" placeholder="Input Success" />
<Input color="warning" placeholder="Input Warning" />
<Input color="error" placeholder="Input Error" />
</div>
);
}
"use client";

import { Input } from "@material-tailwind/react";

export function InputColors() {
return (
<div className="w-72 space-y-4">
<Input color="primary" placeholder="Input Primary" />
<Input color="secondary" placeholder="Input Secondary" />
<Input color="info" placeholder="Input Info" />
<Input color="success" placeholder="Input Success" />
<Input color="warning" placeholder="Input Warning" />
<Input color="error" placeholder="Input Error" />
</div>
);
}

Input with Validation

We provide helpful props like isError and isSuccess for showing error and success states of an input. In the example below, we've showcased the Input component with error and success states that you can use in your project.

Something went wrong!
Congratulations 🎉
"use client";

import { Input, Typography } from "@material-tailwind/react";

export function InputWithValidation() {
return (
<div className="w-72 space-y-6">
<div>
<Input
isError
color="error"
placeholder="Input Error"
className="w-full"
/>
<Typography type="small" color="error" className="mt-1 block">
Something went wrong!
</Typography>
</div>
<div>
<Input
isSuccess
color="success"
placeholder="Input Success"
className="w-full"
/>
<Typography type="small" color="success" className="mt-1 block">
Congratulations 🎉
</Typography>
</div>
</div>
);
}
"use client";

import { Input, Typography } from "@material-tailwind/react";

export function InputWithValidation() {
return (
<div className="w-72 space-y-6">
<div>
<Input
isError
color="error"
placeholder="Input Error"
className="w-full"
/>
<Typography type="small" color="error" className="mt-1 block">
Something went wrong!
</Typography>
</div>
<div>
<Input
isSuccess
color="success"
placeholder="Input Success"
className="w-full"
/>
<Typography type="small" color="success" className="mt-1 block">
Congratulations 🎉
</Typography>
</div>
</div>
);
}

Input with Icon

You can add an icon to the start or end of the input to make it more visually appealing and informative. Use the example below to create inputs with icon.

In the example below we've used the Iconoir icons, but you can use any other icon library you prefer.

"use client";

import { Input } from "@material-tailwind/react";
import { ProfileCircle, Lock } from "iconoir-react";

export function InputWithIcon() {
return (
<div className="w-72 space-y-4">
<Input placeholder="Username">
<Input.Icon>
<ProfileCircle className="h-full w-full" />
</Input.Icon>
</Input>
<Input placeholder="Password">
<Input.Icon placement="end">
<Lock className="h-full w-full" />
</Input.Icon>
</Input>
</div>
);
}
"use client";

import { Input } from "@material-tailwind/react";
import { ProfileCircle, Lock } from "iconoir-react";

export function InputWithIcon() {
return (
<div className="w-72 space-y-4">
<Input placeholder="Username">
<Input.Icon>
<ProfileCircle className="h-full w-full" />
</Input.Icon>
</Input>
<Input placeholder="Password">
<Input.Icon placement="end">
<Lock className="h-full w-full" />
</Input.Icon>
</Input>
</div>
);
}

Input with Label

The Input component can be used with a label to provide more context to the user. In the example below, we've added a label to the input by using the Input and Typography components together.

"use client";

import { Input, Typography } from "@material-tailwind/react";

export function InputWithLabel() {
return (
<div className="w-72 space-y-1">
<Typography
as="label"
htmlFor="email"
type="small"
color="default"
className="font-semibold"
>
Email
</Typography>
<Input id="email" type="email" placeholder="[email protected]" />
</div>
);
}
"use client";

import { Input, Typography } from "@material-tailwind/react";

export function InputWithLabel() {
return (
<div className="w-72 space-y-1">
<Typography
as="label"
htmlFor="email"
type="small"
color="default"
className="font-semibold"
>
Email
</Typography>
<Input id="email" type="email" placeholder="[email protected]" />
</div>
);
}

Input with Helper Text

You can use Input and Typography components together to provide more details for the input. In the example below, we've added a hint text with an icon below the input field to provide more context to the user.

Use at least 8 characters, one uppercase, one lowercase and one number.
"use client";

import { Input, Typography } from "@material-tailwind/react";
import { InfoCircle } from "iconoir-react";

export function InputWithHelperText() {
return (
<div className="w-72 space-y-2">
<Input type="password" placeholder="Password" />
<div className="flex gap-1.5 text-foreground">
<InfoCircle className="h-3.5 w-3.5 shrink-0 translate-y-[3px] stroke-2" />
<Typography type="small">
Use at least 8 characters, one uppercase, one lowercase and one
number.
</Typography>
</div>
</div>
);
}
"use client";

import { Input, Typography } from "@material-tailwind/react";
import { InfoCircle } from "iconoir-react";

export function InputWithHelperText() {
return (
<div className="w-72 space-y-2">
<Input type="password" placeholder="Password" />
<div className="flex gap-1.5 text-foreground">
<InfoCircle className="h-3.5 w-3.5 shrink-0 translate-y-[3px] stroke-2" />
<Typography type="small">
Use at least 8 characters, one uppercase, one lowercase and one
number.
</Typography>
</div>
</div>
);
}

Input with Button

You can use Input and Button components together for submitting the input data. In the example below, we've created a subscription form using Input and Button components.

"use client";

import { Button, Input } from "@material-tailwind/react";

export function InputWithButton() {
return (
<form
action="#"
className="flex w-full max-w-sm items-center justify-center gap-2"
>
<Input type="email" placeholder="[email protected]" />
<Button type="submit">Subscribe</Button>
</form>
);
}
"use client";

import { Button, Input } from "@material-tailwind/react";

export function InputWithButton() {
return (
<form
action="#"
className="flex w-full max-w-sm items-center justify-center gap-2"
>
<Input type="email" placeholder="[email protected]" />
<Button type="submit">Subscribe</Button>
</form>
);
}

Input with Dropdown

You can use Input and Menu components together for creating more complex input fields. In the example below, we've created an input with a dropdown for selecting the country code and typing mobile number.

In the example below we've used the use-react-countries library, for getting the countries name, flag and country-code.

"use client";

import * as React from "react";
import { Input, Menu, Button } from "@material-tailwind/react";
import { useCountries } from "use-react-countries";

export function InputWithDropdown() {
const { countries } = useCountries();
const [country, setCountry] = React.useState(0);
const { name, flags, countryCallingCode } = countries[country];

return (
<div className="relative flex w-full max-w-[24rem]">
<Menu placement="bottom-start">
<Menu.Trigger
as={Button}
color="secondary"
className="flex items-center gap-2 rounded-r-none border border-r-0 border-surface bg-secondary pl-3"
>
<img
src={flags.svg}
alt={name}
className="h-4 w-4 rounded-full object-cover"
/>
{countryCallingCode}
</Menu.Trigger>
<Menu.Content className="h-72 max-w-[18rem] overflow-y-auto">
{countries.map(({ name, flags, countryCallingCode }, index) => {
return (
<Menu.Item
key={name}
value={name}
className="flex items-center gap-2"
onClick={() => setCountry(index)}
>
<img
src={flags.svg}
alt={name}
className="h-5 w-5 rounded-full object-cover"
/>
{name} <span className="ml-auto">{countryCallingCode}</span>
</Menu.Item>
);
})}
</Menu.Content>
</Menu>
<Input placeholder="Mobile Number" className="rounded-l-none" />
</div>
);
}
"use client";

import * as React from "react";
import { Input, Menu, Button } from "@material-tailwind/react";
import { useCountries } from "use-react-countries";

export function InputWithDropdown() {
const { countries } = useCountries();
const [country, setCountry] = React.useState(0);
const { name, flags, countryCallingCode } = countries[country];

return (
<div className="relative flex w-full max-w-[24rem]">
<Menu placement="bottom-start">
<Menu.Trigger
as={Button}
color="secondary"
className="flex items-center gap-2 rounded-r-none border border-r-0 border-surface bg-secondary pl-3"
>
<img
src={flags.svg}
alt={name}
className="h-4 w-4 rounded-full object-cover"
/>
{countryCallingCode}
</Menu.Trigger>
<Menu.Content className="h-72 max-w-[18rem] overflow-y-auto">
{countries.map(({ name, flags, countryCallingCode }, index) => {
return (
<Menu.Item
key={name}
value={name}
className="flex items-center gap-2"
onClick={() => setCountry(index)}
>
<img
src={flags.svg}
alt={name}
className="h-5 w-5 rounded-full object-cover"
/>
{name} <span className="ml-auto">{countryCallingCode}</span>
</Menu.Item>
);
})}
</Menu.Content>
</Menu>
<Input placeholder="Mobile Number" className="rounded-l-none" />
</div>
);
}

Input Disabled

You can disable the input by adding the disabled prop. This will prevent the user from interacting with the input field.

"use client";

import { Input } from "@material-tailwind/react";

export function InputDisabled() {
return (
<div className="w-72">
<Input disabled placeholder="Input" />
</div>
);
}
"use client";

import { Input } from "@material-tailwind/react";

export function InputDisabled() {
return (
<div className="w-72">
<Input disabled placeholder="Input" />
</div>
);
}

Input Custom Styles

You can use className prop to customize the Input component style. In the example below, we make a simple input field with an icon and a border to it's bottom.

"use client";

import { Input } from "@material-tailwind/react";
import { ProfileCircle } from "iconoir-react";

export function InputCustomStyles() {
return (
<div className="w-72">
<Input
placeholder="Username"
className="rounded-none border-0 border-b border-gray-400 pr-0.5 shadow-none ring-0 hover:border-gray-900 focus:border-gray-900 data-[icon-placement=start]:!pl-[26px] dark:border-gray-600 dark:hover:border-gray-50 dark:focus:border-gray-50"
>
<Input.Icon className="data-[placement=start]:left-px">
<ProfileCircle className="h-full w-full" />
</Input.Icon>
</Input>
</div>
);
}
"use client";

import { Input } from "@material-tailwind/react";
import { ProfileCircle } from "iconoir-react";

export function InputCustomStyles() {
return (
<div className="w-72">
<Input
placeholder="Username"
className="rounded-none border-0 border-b border-gray-400 pr-0.5 shadow-none ring-0 hover:border-gray-900 focus:border-gray-900 data-[icon-placement=start]:!pl-[26px] dark:border-gray-600 dark:hover:border-gray-50 dark:focus:border-gray-50"
>
<Input.Icon className="data-[placement=start]:left-px">
<ProfileCircle className="h-full w-full" />
</Input.Icon>
</Input>
</div>
);
}