I am trying to use h1 tags on my blog for the post title and came across one problem. Title is hyperlinked.

so

Case 1:

<h1> <a href=""> xyz </a> </h1>

case 2:

<a href=""> <h1> xyz</h1> </a> 

which one is better in terms of SEO ?

link|improve this question

feedback

3 Answers

up vote 7 down vote accepted

If you are using HTML5, just pick one; they're equivalent.
HTML5 does allow block-level links, but in your case there's no particular reason to do it, since there's only one block-level element. Personally, I wouldn't do it here, because having the h1 tag on the outside would make it easier to scan for in source code.

Anything else(XHTML, HTML 4, etc) and the second one is just plain wrong. It wouldn't be valid code, and on some level that's bad for your search optimization. [Insert standard disclaimer about how much any single offense really affects anything, etc.]

link|improve this answer
I think i should go for the 1st one. Thanks. – Sangram Oct 3 '11 at 18:42
feedback

They're the same as far as SEO is concerned. (Usually block level elements contain inline elements and not vice-versa so you should use the first example but it won't affect SEO).

link|improve this answer
1  
Actually inline elements must not contain block elements as per the HTML spec. – DisgruntledGoat Oct 3 '11 at 15:03
@DisgruntledGoat Not quite. Doctype needs to be accounted for. – Su' Oct 3 '11 at 16:07
@Su' which doctypes allow block elements inside inline elements? – DisgruntledGoat Oct 3 '11 at 23:17
feedback

I find that with Case 2 the href insert is often out of line with the rest of my page. But that could be the way I set my margins in my .css. Thus I would favour Case 1.

link|improve this answer
Thanks Guy Thomas. – Sangram Oct 3 '11 at 18:41
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.