Emergency Exit
Emergency Exit

Reputation: 471

Is it allowed to use <label> tag without labeled control?

I need to show in a page a list of, let's say, person's properties that should be rendered more or less as follow:

name: Name
date: 1/1/2000
other: Other

Reading the doc they say:

The LABEL element may be used to attach information to controls.

So, is it the right tag to encompass the names of the properties like name, date... even if there's not an <input> to associate with?

Upvotes: 5

Views: 3362

Answers (4)

Paul D. Waite
Paul D. Waite

Reputation: 98926

Nope, as per Quentin’s answer.

However, in HTML5, <dl> can be used for generic associations where <label> isn’t appropriate.

Upvotes: 6

Adam
Adam

Reputation: 5455

I partially agree with the answers so far but want to add that if you want to use labels for some reason, then I would display the property values in read-only controls, and then your labels will be valid.

I've done this using appropriate styling to differentiate the read-only controls from the functioning controls to avoid confusing your users. This was on a sequence of pages which built up the information gathered from the user in a wizard.

I have this link to W3C - the "Editor's Draft" as opposed to the link above which is the "Working Draft", which states that you can associate it with any element - as long as it's 'labelable' - even though this is a subsection of the Form section. It states earlier that a labelable element does not have to be within a form.

http://dev.w3.org/html5/spec/single-page.html#the-label-element

Upvotes: 0

Stecman
Stecman

Reputation: 3090

No, it is not correct to use the label element like that.

The important thing here is the meaning of may.

The LABEL element may be used to attach information to controls.

RFC 2119 (which the HTML4 spec follows) defines may:

May: This word, or the adjective "OPTIONAL", mean that an item is truly optional

So here, may does not mean the label element can be used for other purposes; it just means that it is not required to use a label element with controls.


As far as alternatives go, it depends what you want to achieve. If you are just trying to follow the spec closely, then I suggest using p and a strong element for each pair. If you want the data to be more meaningful to computers, you could consider using one of the Microformat specifications.

Upvotes: 2

Quentin
Quentin

Reputation: 944474

No.

It says that it can associate information with controls.

It does not say that it can associate information with anything else.

See also the newer (but draft) specification:

Some elements, not all of them form-associated, are categorized as labelable elements. These are elements that can be associated with a label element.

button input (if the type attribute is not in the hidden state) keygen meter output progress select textarea

Upvotes: 6

Related Questions