Search code examples
htmlanchor

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 favor 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!


Solution

  • The first example is only allowed in HTML5.

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