forms

Tailwind CSS Input

A fundamental tool for receiving user input is a text field, which allows data to be provided or altered using either the keyboard or mouse.

Class Name
Type
Description
labelComponentContainer class for helper texts.
label-textComponentBase class for title label text.
label-text-altComponentBase class for helper label text.
inputComponentBase class for form input.
input-floatingComponentBase class for floating form input.
input-floating-filledComponentFilled input with floating label.
input-groupComponentAdds inline addons to inputs.
input-group-filledComponentInline addon for filled inputs.
input-group-textComponentContainer that holds the add-ons.
input-floating-labelComponentFloats the label to the top.
input-filled-labelComponentKeeps the label at the top.
input-filled-focusedComponentAdds animation to the bottom border of a filled input.
no-focusModifierremove default focus form input, input-group etc
is-validModifierAdds success style to the input.
is-invalidModifierAdds error style to the input.
input-xsResponsiveInput with Extra small size.
input-smResponsiveInput with Smaller size.
input-lgResponsiveInput with Larger size.

Utilize the input component class to style the input.

Basic input with placeholder.

Use the label and label-text classes for the main label, and label-text-alt for helper text to provide additional guidance. This structure ensures clarity and proper styling with Tailwind CSS.

label elements hidden using the .sr-only class.

Use input with label and label-text classes.

Use relative in the parent div, input-floating and peer for standard inputs and input-floating-label to label for floating inputs.

Each input needs a placeholder for our method, which relies on the :placeholder-shown pseudo-element. Make sure the input comes before the label to use the sibling selector (~).

Use relative in the parent div, input-filled and peer for standard inputs and input-filled-label to label for filled floating inputs.

Each input requires a placeholder for our method, which utilizes the :placeholder-shown pseudo-element. Ensure the input precedes the label to enable sibling selector usage (~). Add input-filled-focused for focus border animation.

Input elements come in three sizes: small, default, and large, which can be applied by adding the classes input-xs, input-sm and input-lg along with the input class.

For the floating label input, specify sizes as default, small, and large.

For the Filled label input, specify sizes as default, small, and large.

Success state can be show using is-valid class.

Error state can be show using is-invalid class.

The input-group component class acts as a container, while the input-group-text can include special characters, icons, keyboard keys, and more.

Add a leading icon inside input.

Instead of using input-group, use input-group-filled to incorporate a leading icon within a filled input.
For border animations, input-filled-focused must be a general sibling to input-group-filled.

Add a trailing icon inside input.

Add a trailing icon inside filled input.

Add a leading and trailing icon inside input.

Utilizes kbd component class with input.

Place any checkbox or radio option within an input group’s addon instead of text.

Use input-group to create an inline select.

We can manage the input’s radius using the rounded utility class provided by Tailwind CSS.

Implement varying input styles accompanied by helper text.

Disable the default focus on the input using no-focus class when necessary.

Helper text can be positioned accordingly as demonstrated below.

Add the disabled boolean attribute on an input to remove pointer events, and prevent focusing.

Add the readonly boolean attribute on an input to prevent modification of the input’s value.

Combine a button with the input field using the join method.

Combine a button with the input input.

Combine a select with the input input.