
# Textarea



> Textarea component allows users to enter text that can span multiple lines, such as a message. For shorter input, use the Input component.

## Examples

### Default

```tsx
import { Textarea } from "@kesko/components";

export default () => <Textarea label="Label" name="message" placeholder="Placeholder" />;

```

```html
<k-textarea>
  <label class="k-label" for="message">Label</label>
  <div class="k-field">
    <textarea id="message" name="message" placeholder="Placeholder"></textarea>
  </div>
</k-textarea>
```

### Assistive text

```tsx
import { Textarea } from "@kesko/components";

export default () => (
  <Textarea
    label="Delivery instructions"
    name="instructions"
    description="Door code, floor, or where to leave the bags."
  />
);

```

```html
<k-textarea>
  <label class="k-label" for="instructions">Delivery instructions</label>
  <div class="k-field">
    <textarea id="instructions" name="instructions" aria-describedby="instructions-description"></textarea>
  </div>
  <div class="k-textarea-footer">
    <p class="k-field-description" id="instructions-description">Door code, floor, or where to leave the bags.</p>
  </div>
</k-textarea>
```

### Character count

```tsx
import { Stack, Textarea } from "@kesko/components";

export default () => (
  <Stack>
    <Textarea label="Review" name="review" counter maxLength={200} defaultValue="Fresh bread, friendly staff." />
    <Textarea label="Notes" name="notes" counter description="Anything the driver should know." />
  </Stack>
);

```

```html
<k-stack>
  <k-textarea counter>
    <label class="k-label" for="review">Review</label>
    <div class="k-field">
      <textarea id="review" name="review" maxlength="200" aria-describedby="review-count">Fresh bread, friendly staff.</textarea>
    </div>
    <div class="k-textarea-footer">
      <span class="k-textarea-count" id="review-count">
        <span aria-hidden="true">28/200</span>
        <k-visually-hidden>28 of 200 characters</k-visually-hidden>
      </span>
    </div>
  </k-textarea>
  <k-textarea counter>
    <label class="k-label" for="notes">Notes</label>
    <div class="k-field">
      <textarea id="notes" name="notes" aria-describedby="notes-description notes-count"></textarea>
    </div>
    <div class="k-textarea-footer">
      <p class="k-field-description" id="notes-description">Anything the driver should know.</p>
      <span class="k-textarea-count" id="notes-count">
        <span aria-hidden="true">0</span>
        <k-visually-hidden>0 characters</k-visually-hidden>
      </span>
    </div>
  </k-textarea>
</k-stack>
<script>
  for (const id of ["review", "notes"]) {
    const textarea = document.getElementById(id);
    const [visible, spoken] = document.getElementById(`${id}-count`).children;
    const update = () => {
      const length = textarea.value.length;
      const limit = textarea.maxLength;
      visible.textContent = limit > 0 ? `${length}/${limit}` : length;
      spoken.textContent = limit > 0 ? `${length} of ${limit} characters` : `${length} characters`;
    };
    update();
    textarea.addEventListener("input", update);
  }
</script>
```

### Custom label style

```tsx
import { Textarea } from "@kesko/components";

const subtle = {
  "--k-label-text": "var(--k-color-text-dim)",
  "--k-label-weight": "var(--k-font-weight-medium)",
  "--k-label-required": "var(--k-color-status-error)",
};

export default () => <Textarea label="Custom label" name="custom" required style={subtle} />;

```

```html
<k-textarea
  style="
    --k-label-text: var(--k-color-text-dim);
    --k-label-weight: var(--k-font-weight-medium);
    --k-label-required: var(--k-color-status-error);"
>
  <label class="k-label" for="custom">Custom label<span class="k-label-required" aria-hidden="true">*</span></label>
  <div class="k-field">
    <textarea id="custom" name="custom" required></textarea>
  </div>
</k-textarea>
```

### Custom size

```tsx
import { Stack, Textarea } from "@kesko/components";

export default () => (
  <Stack direction="row">
    <Textarea
      label="Short note"
      name="note"
      style={{ "--k-textarea-inline-size": "16rem", "--k-textarea-block-size": "6rem" }}
    />
    <Textarea label="Long message" name="long" style={{ "--k-textarea-block-size": "20rem" }} />
  </Stack>
);

```

```html
<k-stack direction="row">
  <k-textarea style="--k-textarea-inline-size: 16rem; --k-textarea-block-size: 6rem;">
    <label class="k-label" for="note">Short note</label>
    <div class="k-field">
      <textarea id="note" name="note"></textarea>
    </div>
  </k-textarea>
  <k-textarea style="--k-textarea-block-size: 20rem;">
    <label class="k-label" for="long">Long message</label>
    <div class="k-field">
      <textarea id="long" name="long"></textarea>
    </div>
  </k-textarea>
</k-stack>
```

### Disabled

```tsx
import { Textarea } from "@kesko/components";

export default () => (
  <Textarea label="Message" name="message" defaultValue="Thanks for the quick delivery!" disabled />
);

```

```html
<k-textarea>
  <label class="k-label" for="message">Message</label>
  <div class="k-field">
    <textarea id="message" name="message" disabled>Thanks for the quick delivery!</textarea>
  </div>
</k-textarea>
```

### Hidden label

```tsx
import { Textarea } from "@kesko/components";

export default () => <Textarea label="Comment" hideLabel name="comment" placeholder="Write a comment" />;

```

```html
<k-textarea>
  <k-visually-hidden><label class="k-label" for="comment">Comment</label></k-visually-hidden>
  <div class="k-field">
    <textarea id="comment" name="comment" placeholder="Write a comment"></textarea>
  </div>
</k-textarea>
```

### Read-only

```tsx
import { Textarea } from "@kesko/components";

export default () => (
  <Textarea
    label="Delivery address"
    name="address"
    defaultValue={"Maija Meikäläinen\nMannerheimintie 1 A 2\n00100 Helsinki"}
    readOnly
  />
);

```

```html
<k-textarea>
  <label class="k-label" for="address">Delivery address</label>
  <div class="k-field">
    <textarea id="address" name="address" readonly>Maija Meikäläinen
Mannerheimintie 1 A 2
00100 Helsinki</textarea>
  </div>
</k-textarea>
```

### Required

```tsx
import { Stack, Textarea } from "@kesko/components";

export default () => (
  <Stack>
    <Textarea label="Reason for return" name="reason" required />
    <Textarea label="Additional details" name="details" required hideRequired />
  </Stack>
);

```

```html
<k-stack>
  <k-textarea>
    <label class="k-label" for="reason">Reason for return<span class="k-label-required" aria-hidden="true">*</span></label>
    <div class="k-field">
      <textarea id="reason" name="reason" required></textarea>
    </div>
  </k-textarea>
  <k-textarea>
    <label class="k-label" for="details">Additional details</label>
    <div class="k-field">
      <textarea id="details" name="details" required></textarea>
    </div>
  </k-textarea>
</k-stack>
```

### Resize

```tsx
import { Stack, Textarea } from "@kesko/components";

export default () => (
  <Stack>
    <Textarea label="Resizable" name="vertical" placeholder="Drag the corner to make room" />
    <Textarea label="Fixed height" name="none" resize="none" placeholder="Stays this size" />
    <Textarea label="Grows with content" name="auto" resize="auto" placeholder="Keeps everything visible" />
  </Stack>
);

```

```html
<k-stack>
  <k-textarea>
    <label class="k-label" for="vertical">Resizable</label>
    <div class="k-field">
      <textarea id="vertical" name="vertical" placeholder="Drag the corner to make room"></textarea>
    </div>
  </k-textarea>
  <k-textarea resize="none">
    <label class="k-label" for="none">Fixed height</label>
    <div class="k-field">
      <textarea id="none" name="none" placeholder="Stays this size"></textarea>
    </div>
  </k-textarea>
  <k-textarea resize="auto">
    <label class="k-label" for="auto">Grows with content</label>
    <div class="k-field">
      <textarea id="auto" name="auto" placeholder="Keeps everything visible"></textarea>
    </div>
  </k-textarea>
</k-stack>
```

### Sizes

```tsx
import { Stack, Textarea } from "@kesko/components";

export default () => (
  <Stack>
    <Textarea label="Large" size="lg" placeholder="Placeholder" />
    <Textarea label="Medium" placeholder="Placeholder" />
  </Stack>
);

```

```html
<k-stack>
  <k-textarea size="lg">
    <label class="k-label" for="large">Large</label>
    <div class="k-field">
      <textarea id="large" placeholder="Placeholder"></textarea>
    </div>
  </k-textarea>
  <k-textarea>
    <label class="k-label" for="medium">Medium</label>
    <div class="k-field">
      <textarea id="medium" placeholder="Placeholder"></textarea>
    </div>
  </k-textarea>
</k-stack>
```

### Validation

```tsx
import { Button, Stack, Textarea } from "@kesko/components";

export default () => (
  <form onSubmit={event => event.preventDefault()}>
    <Stack>
      <Textarea label="Feedback" name="feedback" required placeholder="What went well, what did not?" />
      <Textarea
        label="Review"
        name="review"
        defaultValue="Good"
        minLength={20}
        error="Write at least 20 characters so other customers get the picture."
      />
      <Textarea label="Message" name="message" defaultValue="Thanks for the quick delivery!" success="Message sent." />
      <Button type="submit">Submit</Button>
    </Stack>
  </form>
);

```

```html
<form>
  <k-stack>
    <k-textarea>
      <label class="k-label" for="feedback">Feedback<span class="k-label-required" aria-hidden="true">*</span></label>
      <div class="k-field">
        <textarea id="feedback" name="feedback" required placeholder="What went well, what did not?"></textarea>
      </div>
    </k-textarea>
    <k-textarea>
      <label class="k-label" for="review">Review</label>
      <div class="k-field">
        <textarea id="review" name="review" minlength="20" aria-describedby="review-message" aria-invalid="true">Good</textarea>
      </div>
      <k-field-message variant="error" role="alert"><svg viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M22.113 18.023L13.745 3.08c-.75-1.343-2.738-1.338-3.49 0L1.888 18.023C1.153 19.332 2.13 21 3.633 21h16.735c1.503 0 2.476-1.666 1.745-2.978zM20.367 19.5H3.633a.504.504 0 0 1-.435-.745l8.364-14.94a.506.506 0 0 1 .875 0l8.368 14.942a.501.501 0 0 1-.438.743zm-8.885-5.66l-.31-4.785c0-.115.08-.195.194-.195h1.265c.116 0 .196.08.196.195l-.3 4.613c0 .127-.058.217-.208.242l-.61.102c-.128.023-.217-.035-.23-.172zM13 16.14c0 .552-.403.978-1 .978s-1-.425-1-.978.403-.965 1-.965 1 .425 1 .965z" fill="currentColor" /></svg><span id="review-message">Write at least 20 characters so other customers get the picture.</span></k-field-message>
    </k-textarea>
    <k-textarea success>
      <label class="k-label" for="message">Message</label>
      <div class="k-field">
        <textarea id="message" name="message" aria-describedby="message-message">Thanks for the quick delivery!</textarea>
      </div>
      <k-field-message variant="success" role="status"><svg viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M17.5 8.182a.4.4 0 0 1 .055.563l-5.728 6.98a.748.748 0 0 1-.554.275h-.025a.745.745 0 0 1-.545-.235l-3.725-3.958a.397.397 0 0 1 .017-.564l.51-.48a.397.397 0 0 1 .565.017l3.14 3.338 5.185-6.32a.4.4 0 0 1 .563-.055l.54.445zm2.525-2.14a.396.396 0 0 0-.603-.047l-.505.505a.399.399 0 0 0-.035.52 8.45 8.45 0 0 1 1.62 4.982c0 4.688-3.812 8.5-8.5 8.5S3.5 16.687 3.5 12 7.313 3.5 12 3.5c1.86 0 3.58.602 4.983 1.62.16.117.38.105.52-.035l.505-.505a.4.4 0 0 0-.048-.603A9.945 9.945 0 0 0 12 2.002c-5.515 0-10 4.485-10 10s4.485 10 10 10 10-4.485 10-10c0-2.23-.735-4.292-1.975-5.957z" fill="currentColor" /></svg><span id="message-message">Message sent.</span></k-field-message>
    </k-textarea>
    <button class="k-button" type="submit">Submit</button>
  </k-stack>
</form>
```


## Props

- `label` — `ReactNode` Label for the textarea. Always provide one, even when it is hidden with `hideLabel`.
- `hideLabel` — `boolean` (default: `false`) Hides the label visually while keeping it available to assistive technology.
- `description` — `ReactNode` Assistive text shown below the control, such as what to write.
- `error` — `ReactNode` Optional error message for the textarea, shown instead of the built-in validation message. Also marks the control invalid for assistive technology.
- `success` — `ReactNode` Optional success message for the textarea. Shown only while there is no error. A plain string is also announced to screen readers when it appears.
- `size` — `"md" | "lg"` (default: `"md"`) The size of the textarea.
- `resize` — `"vertical" | "none" | "auto"` (default: `"vertical"`) Controls whether the textarea is resizable. By default it is manually resizable vertically and never shrinks below its default height. Set to `none` to lock the height, or `auto` to grow as content grows.
- `counter` — `boolean` (default: `false`) Shows a count of the characters in the textarea below the control. When combined with `maxLength`, both the count and the limit are shown.
- `name` — `string` The name the value is submitted under.
- `value` — `string` The value of the control. Pair with `onChange` to control the field.
- `defaultValue` — `string` The starting value of an uncontrolled field.
- `form` — `string` The `id` of the form the control submits with. Only needed when the control sits outside that form.
- `placeholder` — `string` Short hint shown while the control is empty. Not a substitute for a label.
- `minLength` — `number` The fewest characters the value may have before the form submits.
- `maxLength` — `number` The most characters the control accepts. Shown next to the count when `counter` is set.
- `wrap` — `"soft" | "off"` How long lines are handled. `soft` wraps them in the box and submits only the line breaks people typed. `off` never wraps, so long lines scroll sideways.
- `required` — `boolean` (default: `false`) Requires a value before the form submits. Draws the marker on the label and is announced to assistive technology.
- `hideRequired` — `boolean` (default: `false`) Hides the required marker on the label while keeping `required` on the control. Use it when the form says once that every field is required.
- `readOnly` — `boolean` Stops the value being edited while keeping the control focusable and its value submitted. Reach for `disabled` to drop it from the form entirely.
- `disabled` — `boolean` Disables the control. Blocks interaction and drops the value from the submitted data.
- `autoComplete` — `string` Tells the browser what the value is for, so it can offer to fill it in.

## Events

- `onChange` — `(event: ChangeEvent<HTMLTextAreaElement>) => void` Handler called as the value changes. Fires on every keystroke.
- `onInput` — `(event: SyntheticEvent<HTMLTextAreaElement>) => void` Handler called on the native `input` event. Fires alongside `onChange`; reach for it only when you need the raw event.
- `onSelect` — `(event: SyntheticEvent<HTMLTextAreaElement>) => void` Handler called when the selected text changes.
- `onFocus` — `(event: FocusEvent<HTMLTextAreaElement>) => void` Handler called when the control receives focus.
- `onBlur` — `(event: FocusEvent<HTMLTextAreaElement>) => void` Handler called when the control loses focus.

## CSS custom properties

- `--k-textarea-bg` (default: `var(--k-color-bg-base)`) Overrides the background color.
- `--k-textarea-text` (default: `var(--k-color-text-base)`) Overrides the text color.
- `--k-textarea-border` (default: `var(--k-color-border-control)`) Overrides the border color in every state.
- `--k-textarea-radius` (default: `var(--k-radius-md)`) Overrides the border radius.
- `--k-textarea-inline-size` (default: `100%`) Overrides the width of the field.
- `--k-textarea-block-size` (default: `calc(5lh + 2 * var(--k-space-md))`) Overrides the default height, which is also the minimum height when resizing. Defaults to about five lines of text.

## Accessibility

Textarea is built on a native `<textarea>` and `<label>`, so it behaves as expected with assistive technologies.

- **Always pass a `label`.** A screen reader reads it as the name, and clicking it focuses the control. If there is no room for it, use `hideLabel` rather than leaving it out.
- **`placeholder` is a hint, not a description.** Don’t put anything people need in order to fill in the field in the placeholder. It disappears as soon as they type. Use `description` for that instead.
- **Say what to write.** Use `description` for what the text is for and how it will be used, and `autoComplete` where the browser can fill it in, such as `street-address`.
- **Leave `resize` on.** The default lets people drag the box taller, which helps anyone reviewing a long answer. Use `resize="none"` only when the layout truly cannot grow, and `resize="auto"` when the all of the content should stay visible.
- **Show the limit, don't just enforce it.** `maxLength` alone cuts the text silently. Pair it with `counter` so the count and the limit are visible and read with the field on focus.
- **Avoid `disabled` for validation.** A disabled control leaves the tab order and cannot explain itself. Keep it enabled and let the message say what is wrong. Use `readOnly` for a value people need to see and copy but not edit.
- **Check contrast if you override colors.** Text needs 4.5:1 against `--k-textarea-bg`, and `--k-textarea-border` needs 3:1 against the surface the field sits on. Verify with the [WebAIM contrast checker](https://webaim.org/resources/contrastchecker/).

See the [accessibility guidelines](/accessibility/) and the [A11Y checklist](/a11y-checklist/) for more details.

## Integration

Install `@kesko/components` together with `@kesko/css`, which provides the design tokens and base styles it depends on, and `@kesko/themes` for your brand:

```sh
npm install @kesko/components @kesko/css @kesko/themes
```

Then load the base stylesheet and one brand theme once, in your app's entry point or root layout. Leave out `@kesko/css/components`: it mirrors the component styles for plain HTML, and `@kesko/components` already ships them.

```tsx
import "@kesko/css";
import "@kesko/themes/dist/k-rauta.css";
```

Finally, import the component into your project:

```tsx
import { Textarea } from "@kesko/components";
```

Projects without React get the same markup and styling from `@kesko/css` by importing the base stylesheet, the `components` add-on and a brand theme, in that order:

```css
@import "@kesko/css";
@import "@kesko/css/components";
@import "@kesko/themes/dist/k-rauta.css";
```

The HTML examples above show the exact markup to copy.

## Resources

- [Usage guidelines](/components/usage/) — Learn how to use the component library with React, Next.js, or basic HTML.
- [Localization](/localization/) — How to translate the components for multiple languages.
- [CSS Framework](/css/) — Utilities and tokens for everything the components don’t cover.
- [Themes](/themes/) — How to customize the component library theme.
- [Accessibility checklist](/a11y-checklist/) — Interactive, browser-based Kesko accessibility checklist.

