Skip to main content

Textarea Element (Live Playground)

In this tutorial, we will discuss the textarea element in HTML forms. The textarea element is used to create a multi-line text input field that allows users to enter larger amounts of text, such as comments or descriptions.

Creating a Textarea​

To create a textarea, simply use the <textarea> tag and provide a name attribute. The name attribute is essential for sending the entered text to the server when the form is submitted.

HTML
<label for="message">Your Message:</label> <textarea id="message" name="message"></textarea>
Live Playground, Try it Yourself

Setting Rows and Columns​

By default, a textarea element will have a width and height determined by the browser. You can, however, define the number of visible rows and columns using the rows and cols attributes, respectively.

HTML
<textarea id="message" name="message" rows="5" cols="40"></textarea>

In this example, we have set the textarea to display 5 rows and 40 columns.

Live Playground, Try it Yourself

Placeholder Text​

The placeholder attribute can be used to provide a short hint or description that is displayed in the textarea when it is empty.

HTML
<textarea id="message" name="message" rows="5" cols="40" placeholder="Enter your message here..."></textarea>

In this example, the placeholder text "Enter your message here..." will be displayed in the textarea when it is empty.

Live Playground, Try it Yourself

Additional Attributes​

Required​

The required attribute can be used to make the textarea a required field, meaning the form cannot be submitted without a value entered in the textarea.

HTML
<textarea id="message" name="message" rows="5" cols="40" required></textarea>
Live Playground, Try it Yourself

Readonly​

The readonly attribute can be used to make the textarea read-only, meaning users cannot edit the content inside.

HTML
<textarea id="message" name="message" rows="5" cols="40" readonly>Your message cannot be edited.</textarea>
Live Playground, Try it Yourself

Conclusion​

In this tutorial, we have explored the textarea element in HTML forms. By understanding how to create a textarea and use its attributes, you can provide users with a way to enter larger amounts of text in your forms.