Learn to code in weeks, not months

Get CodeFast

Reusable React Input Component with Tailwind CSS (Icon, Label & Error)

When building forms in React, an input component is one of the most essential UI elements. A well-designed input field improves user experience and ensures validation. This guide provides a reusable input component styled with Tailwind CSS, offering multiple styles:

  • With Error Handling – Displays validation errors.
  • Outlined Style – A modern input with a border.
  • Filled Style – A clean, minimal look with a background fill.

This component supports props like icon, label, and error, making it highly customizable for various use cases.

Input Component Props

The input component is built with TypeScript and includes the following props:

1interface InputProps { 2 type: 'text' | 'number' | 'email' | 'password' 3 label?: string 4 value: string | number 5 name: string 6 placeholder: string 7 error?: string 8 disabled?: boolean 9 icon?: React.ReactNode 10 onChange: (e: ChangeEvent<HTMLInputElement>) => void 11}

Features

Supports multiple input typestext, email, number, and password.

Optional label & placeholder – Helps users understand what to enter.

Error Handling – Displays a validation message.

Optional Icon Support – Adds an icon inside the input.

Disabled State – Prevents input when needed.

Tailwind CSS Input with Error

This is how the component looks with and without error:

React Tailwind with Error and Label

Code Implementation

If you want to learn how to build input component step by step, read the React reusable input component tutorial.

Tailwind CSS Outlined Input

Visual Characteristics

  • Transparent background
  • Defined border
  • Optional left icon

tailwind css input component with icon

Code Implementation

Tailwind CSS Filled Input

Visual Characteristics

  • Solid background (#F6F5F5)
  • Borderless design
  • Subtle focus states

tailwind css filled input style

Code Implementation

React Input Component API

PropTypeRequiredDefaultDescription
type'text' | 'number' | 'email' | 'password'Yes'email'Defines the type of input field.
labelstringNo'Email'Displays a label above the input field.
valuestring | numberYes''Holds the current value of the input field.
namestringYes'email'Specifies the name attribute of the input field.
placeholderstringNo'Please enter your email'Text displayed inside the input as a placeholder.
errorstringNo'Please enter a valid email.'Displays an error message if input validation fails.
disabledbooleanNofalseDisables the input field when set to true.
onChange(e: ChangeEvent<HTMLInputElement>) => voidYesundefinedFunction triggered when input value changes.
iconReact.ReactNodeNo<Mail size={20} />Icon displayed inside the input field.

Input Component Use Cases

  1. Login & Signup Forms – Collect user emails, passwords, etc.
  2. Search Bars – Add an icon for a better UI experience.
  3. User Profile Forms – Input fields for updating user information.
  4. E-commerce Checkout – Collect user details like name, email, and phone number.

Don't forget to let me know if it helps you.


Flexy UI Newsletter

Build better and faster UIs.Get the latest Tailwind UI components directly in your inbox. No spam!