Html tags | SoloLearn: Learn to code for FREE!


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..

1/13/2017 2:54:09 PM


5 Answers

New Answer


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="">


<br> is the official spec for HTML5 ( Both <br> and <br/> are OK for HTML. <br /> is for XHTML. But I think </br> is not valid for either language, though.


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.


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


ok. thanks for the link