Home

OR...">

<h1> inside or outside <a>?

I want to use h1

in an element a

. Which one is more correct?

<a href="#"><h1>Home</h1></a>

      

OR

<h1><a href="#">Home</a></h1>

      

+3


source to share


3 answers


How w3 describes the markup A

:

An anchor is a piece of text that marks the beginning and / or end of a hypertext link.

The text between the start tag and the end tag is either the start or destination (or both) of the link. The anchor label attributes are as follows.

This means both are correct, so it depends on what you want to do the hyperlink , if you surround everything <h1>

you need to specify it as a parent:



<a href="#"><h1>Anchor for entire title</h1></a>
      

Run codeHide result


If you only want to get a specific part <h1>

, you only surround that part like this:



<h1>Anchor only for <a href="#">this</a></h1>
      

Run codeHide result


+1


source


Both are beautiful.

It really depends if you want the entire heading to be a link or just text in it.



(It's a bit weird to make the main title for your page a link to the top of the page (or somewhere else, for that matter).)

0


source


According to the HTML5 spec, both are correct:

An element can be wrapped around all paragraphs, lists, tables, etc., even entire sections if there is no interactive content inside (such as buttons or other links).

0


source







All Articles