HTML5 served as text/html follows HTML 4 syntax rules, for the most part. This means HTML 4 documents will validate as HTML5 with the exception of a few deprecated/obsolete attributes (and a few tags). This means we can write an image or input, or other self-closing tag as simply,
<img src="" alt="">
It is only when serving HTML5 as XML that we need to conform to that syntax model, the way XHMTL does. For that language the above would be invalid, and must be written,
<img src="" alt="" />
with the leading space before the closing slash. With HTML5, the leading space is optional, and the following is also valid:
<img src="" alt=""/>
What some folks would like to say is required is only the case given the XML conformance requirement when serving as application/xml. Don't let anyone tell you it is a must for our purposes. It is not. Some exercises may require it, but that is up to the author, and may be somewhat misleading. One thing is certain, though, consistency is a best practice, so whatever way we choose to write our self-closing tags should be consistent.