Input

Primitive single-line text input component that accepts standard HTML attributes

Import

import { Input } from '@heroui/react';

For validation, labels, and error messages, see TextField.

Usage

"use client";

import {Input} from "@heroui/react";

export function Basic() {
  return <Input aria-label="Name" className="w-64" placeholder="Enter your name" />;
}

Input Types

"use client";

import {Input, Label} from "@heroui/react";

export function Types() {
  return (
    <div className="flex w-80 flex-col gap-4">
      <div className="flex flex-col gap-1">
        <Label htmlFor="input-type-email">Email</Label>
        <Input id="input-type-email" placeholder="jane@example.com" type="email" />
      </div>
      <div className="flex flex-col gap-1">
        <Label htmlFor="input-type-number">Age</Label>
        <Input id="input-type-number" min={0} placeholder="30" type="number" />
      </div>
      <div className="flex flex-col gap-1">
        <Label htmlFor="input-type-password">Password</Label>
        <Input id="input-type-password" placeholder="••••••••" type="password" />
      </div>
    </div>
  );
}

Controlled

https://heroui.com
"use client";

import {Input} from "@heroui/react";
import React from "react";

export function Controlled() {
  const [value, setValue] = React.useState("heroui.com");

  return (
    <div className="flex w-80 flex-col gap-2">
      <Input
        aria-label="Domain"
        placeholder="domain"
        value={value}
        onChange={(event) => setValue(event.target.value)}
      />
      <span className="text-muted px-1 text-sm">https://{value || "your-domain"}</span>
    </div>
  );
}

Styling

Passing Tailwind CSS classes

import {Input, Label} from '@heroui/react';

function CustomInput() {
  return (
    <div className="flex flex-col gap-2">
      <Label htmlFor="custom-input">Project name</Label>
      <Input
        id="custom-input"
        className="rounded-xl border border-border/70 bg-surface-2 px-4 py-2 text-sm shadow-sm focus-visible:border-primary"
        placeholder="New web app"
      />
    </div>
  );
}

Customizing the component classes

The base class .input powers every instance. Override it once with @layer components.

@layer components {
  .input {
    @apply rounded-lg border border-border bg-surface-2 px-4 py-2 text-sm shadow-sm transition-colors;

    &:hover,
    &[data-hovered="true"] {
      @apply bg-surface-3 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 <input> attributes plus the following:

PropTypeDefaultDescription
classNamestring-Tailwind classes merged with the component styles.
typestring"text"Input type (text, email, password, number, etc.).
valuestring-Controlled value.
defaultValuestring-Uncontrolled initial value.
onChange(event: React.ChangeEvent<HTMLInputElement>) => void-Change handler.
placeholderstring-Placeholder text.
disabledbooleanfalseDisables the input.
readOnlybooleanfalseMakes the input read-only.
requiredbooleanfalseMarks the input as required.
namestring-Name for form submission.
autoCompletestring-Autocomplete hint for the browser.
maxLengthnumber-Maximum number of characters.
minLengthnumber-Minimum number of characters.
patternstring-Regex pattern for validation.
minnumber | string-Minimum value (for number/date inputs).
maxnumber | string-Maximum value (for number/date inputs).
stepnumber | string-Stepping interval (for number inputs).

For validation props like isInvalid, isRequired, and error handling, use TextField with Input as a child component.