Alex Rivera | Logout

Can a label only refer to input elements?

Asked 2009-07-07T19:35:30.037
15

W3Schools have this to say about labels:

The <label> tag defines a label for an input element. [Emphasis mine]

Does this mean that the following HTML isn't valid?

<!doctype html>
    <html>
        <head>
             <title>Example document</title>
        </head>
        <body>
            <label for="x">Label</label> 
            <hr>
            <div id="q" contentEditable="true">Hello</div>
            <hr>
            <div id="x" contentEditable="true">World</div>
        </body>
    </html>

Both Chrome and IE8 give focus to World when Label is clicked, Firefox does not. Which is correct?

Edit
Report

2 Answers

11

According to the W3C it applies to Form Controls, and Form Controls are defined as:

  • Buttons
  • Checkboxes
  • Radio buttons
  • Menus
  • Text input
  • File select
  • Hidden controls
  • Object tags

So FireFox is technically right, although I'd hardly consider it to be "breaking" if a browser didn't restrict it to those elements.

answered 2009-07-07T19:44:05.810
1

I would say it was not an appropriate use of the markup, because label semantics are that they are specifically for controls.

The LABEL element is used to specify labels for controls that do not have implicit labels,

http://www.w3.org/TR/html401/interact/forms.html#h-17.9.1

answered 2009-07-07T19:42:33.143

Your Answer