Textarea

Textarea textarea link

Full documentation: https://webawesome.com/docs/components/textarea

<wa-textarea> Stable Since 2.0

Textareas collect multi-line text input from the user, with optional resizing and character counting.

<wa-textarea label="Type somethin', will ya"></wa-textarea>

This component works with standard <form> elements. Please refer to the section on form controls to learn more about form submission and client-side validation.

Examples examples link

Labels labels link

Use the label attribute to give the textarea an accessible label. For labels that contain HTML, use the label slot instead.

<wa-textarea label="Comments"></wa-textarea>

Hint hint link

Add descriptive hint to a textarea with the hint attribute. For hints that contain HTML, use the hint slot instead.

<wa-textarea label="Feedback" hint="Please tell us what you think."> </wa-textarea>

Rows rows link

Use the rows attribute to change the number of text rows that get shown.

<wa-textarea rows="2"></wa-textarea>

Placeholders placeholders link

Use the placeholder attribute to add a placeholder.

<wa-textarea placeholder="Type something"></wa-textarea>

Appearance appearance link

Use the appearance attribute to change the textarea’s visual appearance.

<wa-textarea placeholder="Type something" appearance="filled"></wa-textarea><br />
<wa-textarea placeholder="Type something" appearance="filled-outlined"></wa-textarea><br />
<wa-textarea placeholder="Type something" appearance="outlined"></wa-textarea>

Disabled disabled link

Use the disabled attribute to disable a textarea.

<wa-textarea placeholder="Textarea" disabled></wa-textarea>

Value value link

Use the value attribute to set an initial value.

<wa-textarea value="Write something awesome!"></wa-textarea>

Sizes sizes link

Use the size attribute to change a textarea’s size.

<wa-textarea placeholder="Extra Small" size="xs"></wa-textarea>
<br />
<wa-textarea placeholder="Small" size="s"></wa-textarea>
<br />
<wa-textarea placeholder="Medium" size="m"></wa-textarea>
<br />
<wa-textarea placeholder="Large" size="l"></wa-textarea>
<br />
<wa-textarea placeholder="Extra Large" size="xl"></wa-textarea>

Prevent Resizing prevent resizing link

By default, textareas can be resized vertically by the user. To prevent resizing, set the resize attribute to none.

<wa-textarea resize="none"></wa-textarea>

Expand with Content expand with content link

Textareas will automatically resize to expand to fit their content when resize is set to auto.

<wa-textarea resize="auto"></wa-textarea>

Resize horizontal resize horizontal link

Textareas can be made to resize horizontally when resize is set to "horizontal"

<wa-textarea resize="horizontal"></wa-textarea>

Resize both resize both link

Textareas can be made to resize both vertically and horizontally when resize is set to "both"

<wa-textarea resize="both"></wa-textarea>

Character Count character count link

Add the with-count attribute to show a character count below the textarea. When combined with maxlength, the count shows remaining characters instead. The count is exposed to assistive technologies using a live region so screen readers can announce updates as the user types.

<wa-textarea label="Comments" hint="Share your thoughts with us" with-count></wa-textarea>
<br />
<wa-textarea label="Bio" hint="Tell us a little about yourself" with-count maxlength="100"></wa-textarea>

Importing importing link

If you’re using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.

**CDN**

Import this component directly from the CDN:

import 'https://ka-f.webawesome.com/webawesome@3.7.0/components/textarea/textarea.js';

**npm**

After installing Web Awesome via npm, import this component:

import '@awesome.me/webawesome/dist/components/textarea/textarea.js';

**Self-Hosted**

If you’re self-hosting Web Awesome, import this component from your server:

import './webawesome/dist/components/textarea/textarea.js';

**React**

To import this component for React 18 or below, use the following code:

import WaTextarea from '@awesome.me/webawesome/dist/react/textarea/index.js';

Slots slots link

Learn more about using slots.

Name Description
`hint` `hint` Text that describes how to use the input. Alternatively, you can use the attribute.
`label` `label` The textarea’s . Alternatively, you can use the label attribute.

Attributes & Properties attributes properties link

Learn more about attributes and properties.

Name Description Reflects  
`appearance` appearance `‘filled’ \| ‘outlined’ \| ‘filled-outlined’` The textarea’s visual appearance. Type Default ‘outlined’    
`autocapitalize` autocapitalize `‘off’ \| ‘none’ \| ‘on’ \| ‘sentences’ \| ‘words’ \| ‘characters’` Controls whether and how text input is automatically capitalized as it is entered by the user. Type    
`autocomplete` autocomplete `string` Specifies what permission the browser has to provide assistance in filling out form field values. Refer to this page on MDN for available values. Type    
`autocorrect` autocorrect `“off”` Indicates whether the browser’s autocorrect feature is on or off. When set as an attribute, use or “on”. When set as a property, use true or false. Type boolean    
`autofocus` autofocus `boolean` Indicates that the input should receive focus on page load. Type    
`css` `CSSResultGroup \| undefined` One or more CSSResultGroup to include in the component’s shadow root. Host styles are automatically prepended. Type Default [styles, formControlStyles, sizeStyles, visuallyHidden]    
`defaultValue` value `string` The default value of the form control. Primarily used for resetting the form control. Type    
`disabled` disabled `boolean` Disables the textarea. Type Default false    
`enterkeyhint` enterkeyhint `‘enter’ \| ‘done’ \| ‘go’ \| ‘next’ \| ‘previous’ \| ‘search’ \| ‘send’` Used to customize the label or icon of the Enter key on virtual keyboards. Type    
`form` `    

` By default, form controls are associated with the nearest containing element. This attribute allows you to place the form control outside of a form and associate it with the form that has this id. The form must be in the same document or shadow root for this to work. Type HTMLFormElement \| null | | | | `hint` hint | `hint` The textarea’s . If you need to display HTML, use the hint slot instead. Type string Default ‘’ | | | | `inputmode` inputmode | `‘none’ \| ‘text’ \| ‘decimal’ \| ‘numeric’ \| ‘tel’ \| ‘search’ \| ‘email’ \| ‘url’` Tells the browser what type of data will be entered by the user, allowing it to display the appropriate virtual keyboard on supportive devices. Type | | | | `label` label | `label` The textarea’s . If you need to display HTML, use the label slot instead. Type string Default ‘’ | | | | `maxlength` maxlength | `number` The maximum length of input that will be considered valid. Type | | | | `minlength` minlength | `number` The minimum length of input that will be considered valid. Type | | | | `name` name | `string \| null` The name of the textarea, submitted as a name/value pair with form data. Type Default null | | | | `placeholder` placeholder | `string` Placeholder text to show as a hint when the input is empty. Type Default ‘’ | | | | `readonly` readonly | `boolean` Makes the textarea readonly. Type Default false | | | | `required` required | `boolean` Makes the textarea a required field. Type Default false | | | | `resize` resize | `‘none’ \| ‘vertical’ \| ‘horizontal’ \| ‘both’ \| ‘auto’` Controls how the textarea can be resized. Type Default ‘vertical’ | | | | `rows` rows | `number` The of rows to display by default. Type number Default 4 | | | | `size` size | `‘xs’ \| ‘s’ \| ‘m’ \| ‘l’ \| ‘xl’ \| ‘small’ \| ‘medium’ \| ‘large’` The textarea’s size. Type Default ‘m’ | | | | `spellcheck` spellcheck | `boolean` Enables spell checking on the textarea. Type Default true | | | | `validationTarget` | `undefined \| HTMLElement` Override this to change where constraint validation popups are anchored. Type | | | | `validators` | `observedAttributes` Validators are static because they have , essentially attributes to “watch” for changes. Whenever these attributes change, we want to be notified and update the validator. Type Validator[] Default [] | | | | `value` | The current value of the input, submitted as a name/value pair with form data. | | | | `withCount` with-count | `maxlength` Shows a character count below the textarea. When is set, shows remaining characters instead. Type boolean Default false | | | | `withHint` with-hint | `true` Only required for SSR. Set to if you’re slotting in a hint element so the server-rendered markup includes the hint before the component hydrates on the client. Type boolean Default false | | | | `withLabel` with-label | `true` Only required for SSR. Set to if you’re slotting in a label element so the server-rendered markup includes the label before the component hydrates on the client. Type boolean Default false | | |

Methods methods link

Learn more about methods.

Name Description Arguments
`blur()` Removes focus from the textarea.  
`focus()` Sets focus on the textarea. `options: FocusOptions`
`formStateRestoreCallback()` Called when the browser is trying to restore element’s state to state in which case reason is “restore”, or when the browser is trying to fulfill autofill on behalf of user in which case reason is “autocomplete”. In the case of “restore”, state is a string, File, or FormData object previously set as the second argument to setFormValue. `state: string \| File \| FormData \| null, reason: ‘autocomplete’ \| ‘restore’`
`resetValidity()` Reset validity is a way of removing manual custom errors and native validation.  
`scrollPosition()` Gets or sets the textarea’s scroll position. `position: { top?: number; left?: number }`
`select()` Selects all the text in the textarea.  
`setCustomValidity()` Do not use this when creating a “Validator”. This is intended for end users of components. We track manually defined custom errors so we don’t clear them on accident in our validators. `message: string`
`setRangeText()` Replaces a range of text with a new string. `replacement: string, start: number, end: number, selectMode: ‘select’ \| ‘start’ \| ‘end’ \| ‘preserve’`
`setSelectionRange()` Sets the start and end positions of the text selection (0-based). `selectionStart: number, selectionEnd: number, selectionDirection: ‘forward’ \| ‘backward’ \| ‘none’`

Events events link

Learn more about events.

Name Description
`blur` Emitted when the control loses focus.
`change` Emitted when an alteration to the control’s value is committed by the user.
`focus` Emitted when the control gains focus.
`input` Emitted when the control receives input.
`wa-invalid` Emitted when the form control has been checked for validity and its constraints aren’t satisfied.

Custom States custom states link

Learn more about custom states.

Name Description CSS selector
`blank` The textarea is empty. `:state(blank)`

CSS parts css parts link

Learn more about CSS parts.

Name Description CSS selector
`base` `` The wrapper around the control. `::part(base)`
`count` `with-count` The character count element, rendered when the attribute is present. `::part(count)`
`form-control-input` The input’s wrapper. `::part(form-control-input)`
`hint` The hint’s wrapper. `::part(hint)`
`label` The label `::part(label)`
`textarea` `` The internal control. `::part(textarea)`

Need a hand? Report a bug Ask for help