I wish to markup a heading which is also a regular hyperlink.

Do I put the heading inside the link?

<a href="#"><h3>Heading</h3></a>

Or the link inside the heading?

<h3><a href="#">Heading</a></h3>

2 answers

This was chosen as the best answer

h3 is a block-level element, and a is an inline element, so you put the a inside the h3. You're not supposed to put a block-level element inside an inline element.

Answered about 6 years ago by Kelley Curry
  • +1 True and pithy. Great answer. Abinadi Ayerdis about 6 years ago
  • html5 allows for links around block level elements. http://html5doctor.com/block-level-links-in-html-5/ which makes for a trick question - but most common (as html5 is not widely adopted) would be inside the heading... Tony Crockford about 6 years ago

As Kelley said, the correct answer is to place the link inside the heading.

The semantics of this are that the heading's purpose is to identify a section of content. It also happens to link to something. If the link contained the heading, the link would technically be an inline element of the previous section heading level, so the heading in question would be a child of that - probably not your intent.

Answered about 6 years ago by superstringcheese