0

When should I use one or the other?

At a previous time I learned that a line break is <br>. Through the tutorial, once I reached line break it was taught as <br />. After this I clicked "try it yourself" to test if my previous knowledge worked, and it did. Googling it made me see that one goes for HTML other goes for XHTML, -EXCLUSIVELY- Question is - Is the statement "<br> works only in html, and <br /> works only in xhtml" true when the browser that interprets the code can read only html or xhtml, and not both? What I mean is that when I "try it yourself" both worked. So when do they not work, and when should I use one or the other?

17th Apr 2018, 6:16 AM
Belcone
Belcone - avatar
2 odpowiedzi
+ 7
Andrei Belcu <br> is all the browser needs to parse correctly. <br /> makes it compatible for loading in XML parsers and is often what gets written when being generated from an XML parser. It doesn't hurt to use <br />, but it isn't required. Personally, due to all my XML work from years ago, I use self closing br tags out of habit.
17th Apr 2018, 6:27 AM
David Carroll
David Carroll - avatar
+ 2
In HTML5 <br> don't need to be closed. I mean no need for <br/>
17th Apr 2018, 6:24 AM
Akib
Akib - avatar