Why does Firefox close HTML html tags?

I noticed in Firefox that when viewing a source, it adds closing tags to the null elements of the tag, such as <hr> and <img src="image.jpg"> . Viewing the source in Firefox, I see <hr></hr> and <img src="image.jpg"></img> . An HTML 5 document, not XHTML, and tags are tags that should not be strictly closed in HTML. So why is Firefox doing this?

+1
html html5 firefox tags
source share
2 answers

I assume that you are not only using a view source, but are using the Firefox Browser Inspector instead? This is because there must be an end for each tag, so the inspector explicitly shows this endpoint.

+1
source share

The code validation frames of both Chrome 55.0 and Firefox 50.0.2 show the img and link tags on this page without self-closing slashes and closing closing tags for me. (Details: I am running 64-bit Fedora 24, but would expect the same behavior on other platforms.)

You may have an older version of Firefox, but most likely the page you checked wasn’t the correct one! The DOCTYPE tag at the very beginning informs Firefox about how to interpret HTML5, which, as you pointed out, points to NOT close br, hr, img, input, meta, link and several other tags that MUST be in the document tree.

0
source share

All Articles