Is there a more correct order for nesting a <a>
and <h1>
elements in HTML?
e.g.:
<a href="www.example.com"><h1>Example!</h1></a>
or
<h1><a href="www.example.com">Example!</a></h1>
Is there a more correct order for nesting a <a>
and <h1>
elements in HTML?
e.g.:
<a href="www.example.com"><h1>Example!</h1></a>
or
<h1><a href="www.example.com">Example!</a></h1>
In HTML 4.01 and XHTML 1.1 and older:
h1
may contain ana
a
may not contain anh1
So
<h1><a>…</a></h1>
In the HTML 5 draft:
h1
may contain ana
a
may contain anh1
(but only if thea
is somewhere anh1
is allowed — see the comments on this answer)So either, but browser support may vary (such is life on the bleeding edge).
HTML4, XHTML
HTML5
It's acceptable in HTML5 as the anchor tag's been made 'block level'.
Some good info on block level and inline level tags can be found at http://www.webdesignfromscratch.com/html-css/css-block-and-inline/
this is the right answer: