Home > Blockchain >  Can you use <a> without <p>?
Can you use <a> without <p>?

Time:11-07

Is it okay to create a list like this?

<ul>
  <li><a href="#">Item 1</a></li>
  <li><a href="#">Item 2</a></li>
  <li><a href="#">Item 3</a></li>
  <li><a href="#">Item 4</a></li>
</ul>

Or should I always add a <p>?

<ul>
  <li><p><a href="#">Item 1</a></p></li>
  <li><p><a href="#">Item 2</a></p></li>
  <li><p><a href="#">Item 3</a></p></li>
  <li><p><a href="#">Item 4</a></p></li>
</ul>

CodePudding user response:

A <p> element is an inline element for text. You are allowed to insert whatever you like inside it since links are also inline elements.

A list item (<li>) is also an inline element. So you can put other inline elements in there too.

Just consider that a <p> tag has some built-in styling like a margin.

CodePudding user response:

No <p> is needed, <li> already indicates the type of the item (it's a list item).

This w3schools example shows how there's no need for a <p> tag.

CodePudding user response:

Yes that is perfectly fine. p is not needed to declare a link

CodePudding user response:

<p> is not neccessary in a list, however if you need to put a <p> element within a list, the correct way is to put it inside <a> tags

for example

<li><a href="#"><p>Item 3</p></a></li>
  •  Tags:  
  • html
  • Related