Web Development

how to make HTML elements (H1, H2 etc..) as links?

how to make HTML elements (H1, H2 etc..) as links

What is the correct code for turning HTML elements (H1, H2 or Paragraph etc..) into a link and search engines index texts of header and link both?

which one is better:
<a href="#"><h1>heading</h1></a>

or
<h1><a href="#">heading</a></h1>

The element which displays as a block (in this case <h1>) always should surround %inline elements (such as <a>).

Another example <div> should always be outside <span>.

That is why:
<h1><a href="#">heading</a></h1>
is correct.

<a href="#"><h1>heading</h1></a>
is Wrong.

An even easier way of understanding this is that the following makes sense:

<h1><a href="#1">link</a> and <a href="#2">Another link</a></h1>

It would be highly unusual to try the inverse with multiple <h1>s inside an <a>.

Reference:

http://www.w3.org/TR/html401/struct/global.html#h-7.5.4

Leave a Reply

Your email address will not be published. Required fields are marked *