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

Create a label with a for attribute that matches the input element's ID. Between the label tags, write the text "Name:".

Question or test, inconsistent, relevant but unsubstantiated Logical.

ChecK ...

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

    <form action="index.html" method="post">
      <input type="text" id="name" name="user_name">
      <textarea id="comment" name="user_comment"></textarea>
      <button type="submit">Submit Comment</button>
      <label>for=">Name:</label>
    </form>

  </body>
</html>

2 Answers

Your HTML contains some syntax errors. You have <!DOCTYPE html> added twice. More importantly for the question, your label is incorrect.

The question asks us to:

Create a label with a for attribute that matches the input element's ID

We can see that the ID for the input element is 'name':

<input type="text" id="name" name="user_name">

We then need to create a label with a for="name" attribute:

<label for="name"></label>

The next part of the question asks:

Between the label tags, write the text "Name:"

We can simply add this inside of the label element:

<label for="name">Name:</label>

It might also be best to put your label before the input element. The full code should look similar to the following:

<!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">
      <textarea id="comment" name="user_comment"></textarea>
      <button type="submit">Submit Comment</button>
    </form>
  </body>
</html>

Great explanation, Mark. I have chosen your answer as Best Answer. Ary, in the future, it's encouraged to select a Best Answer if you feel another member of the community has adequately addressed your question and provided you with a solution that helps solve your problem, this awards that user with some bonus points, and it also lets other members of the community, who might be facing the same or similar issues, know that there is an answer contained within this thread.

code original inconsistent , thank you