Does the <li> tag in HTML have an ending tag?
Solution 1:
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.
Solution 2:
It is not good coding practice to leave out the end tags.
If you always write the end tags in
- you will never have an issue if you need to change from HTML to XHTML
- you will always know where the end of the element is
- 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.
Solution 3:
There is a difference here between HTML and XHTML. XHTML are more strict.
While old regular HTML does not enforce it for all tags, all tags in XHTML must have an ending tag** to validate. Even <br>
and <img>
is often written as <br />
or <img ... />
to specifically give them ending tags.
XHTML also introduces other requirements, for example:
- All tags must be lowercase
- Quotations must be used on attributes
For more information see HTML to XHTML