I really wonder is a li
tag in HTML a inline-level or block-level element?
I find that a li
tag in a p
tag can break a new line, so it's kind of like a block, but it's embedded in a ul
tag or a ol
tag.
From this point of view, it's kind of like a inline-level element? Which is right?
<!DOCTYPE html>
<html>
<body>
<div style="background-color:black;color:white;padding:20px;">
<p>
<ul>
<li>Hello</li>World
</ul>
Sagar
</p>
</div>
</body>
</html>
The W3School Definition of Inline and Block Element Stands as follows:
As you can see in the example above, even though I typed "Hello" inside of the li
tag and immediately followed it with "World", the single li
tag will not allow the "World" to be on the same line. This demonstrates that the li
tag is taking 100% of the available width, proving that li
is a block level element.
That is my point of view.