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>
It is often necessary to code certain tags (and their text) within the definition of other tags (between the start and end tags). This is called nesting. A good example of nesting is the relationship between the DL (definition list) tag, the DT (definition term) tag, and the DD (definition description) tag.
HTML defines six levels of headings. A heading element implies all the font changes, paragraph breaks before and after, and any white space necessary to render the heading. The heading elements are H1, H2, H3, H4, H5, and H6 with H1 being the highest (or most important) level and H6 the least.
Yes, it's typically fine to use a span inside of an h1 . span is an inline element, so it's typically okay to use it inside anything (that allows elements inside it!)
In HTML 4.01 and XHTML 1.1 and older:
h1
may contain an a
a
may not contain an h1
So <h1><a>…</a></h1>
In the HTML 5 draft:
h1
may contain an a
a
may contain an h1
(but only if the a
is somewhere an h1
is allowed — see the comments on this answer)So either, but browser support may vary (such is life on the bleeding edge).
this is the right answer:
<h1><a href="www.example.com">Example!</a></h1>
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