开发者

Html: What is the correct order of <a> and <p> tags?

Which of the following, if either, is correct by standards?

<!-- Do the links surround the target link object -->
<a href=''><p>Link Description</p></a>
<!-- or does the object type encapsulate the link-->
<p><a href=''>Link Description</a></p>

I know they function the same, But it's a best practice/standards question. This could apply to ul/ol too.

The only reason I think to fav开发者_运维知识库or the <a> tag inside is with a situation like:

<p>This is a longer sentence with a <a href=''>short link here</a></p>

Thanks!


The first example is only allowed in HTML5.

The second example is allowed in all versions of HTML/XHMTL.


You can't wrap a block element with an inline element. You have to do this in that way:

<p><a href=''>Link Description</a></p>

This is W3C standard. Check this!


As of HTML 5, anchor tags (<a></a>) are allowed to wrap around almost anything, including paragraphs. So either example is valid, although I tend to prefer having anchors inside paragraphs.


anchors (a) should be inside a block element. So

<p><a>...</a></p>


I would say the second one, than the <p> is not inheriting attributes of <a> and keeping it's original formatting.


Inline elements such as <a> are often contained within block-level elements such as <p>. The block elements provide the structure needed to present your data.


I always put the <p> tags inside unless the amount of text is large.


For anyone looking at this now, here is a link that adds more context to correct answer.

The first example is only allowed in HTML5.

The second example is allowed in all versions of HTML/XHMTL.

HTML5 specification

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜