Textarea

Textarea

Multi-line text input field for capturing longer user input with support for labels and validation.

12345678910111213
package showcase import ( popui "github.com/invopop/popui/go" "github.com/invopop/popui/go/props" ) templ TextareaDefault() { @popui.Textarea(props.Textarea{ Placeholder: "Enter your message...", Rows: 4, }) }

With Label

Use the Label prop for a simple text label above the textarea.

12345678910111213141516
package showcase import ( popui "github.com/invopop/popui/go" "github.com/invopop/popui/go/props" ) templ TextareaWithLabel() { @popui.Textarea(props.Textarea{ ID: "bio", Name: "bio", Label: "Biography", Placeholder: "Tell us about yourself...", Rows: 6, }) }

Custom Label

For advanced label features like hints, render a Label component separately with proper spacing using a flex container.

1234567891011121314151617181920
package showcase import ( popui "github.com/invopop/popui/go" "github.com/invopop/popui/go/props" ) templ TextareaCustomLabel() { <div class="flex flex-col gap-2"> @popui.Label(props.Label{ID: "comments", Hint: "Share your thoughts in detail"}) { Comments } @popui.Textarea(props.Textarea{ ID: "comments", Name: "comments", Placeholder: "Enter your comments...", Rows: 5, }) </div> }

Disabled & Read-only

Textarea can be disabled to prevent interaction or set to read-only to prevent editing.

1234567891011121314
package showcase import ( popui "github.com/invopop/popui/go" "github.com/invopop/popui/go/props" ) templ TextareaDisabled() { @popui.Textarea(props.Textarea{ Value: "This textarea is disabled and cannot be edited.", Disabled: true, Rows: 3, }) }

With Error

Textarea can display error messages for validation feedback.

Message must be at least 10 characters long

1234567891011121314151617181920
package showcase import ( "errors" popui "github.com/invopop/popui/go" "github.com/invopop/popui/go/props" ) templ TextareaWithError() { @popui.Textarea(props.Textarea{ ID: "message", Name: "message", Label: "Message", Placeholder: "Enter your message...", Rows: 4, Error: props.Error{ Error: errors.New("Message must be at least 10 characters long"), }, }) }

Monospaced Font

Use the Class prop with font-mono for code or monospaced text display.

123456789101112131415
package showcase import ( popui "github.com/invopop/popui/go" "github.com/invopop/popui/go/props" ) templ TextareaMonospaced() { @popui.Textarea(props.Textarea{ Label: "Code Snippet", Class: "font-mono", Placeholder: "Enter code here...", Rows: 6, }) }

Contenteditable

Use Contenteditable for rich text editing with a div element instead of a textarea. It renders as a contenteditable div that can display formatted content.

This is a contenteditable div. You can use formatted text and it will render properly.
123456789101112131415161718192021
package showcase import ( popui "github.com/invopop/popui/go" "github.com/invopop/popui/go/props" ) templ TextareaContenteditable() { <div class="space-y-4"> @popui.Textarea(props.Textarea{ Label: "Standard Textarea", Value: "This is plain text in a textarea element. HTML tags like <strong>bold</strong> are displayed as text.", Rows: 3, }) @popui.Contenteditable(props.Textarea{ Label: "Contenteditable Div", Value: "This is a contenteditable div. You can use <strong>formatted</strong> <em>text</em> and it will render properly.", Rows: 3, }) </div> }

API Reference

Textarea

Multi-line text input field with support for labels and validation.

NameTypeDefaultDescription
ID string-Unique identifier for the textarea element
Class string-Additional CSS classes to merge with textarea styles
Attributes templ.Attributes-Additional HTML attributes (data-*, aria-*, etc.)
Name string-Name attribute for form submission
Placeholder string-Placeholder text displayed when textarea is empty
Value string-Initial or current value of the textarea
Label string-Simple label text displayed above the textarea
Rows int4Number of visible text rows
Disabled boolfalseDisables the textarea
Readonly boolfalseMakes the textarea read-only
Required boolfalseMarks the textarea as required for form validation
Autofocus boolfalseAutomatically focuses the textarea on page load
Error props.Error-Error configuration to display validation feedback below the textarea

Error

Error configuration for displaying validation feedback.

NameTypeDefaultDescription
Error error-Go error object to display (calls .Error() method)
Text string-Text string to display as error message
Class string-Additional CSS classes to merge with error styles
Attributes templ.Attributes-Additional HTML attributes for the error element