0

Html tags

Does it matter if I close tags using </p> or <p/> ? Will the script even run for the second or...? an error? just curious..

13th Jan 2017, 2:54 PM
V3num
V3num - avatar
5 Respostas
+ 4
It does matter, but it may be corrected by browsers, as they can understand ( may differ according to browser/os )... because only one is valid. They are two type of html ( xml ) tags basically: those who way have childs elements, and those who don't. <p> is from the firsts, so he must have a closing tag, which have only one syntax: </p>. The other one syntax ( <hr/>, <br/>, <img src="" alt=""/> and so on... ) is for elements which cannot have childs ( in case of <img> tag, the content link is defined in attribute ), and is just a shortcut ( instead <br></br> by example ). Furthermore, this was a syntax for Xhtml ( a previous version, more xml compliant ) who require it. In Html otherwise the shortchut ending slash isn't necessary ( but not embarrassing while tolerated by browsers ), and you could write valid: <br> <hr> or <img src="" alt="">
13th Jan 2017, 3:38 PM
visph
visph - avatar
+ 3
<br> is the official spec for HTML5 (https://www.w3.org/TR/html5/text-level-semantics.html#the-br-element). Both <br> and <br/> are OK for HTML. <br /> is for XHTML. But I think </br> is not valid for either language, though.
13th Jan 2017, 6:39 PM
Álvaro
+ 2
I guess that depends mainly on the browser, if it can skip these errors or not (most of them do, though) ("errors" meaning closing as <foo/>). It's a good practice to end properly the <foo> tags with </foo> tags whatsoever.
13th Jan 2017, 3:29 PM
Álvaro
+ 1
thanks guys. just trying to keep up the correct practice to avoid problems down the road. I heard HTML recognizes both <br> and </br> but HTML5 recognizes </br> only. or it could be the other way around. correct me if I'm wrong plz
13th Jan 2017, 5:54 PM
V3num
V3num - avatar
+ 1
ok. thanks for the link
13th Jan 2017, 10:39 PM
V3num
V3num - avatar