In order to understand why the slash was ever there, we need to consider XML and its strict specification (which I won’t go into here. Whew!)
The strict rule in XML is that there are no unclosed elements. In fact all elements in XML have an OPENTAG and an ENDTAG. The language is specially designed for organizing (encoding) data, necessitating that it be entirely declarative. No guesswork for the parsing engine. A single error and nothing happens.
Step forward in time a couple of years and XML meets HTML in a language that conforms to the special requirements of XML strictness… XHTML.
When authors were looking at compliance issues in HTML the biggest one was the void tags that were scattered throughout the language. That’s the old term that describes empty elements. XML would require them to have an ENDTAG to conform. The writers of XHTML arrived at a compromise, space slash would tell the parsing engine to insert the endtag in the DOM without making it a requirement to page authors. Thus, the bridge was built, on this spec, at least.
The self-closing tag was born. Browsers could look up the namespace where the codebase resided (that was written in the rather complex DOCTYPE) and be able to interpret the tags into,
which would conform with XML requirements.
Fine and good for a few years until web applications became mobile apps that we see today. To bring XHTML (and HTML in general) into that world, writing groups worked tirelessly on beefing up the standard for HTML and CSS (and JS). Enter, HTML5 and CSS3 around 2005ish, and ES5 around 2009.
HTML5 working groups actually created two forms of HTML. One that would behave like XHTML, and one that would behave like HTML. The DOCTYPE is simplified to name just the root element,
html, and the namespace is determined by the manner in which the document is served out (its MIME type).
application/xml => served as XML conforming, so validating as XHTML (roughly)
text/html => served as text, so validating as HTML 4 (roughly)
If some lesson authors are expecting the slash, then give it to them. If not, then forget it. Not needed when we consider we are writing text/html markup.
HTML5 went one step further. They got rid of the requirement for the space. (Why the space was there in the first place is a story in itself, to be learned in studying the history of XHTML).
is valid HTML5, XML compliant.
For serving as text/html,
is valid, and all we need concern outselves with here (for the most part).
The default MIME type is `‘text/html’ so we don’t need to declare it unless serving it as application/xml. A site so oriented would decalre the MIME type on the server, so still would not be needed in the site’s pages. If the server configuration is inaccessible, then we would need a declaration in the source HEAD of the document.