TextArea Tag in HTML
The
How Tag work in HTML?
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>
Attributes
The
- autofocus: The autofocus attribute ensures that the text area automatically gets the focus when the page loads.
- cols: The ‘cols’ attribute specifies the text area’s width. The value should be a positive integer. If not specified, the default value of ‘cols’ is 20.
- disabled: This feature disables the text area, freezes it, and does not accept user input changes. Disabling the text area will cause the tab key to skip it.
- form: The ‘form’ attribute specifies the form id to which the text area belongs.
- name: It assigns a name to the text control.
- placeholder: This attribute helps the user by providing a hint or a sample text that guides what should be written in the text box.
- readonly: This attribute sets the text area in read-only mode; that is, it is not affected by the user’s input or cannot change its content.
- wrap: This feature specifies how the text area will wrap the text. If not specified, the default value is ‘soft.’
Examples of TextArea Tags in HTML
To understand the work of text area element more, check out the following example that has
Example #1
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.
Example #2
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.
Example #3
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.
Example #4
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.
Conclusion
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.
