Do I need a “/” at the end of an or tag, etc.? [duplicate]

The / is only required for XHTML & XML.

If you’re using a HTML5 doctype, then there’s no need to terminate self-closing tags in this way.

This applies to <img src="https://stackoverflow.com/questions/15149641/img.png" />, <br />, <hr /> etc.

I.e. Just use <img src="https://stackoverflow.com/questions/15149641/img.png">, <br> and <hr>.

If you need an empty element (like a div), don’t use <div />, instead use <div></div>. This is important since in HTML5, the slash is ignored and <div /> is interpreted as <div> without a closing tag.

Leave a Comment