Is there any problem in not putting "/" (slash) into auto-close tags?

5

When I was learning about HTML, I read that there are two types of tags , which are required to 'close', ( <tag></tag> , ex <div></div> ) and auto However, I came across an inconvenience (or not), which is the following, closing or not my auto-close tags, they work in the same way, for example:

>

This

<tag/>

It's the same as this (note that I did not close the tag with the toolbar)

<img src="#"/>

The same can be fixed in tags <img src="#" /> , <img src="#"> , etc.

My question is, what's the difference between closing or not these tags ? What risks do I run?

    
asked by anonymous 19.03.2014 / 18:47

2 answers

14

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 browsers "come" to interpret content for you .But in this case, the closing must be by a distinct closing tag.)

Notes:

  • Here is the spec snippet that talks about this type of tag. This question in SOEN also gives more information.
  • Also based on the above features, it should be noted that HTML5 <elemento /> is interpreted as simply <elemento> , not <elemento></elemento> as would be done in XML. So if you want to create a childless tag - when this tag children - do not use this simple form.
    • More specifically, / is allowed in types element void elements and foreign elements - elements that run away from HTML, such as SVG or MathML). In the former, it behaves as described, ignoring / . In others, it behaves as in XML, closing the element. Using / in an element that is neither void or foreign - such as div - is incorrect by specification.
  • 19.03.2014 / 18:51
    0

    If you are using XHTML with Java for example, Tags without closing require /> at the end, as well as attributes some attributes that need to receive as value their own name. In HTML there is no such need, however it is a good practice to include yes the closing, ex: <br /> <hr /> ...

        
    31.03.2017 / 09:47