HTML - Why use, or not use, "/" to close tags without content? [duplicate]

0

I noticed that it's common to see some Void element tags with closing />

Ex:

<br />
<hr/>
<meta name="twitter:domain" content="pt.stackoverflow.com"/> 

And right here in the StackOverflow source I found <input> with and without tag closing ...

Ex:

<input id="author" name="author" type="text">
<input type="submit" id="pin-site-btn" value="Adicionar" disabled="disabled"/>

From what I've seen, it seems that in HTML5 the Browser ignores this / in tags that do not need to be closed like the ones above. (Unlike Div for example that should be closed <div>...</div> )

So if the browser ignores this, and if usage is not mandatory, why is it so common to see void-elements closed this way / > for no apparent reason?

NOTE: In the same article, in HTML Setup, you have <link> with and without / > link

W3C Void Elements Reference link

    
asked by anonymous 15.01.2018 / 13:21

2 answers

1

The idea of closing the childless tags comes from XML, in a proposal to unify the two languages by creating XHTML. However, from what I know, this has not gone forward - nor has this requirement been adopted in HTML5.

Therefore, closing these tags is not required, but it is optional if you wish to do so. I always do, for "aesthetics" same, but it is not necessary.

(Note that if the tag is not one of those listed as "childless", not closing is an error - even if the browsers "come" to interpret the content for you, but in this case, closing should be given by a different closing tag)

Excerpt from our colleague: mgibsonbr here from StackOverflow

    
15.01.2018 / 13:29
0

Tag closing comes from HTML5, so if you're developing a website using HTML5, it's important to close the tags. It is important to develop already with the standard of HTML5 because it may be that browsers no longer support old versions of HTML, thus making it mandatory to use tag closing.

    
15.01.2018 / 13:27