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..
5 ответов
+ 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="">
+ 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.
+ 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.
+ 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
+ 1
ok. thanks for the link