I have wondered this after playing around with the <button>
tag, which allows HTML to be rendered as button. Nothing new so far...
But I noticed that one can also use the <a>
tag. Complete example:
<button>
normal text
<b>bold text</b>
<a href="http://www.example.com/">linked text</a>
</button>
This is rendered as following on Firefox:
And in Google Chrome:
Now, On firefox, the link target is NOT clickable, only the button... However, on Chrome, the link is clickable, and will redirect to the IANA RFC2606 Page.
Is this undefined behaviour? Are there more cases in (X)HTML that could be described as undefined behaviour?
It's a little more complex than just inspecting the DTD as given by Yi Jiang and mu is too short.
It's true that the XHTML 1.0 DTDs explicitly forbid <a>
elements as children of <button>
elements as given in your question. However it does not forbid <a>
elements as descendants of <button>
elements.
So
<button>
normal text
<b>bold text</b>
<span><a href="http://www.example.com/">linked text</a></span>
</button>
is XHTML 1.0 Strict DTD conforming. But it has the same behavioural difference between Firefox and Chrome as the button fragment in the question.
Now, it is known that DTDs have problems describing limitations on descendant relationships, so it's maybe not surprising that the above sample is DTD conforming.
However. Appendix B of the XHTML 1.0 spec normatively describes descendant limitations in addition to the DTD. It says:
The following elements have prohibitions on which elements they can contain (see SGML Exclusions). This prohibition applies to all depths of nesting, i.e. it contains all the descendant elements.
button
must not contain the input, select, textarea, label, button, form, fieldset, iframe or isindex elements.
Note that it does not contain an exclusion for the <a>
element. So it seems that XHTML 1.0 does not prohibit the <a>
element from being non-child descendant of <button>
and the behaviour in this case is indeed undefined.
This omission is almost certainly a mistake. The <a>
element should have been in the list of elements prohibited as descendants of button in Appendix B.
HTML5 (including XHTML5) is much more thorough on the matter. It says:
4.10.8 The button element
Content model: Phrasing content, but there must be no interactive content descendant.
where interactive content is defined as
Interactive content is content that is specifically intended for user interaction.
a
audio
(if thecontrols
attribute is present)button
details
embed
iframe
img
(if theusemap
attribute is present)input
(if thetype
attribute is not in theHidden
state)keygen
label
menu
(if thetype
attribute is in thetoolbar
state)object
(if theusemap
attribute is present)select
textarea
video
(if thecontrols
attribute is present)
So in (X)HTML5 the <a>
element is prohibited from being a descendant of the <button>
element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With