Learn HTML Forms by Building a Registration Form - Step 17

Hello, I have a question. I uderstood that the id attribute has to be in the input element and the for attribute in the label element. Do I have the for element in the wrong place?

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Registration Form</title>
    <link rel="stylesheet" href="styles.css" />
  </head>
  <body>
    <h1>Registration Form</h1>
    <p>Please fill out this form with the required information</p>
    <form action='https://register-demo.freecodecamp.org'>
      <fieldset>
        <label>Enter Your First Name: <input id="first-name" /><for="first-name"></label>
        <label>Enter Your Last Name: <input id="last-name" /><for="last-name"></label>
        <label>Enter Your Email: <input id="email" /><for="email"></label>
        <label>Create a New Password: <input id="new-password" /><for="new-password"></label>
      </fieldset>
      <fieldset></fieldset>
      <fieldset></fieldset>
    </form>
  </body>
</html>
/* file: styles.css */
body {
  width: 100%;
  height: 100vh;
  margin: 0;
  background-color: #1b1b32;
  color: #f5f6f7;
}

label {
  display: block;
  margin: 0.5rem 0;
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.42

Challenge: Learn HTML Forms by Building a Registration Form - Step 17

Link to the challenge:

this is the label opening tag
you need to put the for attributes in the opening tags

1 Like

I’m learning, so hopefully someone can chime in.

I see that you’re putting the < input > tag inside of the < label > tag. If that’s the case, then I don’t think a id=“”" and for=“” attribute is needed as its understood (someone please correct me if I’m off).

For me, I try to keep things organized by putting the < label for =“” > on one line, and then the < input type=“text” id=“” name=“” value=“” > on another.

1 Like

I got it, thanks for the help. One more question; Should an attribute always be in the opening tag from a element?

1 Like

hi, yes, always put attributes in the opening tags.