ProComponents, templates & AI tooling
HeroUI
27.7k

Input

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

Usage

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

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

Examples

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

In Surface

When used inside a Surface component, use variant="secondary" to apply the lower emphasis variant suitable for surface backgrounds.

Full Width

Input Types

Controlled

Customization

Tailwind CSS

Global CSS

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

@layer components {
  .input {
    @apply rounded-lg border border-border bg-surface 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-accent ring-2 ring-accent/20;
    }

    &[data-invalid="true"] {
      @apply border-danger bg-danger-soft text-danger;
    }
  }
}

Styling Reference

HeroUI follows the BEM methodology to ensure component variants and states are reusable and easy to customize.

CSS Classes

Base 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

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).
fullWidthbooleanfalseWhether 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 with Input as a child component.

On this page