It depends on what the span is for. If it refers to the text of the link, and not the fact that it is a link, choose #1. If the span refers to the link as a whole, then choose #2. Unless you explain what the span represents, there's not much more of an answer than that. They're both inline elements, can be syntactically nested in any order.
with both HTML 4.01 and XHTML 1.0 doctypes, and both passed validation successfully!
Only thing to be aware of is to ensure that you close the tags in the correct order. So if you start with a <span> then an <a>, make sure you close the <a> tag first before closing the <span> and vice-versa.
SPAN is a GENERIC inline container. It does not matter whether an a is inside span or span is inside a as both are inline elements. Feel free to do whatever seems logically correct to you.
Personally, as a web developer, I only ever put a span within an anchor tag if I am trying to highlight a section of the links text, such as applying a background to one section.
It depends on what the span is for. If it refers to the text of the link, and not the fact that it is a link, choose #1. If the span refers to the link as a whole, then choose #2. Unless you explain what the span represents, there's not much more of an answer than that. They're both inline elements, can be syntactically nested in any order.
It will work both, but personally I'd prefer option 2 so the span is "around" the link.
It doesn't matter - they're both allowed inside each other.
It is perfectly valid (at least by HTML 4.01 and XHTML 1.0 standards) to nest either a
<span>
inside an<a>
or an<a>
inside a<span>
.Just to prove it to yourself, you can always check it out an the W3C MarkUp Validation Service
I tried validating:
And also the same as above, but with the
<a>
inside the<span>
i.e.
with both HTML 4.01 and XHTML 1.0 doctypes, and both passed validation successfully!
Only thing to be aware of is to ensure that you close the tags in the correct order. So if you start with a
<span>
then an<a>
, make sure you close the<a>
tag first before closing the<span>
and vice-versa.SPAN is a GENERIC inline container. It does not matter whether an
a
is insidespan
orspan
is insidea
as both are inline elements. Feel free to do whatever seems logically correct to you.Personally, as a web developer, I only ever put a span within an anchor tag if I am trying to highlight a section of the links text, such as applying a background to one section.