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
The <a> tag (anchor tag) in HTML is used to create a hyperlink on the webpage. This hyperlink is used to link the webpage to other web pages or some section of the same web page. It's either used to provide an absolute reference or a relative reference as its “href” value.
Nested links are illegal. Links and anchors defined by the A element must not be nested; an A element must not contain any other A elements.
The <a> nchor element is simply an anchor to or from some content. Originally the HTML specification allowed for named anchors ( <a name="foo"> ) and linked anchors ( <a href="#foo"> ).
12.2.An anchor name is the value of either the name or id attribute when used in the context of anchors. Anchor names must observe the following rules: Uniqueness: Anchor names must be unique within a document. Anchor names that differ only in case may not appear in the same document.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With