What is the point of adding input id?

I have 3 questions…

  1. What is the point of adding input id?
  2. Why is the name attribute like this?
    instead of being something like this: name=“cute-mean-ugly”.
  3. And what does “label for” do? is it necessary?

Is this in the context of a specific challenge? Can you provide a link? We don’t have them all memorized.

  1. An “id” is a unique identifier that allows it to be located. You can use it to target CSS, do DOM manipulation, or to link it up with other elements that need to know where it is.
  2. That depends on the larger context.
  3. The “label” identifies it as a label for another element and the “for” tells for what element. We can usually infer that visually when reading a form, but that won’t help people with screen readers.

It would be good to get into the habit of looking things up. This is one of the most important skills for a developer (seriously, I’m not being glib or dismissive here, it can’t be stressed enough). You can probably find a lot of information on sites like this.


Yes it was of a lesson…
Here: https://www.freecodecamp.org/learn/responsive-web-design/basic-html-and-html5/create-a-set-of-checkboxes
and this: https://www.freecodecamp.org/learn/responsive-web-design/basic-html-and-html5/create-a-set-of-radio-buttons

I don’t deal a lot with vanilla forms, but I think the “name” is as a “category”. I think it becomes important when the form is submitted.

Maybe someone with more direct information has a better explanation.

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