- Local time
- 21:56
- Joined
- Sep 24, 2019
- Messages
- 1,259
- Pronouns
- he/him
According to the HTML5 spec, there are a handful of tags that must not have contents. Those are area, base, br, col, embed, hr, img, input, link, meta, param, source, track, wbr.
It seems like it's left up to us how we format those. We can leave it 'open' like <img src="cat.gif">, <br>
or 'close' them like <img src="cat.gif" />, <br />
.
I sway towards closing them with a forward slash at the end, I think it's more readable. Do you have a preference or a good reason for either way?
Opinion on this seems to have shifted quite a bit through different versions of HTML.
- HTML5: the slash is optional.
- HTML4: the slash is technically invalid. However, it's accepted by W3C's HTML validator.
- XHTML: The slash is REQUIRED.
Last edited: