I don't understand what the label element really is. Don't understand either what the attributes id and name are. I've got no problem in completing the steps

Tell us what’s happening:
I need someone to explain what the id and name attributes are, what is the difference between them and what’s the purpose for the label element

  **Your code so far**
      <h2>Cat Photos</h2>
      <!-- TODO: Add link to cat photos -->
      <p>Click here to view more <a target="_blank" href="https://freecatphotoapp.com">cat photos</a>.</p>
      <a href="https://freecatphotoapp.com"><img src="https://cdn.freecodecamp.org/curriculum/cat-photo-app/relaxing-cat.jpg" alt="A cute orange cat lying on its back."></a>
      <h2>Cat Lists</h2>
      <h3>Things cats love:</h3>
        <li>cat nip</li>
        <li>laser pointers</li>
        <img src="https://cdn.freecodecamp.org/curriculum/cat-photo-app/lasagna.jpg" alt="A slice of lasagna on a plate.">
        <figcaption>Cats <em>love</em> lasagna.</figcaption>  
      <h3>Top 3 things cats hate:</h3>
        <li>flea treatment</li>
        <li>other cats</li>
        <img src="https://cdn.freecodecamp.org/curriculum/cat-photo-app/cats.jpg" alt="Five cats looking around a field.">
        <figcaption>Cats <strong>hate</strong> other cats.</figcaption>  
      <h2>Cat Form</h2>
      <form action="https://freecatphotoapp.com/submit-cat-photo">
          <legend>Is your cat an indoor or outdoor cat?</legend>
          <label><input id="indoor" type="radio" name="indoor-outdoor" value="indoor"> Indoor</label>
          <label><input id="outdoor" type="radio" name="indoor-outdoor" value="outdoor"> Outdoor</label>
          <legend>What's your cat's personality?</legend>
          <input id="loving" type="checkbox" name="personality"><label for="loving">Loving</label>
          <input id='lazy' type='checkbox' name='personality'><label for='lazy'>Lay</label>
        <input type="text" name="catphotourl" placeholder="cat photo URL" required>
        <button type="submit">Submit</button>
  **Your browser information:**

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

Challenge: Step 57

Link to the challenge:

1 Like

id and class attributes are used to identify an element. The difference between the two is that id is a unique identifier, meaning there cannot be any elements with the same id. eg:

<div id="apple" class="fruits"></div> <!--no other element can have the id 'apple' -->
<div id="orange" class="fruits"></div> <!-- there can be multiple elements with the same class 'fruits' -->

Recall that you can target these id and class in css by using the hash (#) and dot (.) selectors respectively.

As for name attribute, what you need to know now is that when a form is submitted, the data is packaged as a series of name-value pairs. Without the name attribute, <input> tag is unable to provide its value to the server when submitted.

What <label> tag does, is quite literally labelling the <input> tag. This has several benefits over simply using a general tags like <p>:
The label is associated with the input , so clicking the label will automatically redirect user to the input (eg. clicking on the ‘Loving’ label will automatically check the checkbox input with id='loving'). It also helps with accessibility for screen reader users.


This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.