Parveez Ahmed
Parveez Ahmed

Reputation: 1417

Is it legal to have children of an anchor tag (<a>) in HTML?

Is it legal to have children of an anchor tag in HTML? For an example:

 <a>
     <font>Example</font>
     <img src="example.jpg"/>
 </a>

It works fine in the browsers.But is it valid? Please help

Upvotes: 27

Views: 15810

Answers (2)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201568

Yes, all versions of HTML allow some elements inside an a element. The set of allowed elements depends on the HTML version. The code posted is valid HTML 3.2 and HTML 4.01 as far as element nesting goes, though the img element is not valid HTML 4.01 due to lack of alt attribute.

Upvotes: 3

Adrift
Adrift

Reputation: 59779

Yes - even more so with the advent of HTML 5 (From the spec):

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.

Upvotes: 34

Related Questions