Home >Web Front-end >HTML Tutorial >TextArea Tag in HTML
The
A textarea element creates an area or space specified using attributes like cols, rows, or both. CSS styling and height and width properties can format the look and feel.
Syntax:
<textarea rows="3" cols="20"> Enter your text here... </textarea>
The
To understand the work of text area element more, check out the following example that has
Code:
<form> <p>Leave your Comment:</p> <br /> <textarea id="ta" cols="60" rows="5"> Write Here...</textarea></form>
Output:
The above example is simple, demonstrating features of
The rows and cols allow the programmer to set the boundary values for the size of the text area, the exact space the text area will acquire. Using these attributes helps in cross-browser support and format consistency since browser defaults can be different.
Code:
<!DOCTYPE html> <html> <head> <title> Textarea HTML Tag Demo </title> </head> <body> <form> <p>Fill the Detail:</p> <br /> <textarea rows="5" cols="40" name="demo" maxlength="60" minlength="10" required="required">Enter your name</textarea> <br /> <input type="submit" name="Submit" value="Submit" /> </form> </body> </html>
Output:
The above example shows another set of properties used alongside
The max length attribute was added in HTML5; HTML did not support this attribute. The text area requires a minimum of 10 characters as set by the ‘minlength’ property. The ‘required’ attribute indicates that the user must not leave the text area blank to be considered valid and submitted. It’s a simple validation for the tag.
Code:
<form id="Form1"> <label>Textarea Box 1</label> <br /> <textarea rows="5" cols="40" name="demo" maxlength="60" minlength="10" disabled="disabled"> This is Disabled</textarea> <br /> <label>Textarea Box 2</label> <br /> <textarea rows="5" cols="40" required="required"></textarea> <br /> <label>Textarea Box 3</label> <br /> <textarea rows="5" cols="40" placeholder="This is readonly textarea" readonly="readonly"></textarea> <br /> <input type="submit" name="Submit" value="Submit" /> </form>
Output:
Observe that the ‘Textarea Box 2’ text area is a required text area, whereas the ‘Textarea Box 1’ is disabled.
Code:
<form id="label2" action="textareaDemo.html"> <fieldset> <legend><b>Form 2</b></legend> <input type="text" name="FN" value="Name" /> <br /> <input type="submit" name="Submit" value="Submit" /> <br /> </fieldset> </form> <textarea rows="5" cols="40" form="label2" required="required"></textarea> <br /> <p>Above Text Area belongs to 'Form 2'</p>
Output:
Note the output below. The textarea box below is a ‘required’ field, and as mentioned in the code above, this field is associated with the form ‘Form 2’. Thus when we try to submit the form with an empty text area, it shows an alert.
The
The above is the detailed content of TextArea Tag in HTML. For more information, please follow other related articles on the PHP Chinese website!