Is it legal to have children of an anchor tag (

2020-02-11 21:36发布

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

2条回答
家丑人穷心不美
2楼-- · 2020-02-11 21:48

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.

查看更多
够拽才男人
3楼-- · 2020-02-11 21:56

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.

查看更多
登录 后发表回答