forms

Tailwind CSS Textarea

A textarea is a multi-line text input field that allows users to enter longer text.

Class Name
Type
Description
form-controlComponentContainer element.
labelComponentFor helper text.
textareaComponentBasic textarea field.
textarea-floatingComponentFloating textarea field.
textarea-filledComponenttextarea with background color and floating label.
textarea-floating-labelComponentFloats the label to the top.
textarea-filled-labelComponentFloats the label at the top.
textarea-filled-focusedComponentAdds animation to the bottom border of a floating filled textarea.
is-validModifierAdds success style to the textarea.
is-invalidModifierAdds error style to the textarea.

Basic textarea example.

Basic textarea with placeholder.

The textarea-floating style is used to define the appearance of the textarea, while the textarea-floating-label is the container for the label text. To handle cases where the content exceeds the initial size, we applied the field-sizing: content; CSS rule, allowing the textarea to expand when the content exceeds the set maximum height of 5rem (m-h-20).

The textarea-filled style is applied to the textarea, with textarea-filled-label for the label and textarea-filled-focused for focus animations. The textarea auto-expands beyond a 5rem max height using field-sizing: content;.

Success state can be show using is-valid class.

Error state can be show using is-invalid class.

label elements hidden using the .sr-only class.

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

Add the readonly boolean attribute on an textarea to prevent modification of the textarea value.

Basic textarea example with helper text and hints.