This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
* Some parts of this feature may have varying levels of support.
The HTMLTextAreaElement interface provides properties and methods for manipulating the layout and presentation of <textarea> elements.
Also inherits properties from its parent interface, HTMLElement.
autocompleteA string that represents the element's autocomplete attribute.
colsA number that represents the element's cols attribute, indicating the visible width of the text area.
defaultValueA string that represents the control's default value, which behaves like the Node.textContent property.
dirNameA string that represents the directionality of the element.
disabledA boolean that represents the element's disabled attribute, indicating that the control is not available for interaction.
form Read only
Returns a reference to the parent form element. If this element is not contained in a form element, it can be the id attribute of any <form> element in the same document or the value null.
labels Read only
Returns a NodeList of the <label> elements associated with this element.
maxLengthA number that represents the element's maxlength attribute, indicating the maximum number of characters the user can enter. This constraint is evaluated only when the value changes.
minLengthA number that represents the element's minlength attribute, indicating the minimum number of characters the user can enter. This constraint is evaluated only when the value changes.
nameA string that represents the element's name attribute, containing the name of the control.
placeholderA string that represents the element's placeholder attribute, containing a hint to the user about what to enter in the control.
readOnlyA boolean that represents the element's readonly attribute, indicating that the user cannot modify the value of the control.
requiredA boolean that represents the element's required attribute, indicating that the user must specify a value before submitting the form.
rowsA number that represents the element's rows attribute, indicating the number of visible text lines for the control.
selectionDirectionA string that represents the direction in which selection occurred. This is forward if selection was performed in the start-to-end direction of the current locale, or backward for the opposite direction. This can also be none if the direction is unknown.
selectionEndA number that represents the index of the end of selected text. If no text is selected, it contains the index of the character that follows the input cursor. On being set, the control behaves as if setSelectionRange() had been called with this as the second argument, and selectionStart as the first argument.
selectionStartA number that represents the index of the beginning of selected text. If no text is selected, it contains the index of the character that follows the input cursor. On being set, the control behaves as if setSelectionRange() had been called with this as the first argument and selectionEnd as the second argument.
textLength Read only
Returns the code point length of the control's value. Same as reading value.length.
type Read only
Returns the string textarea.
validationMessage Read only
Returns a localized message that describes the validation constraints that the control does not satisfy (if any). This is the empty string if the control is not a candidate for constraint validation (willValidate is false), or it satisfies its constraints.
validity Read only
Returns the validity state that this element is in.
valueA string that represents the raw value contained in the control.
willValidate Read only
Returns whether the element is a candidate for constraint validation. false if any conditions bar it from constraint validation, including its readOnly or disabled property is true.
wrapA string that represents the element's wrap attribute, indicating how the control wraps text.
Also inherits methods from its parent interface, HTMLElement.
checkValidity()Returns false if the element is a candidate for constraint validation, and it does not satisfy its constraints. In this case, it also fires a cancelable invalid event at the control. It returns true if the control is not a candidate for constraint validation, or if it satisfies its constraints.
reportValidity()This method reports the problems with the constraints on the element, if any, to the user. If there are problems, it fires a cancelable invalid event at the element, and returns false; if there are no problems, it returns true.
select()Selects the contents of the control.
setCustomValidity()Sets a custom validity message for the element. If this message is not the empty string, then the element is suffering from a custom validity error, and does not validate.
setRangeText()Replaces a range of text in the element with new text.
setSelectionRange()Selects a range of text in the element (but does not focus it).
Also inherits events from its parent interface, HTMLElement.
Listen to these events using addEventListener() or by assigning an event listener to the oneventname property of this interface:
select eventFires when some text has been selected.
selectionchange eventFires when the text selection in a <textarea> element has been changed.
Make a textarea autogrow while typing:
function autoGrow(field) {
if (field.scrollHeight > field.clientHeight) {
field.style.height = `${field.scrollHeight}px`;
}
}
document.querySelector("textarea").addEventListener("keyup", (e) => {
autoGrow(e.target);
});
textarea.no-scrollbars {
overflow: hidden;
width: 300px;
height: 100px;
}
<form>
<fieldset>
<legend>Your comments</legend>
<p><textarea class="no-scrollbars"></textarea></p>
<p><input type="submit" value="Send" /></p>
</fieldset>
</form>
Insert some HTML tags in a textarea:
function insert(startTag, endTag) {
const textArea = document.myForm.myTextArea;
const start = textArea.selectionStart;
const end = textArea.selectionEnd;
const oldText = textArea.value;
const prefix = oldText.substring(0, start);
const inserted = startTag + oldText.substring(start, end) + endTag;
const suffix = oldText.substring(end);
textArea.value = `${prefix}${inserted}${suffix}`;
const newStart = start + startTag.length;
const newEnd = end + startTag.length;
textArea.setSelectionRange(newStart, newEnd);
textArea.focus();
}
function insertURL() {
const newURL = prompt("Enter the full URL for the link");
if (newURL) {
insert(`<a href="${newURL}">`, "</a>");
} else {
document.myForm.myTextArea.focus();
}
}
const strong = document.querySelector("#format-strong");
const em = document.querySelector("#format-em");
const link = document.querySelector("#format-link");
const code = document.querySelector("#format-code");
strong.addEventListener("click", (e) => insert("<strong>", "</strong>"));
em.addEventListener("click", (e) => insert("<em>", "</em>"));
link.addEventListener("click", (e) => insertURL());
code.addEventListener("click", (e) => insert("<code>", "</code>"));
Decorate the span to behave like a link:
.intLink {
cursor: pointer;
text-decoration: underline;
color: blue;
}
<form name="myForm">
<p>
[
<span class="intLink" id="format-strong"><strong>Bold</strong></span> |
<span class="intLink" id="format-em"><em>Italic</em></span> |
<span class="intLink" id="format-link">URL</span> |
<span class="intLink" id="format-code">code</span> ]
</p>
<p>
<textarea name="myTextArea" rows="10" cols="50">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut facilisis, arcu vitae adipiscing placerat, nisl lectus accumsan nisi, vitae iaculis sem neque vel lectus. Praesent tristique commodo lorem quis fringilla. Sed ac tellus eros.
</textarea>
</p>
</form>
| Specification |
|---|
| HTML> # htmltextareaelement> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
HTMLTextAreaElement |
1 | 12 | 1 | 8 | 1 | 18 | 4 | 10.1 | 1 | 1.0 | 3 | 1 |
autocomplete |
66 | 79 | 59 | 53 | 9.1 | 66 | 59 | 47 | 9.3 | 9.0 | 66 | 9.3 |
checkValidity |
4 | 12 | 4 | ≤12.1 | 5 | 18 | 4 | ≤12.1 | 5 | 1.0 | 4.4 | 5 |
cols |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
defaultValue |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
dirName |
17 | 79 | 116 | ≤12.1 | 6 | 18 | 116 | ≤12.1 | 6 | 1.0 | 4.4 | 6 |
disabled |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
form |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
labels |
6 | 18 | 56 | ≤12.1 | 5.1 | 18 | 56 | ≤12.1 | 5 | 1.0 | 3 | 5 |
maxLength |
4 | 12 | 4 | ≤12.1 | 5 | 18 | 4 | ≤12.1 | 5 | 1.0 | 4.4 | 5 |
minLength |
40 | 17 | 51 | 27 | 10.1 | 40 | 51 | 27 | 10.3 | 4.0 | 40 | 10.3 |
name |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
placeholder |
4 | 12 | 4 | ≤12.1 | 5 | 18 | 4 | ≤12.1 | 5 | 1.0 | 4.4 | 5 |
readOnly |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
reportValidity |
40 | 17 | 49 | 27 | 10.1 | 40 | 64 | 27 | 10.3 | 4.0 | 40 | 10.3 |
required |
4 | 12 | 4 | ≤12.1 | 5 | 18 | 4 | ≤12.1 | 5 | 1.0 | 4.4 | 5 |
rows |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
select |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
select_event |
1 | 12 | 6 | ≤12.1 | 1 | 18 | 6 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
selectionDirection |
15 | 79 | 8 | ≤12.1 | 6 | 18 | 8 | ≤12.1 | 6 | 1.0 | 4.4 | 6 |
selectionEnd |
1 | 12 | 1 | ≤12.1 | 1.3 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
selectionStart |
1 | 12 | 1 | ≤12.1 | 1.3 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
selectionchange_event |
127Before Chrome 127, aselectionchange event was fired on Document, see Document's selectionchange event. See bug 40840956 for firing the event on <textarea> elements. |
127Before Edge 127, aselectionchange event was fired on Document, see Document's selectionchange event. See bug 40840956 for firing the event on <textarea> elements. |
92 | 113Before Opera 113, aselectionchange event was fired on Document, see Document's selectionchange event. See bug 40840956 for firing the event on <textarea> elements. |
18Before Safari 18, aselectionchange event was fired on Document, see Document's selectionchange event. See bug 271033 for firing the event on <textarea> elements. |
127Before Chrome Android 127, aselectionchange event was fired on Document, see Document's selectionchange event. See bug 40840956 for firing the event on <textarea> elements. |
92 | 84Before Opera Android 84, aselectionchange event was fired on Document, see Document's selectionchange event. See bug 40840956 for firing the event on <textarea> elements. |
18Before Safari on iOS 18, aselectionchange event was fired on Document, see Document's selectionchange event. See bug 271033 for firing the event on <textarea> elements. |
28.0Before Samsung Internet 28.0, aselectionchange event was fired on Document, see Document's selectionchange event. See bug 40840956 for firing the event on <textarea> elements. |
127Before WebView Android 127, aselectionchange event was fired on Document, see Document's selectionchange event. See bug 40840956 for firing the event on <textarea> elements. |
18Before WebView on iOS 18, aselectionchange event was fired on Document, see Document's selectionchange event. See bug 271033 for firing the event on <textarea> elements. |
setCustomValidity |
4This method only updates the validation error popup, not the tooltip that appears when hovering the mouse over the element, see bug 41380670. |
12 | 4 | ≤12.1 | 5 | 18This method only updates the validation error popup, not the tooltip that appears when hovering the mouse over the element, see bug 41380670. |
4 | ≤12.1 | 5 | 1.0This method only updates the validation error popup, not the tooltip that appears when hovering the mouse over the element, see bug 41380670. |
4.4This method only updates the validation error popup, not the tooltip that appears when hovering the mouse over the element, see bug 41380670. |
5 |
setRangeText |
24 | 79 | 27 | 15 | 7 | 25 | 27 | 14 | 7 | 1.5 | 4.4 | 7 |
setSelectionRange |
1 | 12 | 1 | ≤12.1 | 1.3 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
textLength |
4 | 17 | 1 | ≤12.1 | 5 | 18 | 4 | ≤12.1 | 4 | 1.0 | 4.4 | 4 |
type |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
validationMessage |
5 | 12 | 4 | ≤12.1 | 5 | 18 | 4 | ≤12.1 | 5 | 1.0 | 4.4 | 5 |
validity |
4 | 12 | 4 | ≤12.1 | 5 | 18 | 4 | ≤12.1 | 5 | 1.0 | 4.4 | 5 |
value |
1 | 12 | 1 | ≤12.1 | 1 | 18 | 4 | ≤12.1 | 1 | 1.0 | 4.4 | 1 |
willValidate |
2 | 12 | 4 | ≤12.1 | 4 | 18 | 4 | ≤12.1 | 3.2 | 1.0 | 4.4 | 3.2 |
wrap |
16 | 12 | 4 | ≤12.1 | 6 | 18 | 4 | ≤12.1 | 6 | 1.0 | 4.4 | 6 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLTextAreaElement