<textarea> tag in HTML
The <textarea> tag is used to represent a input field to get single or multipe line of texts.
Example 2 - Assign default value
Attribute of <textarea> tag
cols attribute for <textarea> tag
cols attribute is used to assign the width of the textarea.
The value provided in this attribute should be an integer greater than zero.
If the value is absent or incorrect, the attribute will take the default value 20.
rows attribute for <textarea> tag
rows attribute is used to assign the height of the textarea.
It denotes the number of lines the textarea should display by default.
If the text inside this control has more lines than the specified by this attribute, browsers will provide a vertical scrollbar to access the hidden content.
Its default size is 2.
maxlength attribute for <textarea> tag
maxlength attribute is used to set the maximum length of the characters the textarea can hold.
In the below example you cannot enter more than 5 characters.
placeholder attribute for <textarea> tag
It contains text that provide a hint about what type of input to be given in the textarea.
Browsers will display the value of placeholder attribute in the textarea control by default.
As soon as users start to write down their own text, the placeholder text disappear from the control.
readonly attribute for <textarea> tag
readonly attribute has a boolean value instructing the browser to allow or prevent the user from changing the textareas value.
disabled attribute for <textarea> tag
disabled attribute contains a boolean value indicating whether the textarea is to be disabled or not.
disabled controls are rendered grayed out, and blocked from user interaction.
spellcheck attribute for <textarea> tag
spellcheck attribute checks for spelling errors when the user types the text, if an error occurs the text is indicated with red mark.
In the below example click the textarea box, you can see the red indication below the error text.
autofocus attribute for <textarea> tag
autofocus attribute contains a boolean value instructing the browser to set the focus to this control when the document has finished loading.
Only one HTML control can have autofocus attribute set as true in the whole web page.
In the below example there are many html controller, but autofocus attribute is set for the textarea only. So the textarea control will be automatically focused.
required attribute for <textarea> tag
required attribute contains a boolean value indicating whether the given control can be left empty or not.
require attribute can not able to validate the value without form tag.
minlength attribute for <textarea> tag
minlength attribute indicates the minimum number of characters the value of the control can have.