So, I was learning about lists in HTML at college and the professor said <li>
doesn't have an ending tag </li>
along with some other tags like <img>
and <br>
. Is that correct or not? Because I've seen a lot of templates / themes using tag at the end, as well many sites also teach you that </li>
exists, so I'm not sure whom to believe and what is correct way of using <li>
?
The reason why I'm asking this is because last time we learned about <img>
tag, he said that the alt=""
attribute gives you a text displayed over the image when you hover the mouse, which turned it's only alternative text for broken images when I asked here and he was wrong for that case, which also made me wonder this as well.
Thanks.
li tag is used for inserting List item in both ordered and unordered list. Q2. li is an empty tag.
<li>: The List Item element. The <li> HTML element is used to represent an item in a list. It must be contained in a parent element: an ordered list ( <ol> ), an unordered list ( <ul> ), or a menu ( <menu> ). In menus and unordered lists, list items are usually displayed using bullet points.
What Is a Void Element? The void elements or singleton tags in HTML don't require a closing tag to be valid. These elements are usually ones that either stand alone on the page or where the end of their contents is obvious from the context of the page itself.
No, it isn't. You can test this with a validator.
The li
element has an end tag (</li>
), but it’s optional in some cases:
An
li
element's end tag may be omitted if theli
element is immediately followed by anotherli
element or if there is no more content in the parent element.
It is not good coding practice to leave out the end tags.
If you always write the end tags in
Semantically, all tags have a beginning tag and an end tag, whether you use them or not is a different matter entirely.
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