Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it right to add <span> tag inside <a> tag?

Tags:

html

I was wondering if we could add a span tag inside a tag....

<h2 style="text-align: left;"><a href="mydomain.com"><span style="font-weight: bold;">Dog dresses</span></a><br></h2> 

Is the above method right? Is it safe to use...???

I know that We can define some class here and let it go inside other elements like this.

<h2><a href="mydomain" class="bold">Dog dresses</a></h2>  .bold {font-weight: bold; } 

OR

<h2 class="bold"><a href="mydomain">Dog dresses</a></h2>  h2.bold a { font-weight: bold; } 

Please share your views..

like image 562
Codeobsession Avatar asked Sep 15 '11 07:09

Codeobsession


People also ask

Can you put a span inside an a tag?

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.

Can we use span inside I?

Yes, it is valid to have a <span> tag as the content of an <i> tag.

Can I put span inside heading?

Yes, it's typically fine to use a span inside of an h1 . span is an inline element, so it's typically okay to use it inside anything (that allows elements inside it!)

Can I have span inside div?

The span tag is just like a div, which is used to group similar content so it can all be styled together. But span is different in that it is an inline element, as opposed to div , which is a block element.


1 Answers

Yes, it's fine. <span> is an inline element. Unless you add the css display: block; to it, it can go in the <a>.

like image 88
Paul Avatar answered Sep 21 '22 13:09

Paul