Amit
Amit

Reputation: 46341

Why does the spec for the "for attribute" of a <label> hints that an ID is not unique?

We all know that in HTML, an element ID is (and must be) unique.

From the standard:

The value must be unique amongst all the IDs in the element's home subtree and must contain at least one character.

Yet in the same standard, the for attribute in the <label> element it reads:

If the attribute is specified and there is an element in the Document whose ID is equal to the value of the for attribute, and the first such element is a labelable element, then that element is the label element's labeled control.

That would mean there could be more then one element with an ID equal to the value of the for attribute.

So which is it? Unique - or not?

Upvotes: 0

Views: 136

Answers (1)

scrappedcola
scrappedcola

Reputation: 10572

It's covering the case where someone may not have made a unique id, since really there isn't anything hard preventing anyone from breaking standard, and specifies the behavior in such a case. Basically a secondary line enforcing the idea that there should only be 1 id with a certain value.

Upvotes: 3

Related Questions