Open In App

HTML <textarea> tag

Last Updated : 12 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The <textarea> tag in HTML is used to create a multi-line text input field, allowing users to enter and edit text in a form. Unlike the <input> tag, which is designed for single-line input, <textarea> can be resized and can accommodate longer entries of text.

Syntax

<textarea>....</textarea>

In the above syntax

  • <textarea> and </textarea>: These are the opening and closing tags for the textarea element.
  • rows="4": This specifies the number of visible text lines that the textarea will display.
  • cols="50": This defines the width of the textarea, measured in characters. The number of columns determines how wide the text area is in terms of characters per line.

Creating a Basic <textarea>

The <textarea> element in HTML is used to create a multi-line text input field. This allows users to enter larger amounts of text, such as comments, feedback, or other data that requires more space than a standard text input field.

HTML
<html>
<head></head>
<body>
    <form>
        <label for="feedback">Your Feedback:</label><br>
        <textarea id="feedback" name="feedback" rows="4" cols="50">
        </textarea><br>
        <input type="submit" value="Submit">
    </form>
</body>
</html>

Output

text-area-1
Creating basic text area

In this example

  • The label element is used to create a label for the textarea, improving accessibility.
  • The rows and cols attributes define the size of the textarea.
  • The id attribute links the <textarea> with the <label>.

Styling the <textarea>

Although the <textarea> element comes with default styling, you can customize its appearance using CSS.

HTML
<html>
<head>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f9;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }

        form {
            background-color: #fff;
            padding: 20px;
            width: 100%;
            max-width: 500px;
            border-radius: 8px;
        }

        label {
            font-size: 1.1em;
            margin-bottom: 8px;
            display: block;
        }

        textarea {
            width: 100%;
            padding: 12px;
            font-size: 14px;
            border: 1px solid #ccc;
            border-radius: 4px;
            background-color: #fafafa;
            resize: vertical;
            outline: none;
            transition: border-color 0.3s ease;
        }

        textarea:focus {
            border-color: #4CAF50;
            background-color: #fff;
        }

        input[type="submit"] {
            background-color: #4CAF50;
            color: white;
            border: none;
            padding: 12px 20px;
            cursor: pointer;
            border-radius: 4px;
            width: 100%;
            margin-top: 10px;
        }

        input[type="submit"]:hover {
            background-color: #45a049;
        }
    </style>
</head>
<body>
    <form>
        <label for="feedback">Feedback:</label>
        <textarea id="feedback" name="feedback" rows="4" cols="50"
            placeholder="Type your feedback here..."></textarea><br>
        <input type="submit" value="Submit">
    </form>
</body>
</html>

Output

text-area-2
<textarea> tag in HTML

HTML textarea tag Attribute values

AttributeDescription
autocompleteSpecifies whether the textarea field has autocompleted on or off.
autofocusSpecifies that the textarea field should automatically receive focus when the page loads.
colsTells the browser how many average-width characters should fit on a single line, i.e., the number of columns.
dirnameEnables setting the text direction of the textarea field after submitting the form.
disabledSpecifies that the textarea element is disabled.
formSpecifies one or more forms that the <textarea> element belongs to.
maxlengthSpecifies the maximum number of characters entered into the textarea element.
minlengthDefines the minimum number of characters (as UTF-16 code units) of a textarea element.
nameSpecifies the name of the <textarea> element.
placeholderSpecifies the expected value to be displayed before user input in the textarea element.
readonlySpecifies that the textarea element is read-only. If the textarea is read-only, then its content cannot be changed but can be copied and highlighted.
requiredA boolean attribute that specifies that the <textarea> element must be filled out before submitting the form.
rowsSpecifies the number of visible text lines for the control, i.e., the number of rows to display.
wrapSpecifies in which manner the text is to be wrapped in a textarea when a form is submitted.

Conclusion

The <textarea> tag in HTML is a versatile element for collecting multi-line text inputs from users. By using its various attributes, we can control the size, appearance, and behavior of the textarea to suit our form's needs. Whether we're creating a simple comment box or a more complex input field, the <textarea> tag provides the necessary functionality to capture user input effectively.


Article Tags :

Similar Reads