---
title: Textarea for Astro
description: "Native Astro multiline fields with shared focus and error styles."
seo:
    title: Textarea for Astro | Shadcn & Tailwind CSS
related:
    - /components/input
    - /components/input-group
sidebar:
    label: "Textarea"
---

```astro
---
import { Label } from "@/components/ui/label"
import { Textarea } from "@/components/ui/textarea"
---

<div class="grid w-full max-w-sm gap-2">
  <Label for="message">Message</Label>
  <Textarea id="message" placeholder="Type your message here..." />
  <Textarea placeholder="Disabled textarea" disabled />
</div>
```

## Installation

### Command

```sh
bunx --bun shadcn@latest add @gnostic/textarea
```

### Manual

Complete the [Installation guide](/docs/installation) first. Then copy the component files below.

No extra packages are required.

#### src/components/ui/textarea/index.ts

```ts
export { default as Textarea } from "./textarea.astro"
```

#### src/components/ui/textarea/textarea.astro

```astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"textarea">

const {
  class: className,
  "data-slot": dataSlot = "textarea",
  ...props
} = Astro.props
---

<textarea data-slot={dataSlot} class={cn("font-sans border-input bg-background text-foreground ring-ring/24 placeholder:text-muted-foreground/72 dark:bg-input/32 focus-visible:border-ring aria-invalid:border-destructive/36 focus-visible:aria-invalid:border-destructive/64 focus-visible:aria-invalid:ring-destructive/16 dark:aria-invalid:ring-destructive/24 field-sizing-content min-h-18 w-full rounded-lg border px-[calc(--spacing(3)-1px)] py-[calc(--spacing(1.5)-1px)] text-base shadow-xs/5 transition-shadow outline-none not-disabled:not-focus-visible:not-aria-invalid:inset-shadow-[0_1px_--theme(--color-black/4%)] focus-visible:shadow-none focus-visible:ring-[3px] disabled:opacity-64 max-sm:min-h-21 sm:text-sm dark:not-disabled:not-focus-visible:not-aria-invalid:inset-shadow-[0_-1px_--theme(--color-white/6%)]", className)} {...props}>
</textarea>
```

Component classes use the preset configured during project setup. Select the same preset in the docs before copying Manual source. To change installed component classes, edit or reinstall their source. See [Theming](/docs/theming) for details.


## Usage

```ts
import { Textarea } from "@/components/ui/textarea"
```

```astro
<Textarea placeholder="Type your message here..." />
```

## Notes

- Use `Textarea` for longer free-form input where multiple lines are expected.
- Set `rows` when you want a clearer default height.
- Pair it with [Field](/components/field) when you need descriptions or
  validation messaging.

## Example

```astro
<Textarea rows={6} placeholder="Write your message..." />
```

## Sizes and states

```astro
---
import { Label } from "@/components/ui/label"
import { Textarea } from "@/components/ui/textarea"
---

<div class="grid w-full max-w-sm gap-3">
  <Label for="review-notes">Review notes</Label>
  <Textarea
    id="review-notes"
    placeholder="What needs to change before handoff?"
  />
  <Label for="required-notes">Required explanation</Label>
  <Textarea
    id="required-notes"
    aria-invalid="true"
    aria-describedby="notes-error"
  />
  <p id="notes-error" class="text-destructive-foreground text-sm">
    Explain why this page cannot be published.
  </p>
  <Label for="locked-notes">Archived notes</Label>
  <Textarea id="locked-notes" disabled>
    This review is closed.
  </Textarea>
</div>
```

## API Reference

Read the [installed source](/r/textarea.json) for the complete prop types.

## When to use Textarea

Use Textarea for messages, notes, and other values that need several lines. Provide a visible label, name, and useful initial height. Put initial text in the default slot as required by native textarea markup.

## Keyboard and behavior

Browser editing, selection, form submission, and disabled behavior remain native. Set `aria-invalid` only with a corresponding explanation. Length limits should be stated before the user reaches them.

## Theme and layout

The single element owns its surface styles and can grow with content according to its CSS. Check resize behavior and long unbroken text. Use classes for width and height rather than importing a React control wrapper.
