Computer Study

textarea Tag in HTML

The `<textarea>` tag in HTML is used to create a multi-line text input field where users can input and edit text. This tag is especially useful when you need to allow users to input long-form text such as comments, messages, or descriptions.

Syntax:

<textarea name=”input-name” rows=”number-of-rows” cols=”number-of-columns”>Initial text value</textarea>

Attributes:
– `name` (required): Specifies the name of the input field. This attribute is used to identify the input element when the form is submitted.
– `rows` (optional): Specifies the number of rows (i.e., lines) that should be visible in the text area. The default value is 2.
– `cols` (optional): Specifies the number of columns (i.e., characters per line) that should be visible in the text area. The default value is 20.

Example usage:

<form>
<label for=”message”>Leave a message:</label>
<textarea id=”message” name=”message” rows=”4″ cols=”50″></textarea>
<button type=”submit”>Submit</button>
</form>

In the above example, a textarea element is created with an `id` of “message” and a `name` of “message”. The `rows` and `cols` attributes are also specified to make the input field larger, with 4 rows and 50 columns. The `for` attribute of the label tag should be equal to the id of the textarea element for accessibility purposes.

When the form is submitted, the value of the textarea will be sent to the server with the name “message”.

You can also pre-fill the textarea with text by placing the text between the opening and closing tags of the `<textarea>` element:

<textarea name=”message” rows=”4″ cols=”50″>This is some initial text.</textarea>

In conclusion, the `<textarea>` tag is a useful tool for creating multi-line text input fields in HTML forms. By specifying the number of rows and columns, you can customize the appearance of the input field to fit your needs.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also
Close
Back to top button