mdo/code-guide

Why no trailing slash on self closing elements?

antony opened this issue · 2 comments

Just wondering, given its optional status, why not use it?

Using it makes it easy to differentiate between an closed 'void' element and an accidentally unclosed element...

mdo commented

It's an unnecessary syntactical bit, yes, but the main thing to realizes is that a trailing slash isn't the focus of the element. When I think of an <img>, I know it doesn't need closing, so I know I don't need to go looking for an indicator of it being closed. I just think <img>. Same with <hr>, <br>, etc.

This falls in the same camp as the 'no final semi-colon'.
While I personally always add the closing slash to all these type of tags, and the final semi-colon for that matter, it is not necessary, it just makes me happy.
This is a code 'guide' to help give us all a base of good coding practices, and direction, not a coding law/requirement.
Take what you need from the guide, and try to understand it's principles, and hopefully it will help you become a better programmer.
I think the main idea of the guide is to bring us all together, so when I open your code I'm not lost, making us more productive.