Magento 2 Experten — Hyvä Theme, Tailwind CSS & SEO aus einer Hand ›

Multi-Line Text: textarea, and Connecting label Correctly

Multi-Line Text: textarea, and Connecting label Correctly

~7 Min. Lesezeit Zuletzt aktualisiert am August 8, 2026

<input type="text"> is only meant for a single line of text. For longer text, like a message in a contact form, there's <textarea>.

The <textarea> element

Unlike <input>, <textarea> is not a self-closing element - it has an opening and a closing tag, and the starting value (if any) goes as text in between, instead of in a value attribute:

<label for="message">Your message:</label><br>
<textarea name="message" id="message" rows="5" cols="40"></textarea>

rows and cols control the visible size: rows is the number of visible text lines, cols the approximate width in characters. Unlike a single-line <input>, a user can actually create new lines in a <textarea> by pressing Enter.

The label principle recapped

You've already used <label> several times now. Let's recap the rule clearly once more, since it's so important:

  1. Every input field gets a unique id.
  2. The matching <label> gets a for attribute with exactly the same value as that id.
  3. Result: clicking the label automatically activates (or focuses) the matching field.

Achtung: A form with no <label> elements at all, only placeholder text (placeholder), is a very common beginner mistake. placeholder disappears as soon as you start typing - then you suddenly no longer know which field you're filling in! <label>, on the other hand, always stays visible. It's best to use both together: <label> for the permanent caption, placeholder at most as an additional example.

Adding the message field

Extend Finn's contact form with a message field:

contact.html
<form>
  <p>
    <label for="first-name">Your first name:</label><br>
    <input type="text" name="first-name" id="first-name" required>
  </p>

  <p>
    <label for="email">Your email:</label><br>
    <input type="email" name="email" id="email" required>
  </p>

  <p>
    <label for="message">Your message:</label><br>
    <textarea name="message" id="message" rows="5" cols="40"></textarea>
  </p>
</form>

Tipp: Notice that the <input> fields now also have id attributes, so their <label> are correctly connected - we hadn't done that consistently for this form in the earlier chapters.