Reputation: 99
Hy guys, is there a difference between <li>Hello wolrd</li>
and <li>Hello world
.
Both tags have the same result:
- Hello world
I know that every tag should have an close tag but I discovered this by mistake. Can anyone tell me the reason?
Upvotes: 1
Views: 989
Reputation: 466
HTML will in some cases be allowed to have errors and still run successfully (as someone else mentioned in this case it may be omitted). This doesn't mean you should be doing that. There's also the doctype declaration which you could leave out, you can put tags outside of the body, but it's not the correct way to do it.
Having these kind of mistakes may seem to work now, but it may also cause problems (and that might differ per browser). It will also impact your page rank on google. Use the https://validator.w3.org/ to ensure you have as few problems on the page as possible.
Upvotes: 0
Reputation: 6489
In HTML some closing tags are optional. </li>
is one of them.
From the HTML5 syntax W3C recommendations:
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.
Upvotes: 5
Reputation: 156958
No, actually there isn't, if you follow the rules described in the spec.
The HTML specification, both HTML4 and HTML5 provide a way to write <li>
without closing tag, since it can be logically derived from the markup.
The rule is, as pointed out in the HTML spec:
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.
Upvotes: 2