Where should the <label> be positioned? Before or after the <input> tag?

I am doing the New RWD and I am confused about the label tag.

  1. When working on radio boxes, we nested the input inside the label field.
  2. When working on checkboxes, we nested labels inside input.

Could someone explain this to me? Thank you!

To associate the <label> with an <input> element, you need to give the <input> an id attribute. The <label> then needs a for attribute whose value is the same as the input’s id. which is what you did in this challenge.

Alternatively, you can nest the <input> directly inside the <label>, in which case the for and id attributes are not needed because the association is implicit:

<label>Do you like peas?
  <input type="checkbox" name="peas">

Here’s a resource on the label tag: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label

Thank you for your response!

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