# Input **Category**: react **URL**: https://www.heroui.com/docs/react/components/input **Source**: https://raw.githubusercontent.com/heroui-inc/heroui/refs/heads/v3/apps/docs/content/docs/react/components/(forms)/input.mdx > Primitive single-line text input component that accepts standard HTML attributes *** ## Import ```tsx import { Input } from '@heroui/react'; ``` For validation, labels, and error messages, see **[TextField](/docs/components/text-field)**. ### Usage ```tsx import {Input} from "@heroui/react"; export function Basic() { return ; } ``` ### Input Types ```tsx import {Input, Label} from "@heroui/react"; export function Types() { return (
); } ``` ### Controlled ```tsx "use client"; import {Input} from "@heroui/react"; import React from "react"; export function Controlled() { const [value, setValue] = React.useState("heroui.com"); return (
setValue(event.target.value)} /> https://{value || "your-domain"}
); } ``` ### Full Width ```tsx import {Input} from "@heroui/react"; export function FullWidth() { return (
); } ``` ### Variants The Input component supports two visual variants: - **`primary`** (default) - Standard styling with shadow, suitable for most use cases - **`secondary`** - Lower emphasis variant without shadow, suitable for use in Surface components ```tsx import {Input} from "@heroui/react"; export function Variants() { return (
); } ``` ### In Surface When used inside a [Surface](/docs/components/surface) component, use `variant="secondary"` to apply the lower emphasis variant suitable for surface backgrounds. ```tsx import {Input, Surface} from "@heroui/react"; export function OnSurface() { return ( ); } ``` ## Related Components - **TextField**: Composition-friendly fields with labels and validation - **TextArea**: Multiline text input with focus management - **Label**: Accessible label for form controls ## Styling ### Passing Tailwind CSS classes ```tsx import {Input, Label} from '@heroui/react'; function CustomInput() { return (
); } ``` ### Customizing the component classes The base class `.input` powers every instance. Override it once with `@layer components`. ```css @layer components { .input { @apply rounded-lg border border-border bgsurface px-4 py-2 text-sm shadow-sm transition-colors; &:hover, &[data-hovered="true"] { @apply bg-surface-secondary border-border/80; } &:focus-visible, &[data-focus-visible="true"] { @apply border-primary ring-2 ring-primary/20; } &[data-invalid="true"] { @apply border-danger bg-danger-50/10 text-danger; } } } ``` ### CSS Classes - `.input` – Native input element styling ### Interactive States - **Hover**: `:hover` or `[data-hovered="true"]` - **Focus Visible**: `:focus-visible` or `[data-focus-visible="true"]` - **Invalid**: `[data-invalid="true"]` (also syncs with `aria-invalid`) - **Disabled**: `:disabled` or `[aria-disabled="true"]` - **Read Only**: `[aria-readonly="true"]` ## API Reference ### Input Props Input accepts all standard HTML `` attributes plus the following: | Prop | Type | Default | Description | |------|------|---------|-------------| | `className` | `string` | - | Tailwind classes merged with the component styles. | | `type` | `string` | `"text"` | Input type (text, email, password, number, etc.). | | `value` | `string` | - | Controlled value. | | `defaultValue` | `string` | - | Uncontrolled initial value. | | `onChange` | `(event: React.ChangeEvent) => void` | - | Change handler. | | `placeholder` | `string` | - | Placeholder text. | | `disabled` | `boolean` | `false` | Disables the input. | | `readOnly` | `boolean` | `false` | Makes the input read-only. | | `required` | `boolean` | `false` | Marks the input as required. | | `name` | `string` | - | Name for form submission. | | `autoComplete` | `string` | - | Autocomplete hint for the browser. | | `maxLength` | `number` | - | Maximum number of characters. | | `minLength` | `number` | - | Minimum number of characters. | | `pattern` | `string` | - | Regex pattern for validation. | | `min` | `number \| string` | - | Minimum value (for number/date inputs). | | `max` | `number \| string` | - | Maximum value (for number/date inputs). | | `step` | `number \| string` | - | Stepping interval (for number inputs). | | `fullWidth` | `boolean` | `false` | Whether the input should take full width of its container | | `variant` | `"primary" \| "secondary"` | `"primary"` | Visual variant of the component. `primary` is the default style with shadow. `secondary` is a lower emphasis variant without shadow, suitable for use in surfaces. | > For validation props like `isInvalid`, `isRequired`, and error handling, use **[TextField](/docs/components/text-field)** with Input as a child component.