17

What is the main difference between <br> and <br /> in html markup? Can someone explain the main difference of the two because it's confusing to me. Thanks in advance for all of your comments. :)

5
  • 2
    <br/> = <br> + </br>
    – Drux
    Feb 14, 2015 at 5:13
  • @Drux <script/> = <script> + </script> its the same
    – ggtaetiseo
    Feb 14, 2015 at 5:17
  • Yes. In HTML <br> can also be serve as "abbreviation" for <br/>, which can cause mind confusion.
    – Drux
    Feb 14, 2015 at 5:18
  • 1
    This is very basic to HTML, you should read intro docs first. <TAG> is an open tag, </TAG> it's closing counterpart, some could be shorten by <TAG/> if their content is null. Using </TAG> without a corresponding open counterpart is undefined behavior. Feb 14, 2015 at 5:18
  • @Jean-BaptisteYunès thank you for your help topic closed
    – ggtaetiseo
    Feb 14, 2015 at 5:21

1 Answer 1

34

In practice, </br> does not exist. Just <br> or <br />.

However, the difference is the position, and is universal for all XML tags. <TAG_NAME> indicates the beginning of a tag, and </TAG_NAME> indicates the end of a tag. When a tag is used with nothing between it, then a self-closing, or null tag can be used, which combines the beginning and end. It looks like <TAG_NAME />.

In XML, any tag can be self closing, however, with HTML, only tags which are defined as such should be used that way. So you should never do <div />, instead you should use <div></div>, even if it's empty. Some self closing tags in HTML are, as already noted, <br />, also things like <param />, <input /> and <track />. You can view the full list here.

So, basically, elements in the link above are allowed to be self closing. They often have attributes to indicate their data, but no additional elements are allowed inside of them. Other elements, which can have additional elements inside of them require both <TAG> and </TAG> to be complete.

Note that under less strict rules, in HTML, self closing tags do not require the ending slash, so <br> is equivalent to <br />. However, the latter form is preferred, and much cleaner looking. Also, any tags that aren't self closing, that aren't closed property (i.e. has a </TAG>) will cause you a nightmare because elements will have a parent who should be a sibling.

Hope that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.