Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML HTML Forms Organizing Forms Add Labels

label for text area element , and give it the text "comment"

how to create a label for the textarea , and give it the text "comment"

index.html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>HTML Forms</title>
  </head>
  <body>

    <form action="index.html" method="post">
      <label for="name">Name:</label>
      <input type="text" id="name" name="user_name">

      <input type="email" id="email" name="user_email"




      <label for="comment"> comment: </label>
      <textarea id="comment" name="user_comment"></textarea>







      <button type="submit">Submit Comment</button>
    </form>

  </body>
</html>

2 Answers

Felix Sonnenholzer
Felix Sonnenholzer
14,654 Points

Hi,

So I am not sure what you exactly mean so I am giving you more solutions, for what I interpreted.

If you just want to label your comment textarea with the word "comment", then you have to put the text between the label tags. You are actually already doing it, but the reason your code isn't working properly might be, because you didn't close the "email"-input.

<input type="email" id="email" name="user_email"

Just close the tag and it should show up.

Or if you want to add text in the field, you can add the attribute "placeholder" for text to display in the textarea field and disappear when the user is writing something. It works like this:

<label for="comment"> comment: </label>
<textarea id="comment" name="user_comment" placeholder="Please leave a comment!"></textarea>

You could also put text between the textarea tags like this:

<label for="comment"> comment: </label>
<textarea id="comment" name="user_comment">Please leave a comment!</textarea>

But the user would have to delete the content before he can write something himself, so I would recommend the first solution!

Try it! I hope this helps!

Hi,

What you have for the label is correct but you have a few extra bits in your code that you don't need like this line:

<input type="email" id="email" name="user_email"

The final code should look like this:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>HTML Forms</title>
  </head>
  <body>

    <form action="index.html" method="post">

      <label for="name">Name:</label>
      <input type="text" id="name" name="user_name">

      <label for="comment">Comment:</label>
      <textarea id="comment" name="user_comment"></textarea>

      <button type="submit">Submit Comment</button>

    </form>

  </body>
</html>

-Rich