Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the <li> tag in HTML have an ending tag?

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.

like image 692
user2699298 Avatar asked Dec 12 '13 17:12

user2699298


People also ask

Is Li An empty tag in HTML?

li tag is used for inserting List item in both ordered and unordered list. Q2. li is an empty tag.

What is the LI tag in HTML?

<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.

Which tag has no ending?

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.

Is UL a self closing tag?

No, it isn't. You can test this with a validator.


2 Answers

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 the li element is immediately followed by another li element or if there is no more content in the parent element.

like image 75
unor Avatar answered Sep 17 '22 13:09

unor


It is not good coding practice to leave out the end tags.

If you always write the end tags in

  1. you will never have an issue if you need to change from HTML to XHTML
  2. you will always know where the end of the element is
  3. it's cleaner and easier to read.

Semantically, all tags have a beginning tag and an end tag, whether you use them or not is a different matter entirely.

like image 40
Malachi Avatar answered Sep 17 '22 13:09

Malachi