HTML tags inside <label>


Html Problem Overview

I have a table in a page that consists of checkboxes in the cells on the left and descriptions in the cells on the right. The "description" contains h4 headers and plain text. I want to make that whole description (everything inside <td></td>) a label.

So each row looks like this:

<tr><td><input type="checkbox" name="entiries[]" value="i1" id="i1"></td>
<td><label for="i1">
<h4>Some stuff</h4>more stuff..
<h4>Some stuff</h4>more stuff..

This does not work however, the text does not act like a label and is not clickable. I'm using Firefox 3.6 to test it. If I remove <h4> tags it starts working, but that complicates formatting. Is there something about <h*> tags that prevents <label> from working correctly?

Html Solutions

Solution 1 - Html

Block level elements (to which h4 belongs) are not allowed inside inline elements, and will cause undefined behaviour. You can use span elements instead.

Solution 2 - Html

Only inline elements (except other label elements) may appear inside label elements.

<!ELEMENT LABEL - - (%inline;)* -(LABEL) -- form field label text -->


It doesn't make sense to put headings there anyway.

Solution 3 - Html

The <label> element in HTML is an inline level element and cannot contain block level elements.

This is probably what's causing your issues. Alternatively you can put your labels inside the <h4>'s :

<tr><td><input type="checkbox" name="entiries[]" value="i1" id="i1"></td>
<h4><label for="i1">Some stuff</label></h4>more stuff..
<h4><label for="i1">Some stuff</label></h4>more stuff..

Solution 4 - Html

Here on MDN they explain exactly why NOT to use headings inside a label tag:

> Placing heading elements within a


All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSaltyNutsView Question on Stackoverflow
Solution 1 - HtmlTatu UlmanenView Answer on Stackoverflow
Solution 2 - HtmlQuentinView Answer on Stackoverflow
Solution 3 - HtmlJamie DixonView Answer on Stackoverflow
Solution 4 - HtmlWiltView Answer on Stackoverflow