Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Possible Duplicate:
Anchor tag inside H1 or H1 inside achor tag : Which is better?

I am being advised to place a H2 tag within a A href tag. To me this does not meet with standards and may even be considered as black hat techniques (or at least grey) I have expressed my concerns but they are insisting its a valid SEO technique.

If I run the code past W3C Markup Validation Service it fails and must admit I do get a bit anal regarding using correct syntax on our website.

Am I being too picky over conforming to standards which in my mind would make it easier for a search engine to read or am I missing a trick here. ?

share|improve this question
add comment

marked as duplicate by Su', John Conde Oct 27 '11 at 22:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

Placing a hyperlink in a heading is perfectly fine. WordPress posts have their titles in <hx> tags (I think it's <h1> on the individual post page and <h2> on the category pages) and are hyperlinked and they are well indexed and ranked.

What you are seeing is that the HTML is poorly formatted. The anchor goes inside the heading. Not the other way around. Remember, inline elements go inside block level elements, not the other way around.

share|improve this answer
    
Sorry no I meant the other way round, a <a href containing a <h2> tag so a block element within a inline element. –  Chedders Oct 27 '11 at 19:11
    
I know what you meant. :) The only difference between the two is one is valid HTML and the other is not. As far as SEO goes there is no difference. –  John Conde Oct 27 '11 at 19:15
    
In html5 an h2 or any block element can be used inside an anchor. It's correct code and it validates. However you should not put it (the anchor with the block-element inside) inside an element that does not allow block elements inside. –  Osvaldo Oct 27 '11 at 21:22
add comment

In html5 you can put the any block-type element inside the anchor tag:

Although previous versions of HTML restricted the a element to only containing phrasing content (essentially, what was in previous versions referred to as “inline” content), the a element is now transparent; that is, an instance of the a element is now allowed to also contain flow content (essentially, what was in previous versions referred to as “block” content)—if the parent element of that instance of the a element is an element that is allowed to contain flow content.

http://dev.w3.org/html5/markup/a.html#a-changes

Just use html5 and it will validate. AFAIK putting a header tag inside a anchor tag is not consider black-hat.

share|improve this answer
2  
Can you post a link for that bit about Google penalizing sites for excessive HTML errors? I'd like to give that a read. –  John Conde Oct 27 '11 at 20:22
    
I can't find the original article (I've searched for it), but it was an article about new quality indicators. That included that a site would rank better if it would met a number of (new) quality indicators. For example I remember a reputable author/editor, less spelling mistakes, speed, and cleaner html code. I'll edit my answer. "penalize" is a strong word and what I've read is that it would be one of many many quality indicators. –  Osvaldo Oct 27 '11 at 21:14
1  
@JohnConde Is HTML validation necessary for ranking? from mid-March 2011 still basically says no. Osvaldo, unless you can back up the validation comment better, I'd remove it. (Though I do still think the question should be closed as a dupe.) –  Su' Oct 27 '11 at 21:22
    
I've removed it. –  Osvaldo Oct 27 '11 at 21:24
    
It is a dupe indeed. Nice catch. –  John Conde Oct 27 '11 at 22:30
add comment

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