Can I have heading elements inside definition lists?
Example:
<dl>
<h4> heading </h4>
<dt> title </dt> <dd> content </dd>
<dt> title </dt> <dd> content </dd>
<dt> title </dt> <dd> content </dd>
<h4> heading </h4>
<dt> title </dt> <dd> content </dd>
<dt> title </dt> <dd> content </dd>
<dt> title </dt> <dd> content </dd>
</dl>
It seems to work as expected in my browser 🙂
No; the only elements that might be valid within a
dlareddanddt.The reason it may appear to work is error handling by the browser, which is both unpredictable and, so far as I can tell, mostly undocumented and therefore should not be relied upon.
Though interestingly, as Šime Vidas notes in the comments (below), Firefox, Chrome, Safari, Opera and Internet Explorers 7 and 9 don’t correct the structure and allows the heading elements to remain within the
dl. Which strikes me as being weird.It is, though, while tolerated, still invalid. Whether or not you choose to respect that validity is, of course, optional.
References:
dl, at the W3.org.