Span inside anchor or anchor inside span or doesn't matter?

user214582 picture user214582 · Nov 19, 2009 · Viewed 164.7k times · Source

I want to nest span and a tags. Should I

  1. Put <span> inside <a>
  2. Put <a> inside <span>
  3. It doesn't matter ?

Answer

Jon Hadley picture Jon Hadley · Nov 19, 2009

3 - It doesn't matter.

BUT, I tend to only use a <span> inside an <a> if it's only for a part of the contents of the tag i.e.

<a href="#">some <span class="red">text</span></a>

Rather than:

<a href="#"><span class="red">some text</span></a>

Which should obviously just be:

<a href="#" class="red">some text</a>