What is the difference between <br></br><br /> tag in HTML
tag in HTML
<br> <hr> <meta>
html
<br> <hr> <meta name="keywords" content=""> <link rel="canonical" href="http://www.google.com/">
xhtml
<br /> <hr /> <meta name="keywords" content="" /> <link rel="canonical" href="http://www.google.com/" />
Not all tags can be self closed. For example, <script src="jQuery.min.js" />
is not allowed by XHTML DTD.
<br> is typically used in HTML while <br /> is used in XHTML which has a stricter syntax.
HTML <br> Tag :-
- It inserts a single line break .
- It is an empty tag without any end tag.
The main difference between <br> and <br\> is :
In HTML (up to HTML 4): use <br>
In HTML 5: <br>
is preferred, but <br/>
and <br />
is also acceptable.
In XHTML: <br />
is preferred. Can also use <br/>
or <br></br>.
<br /> is backwards-compatible with XHTML and well-formed HTML (ie: XHTML) is often easier to validate for errors and debug.
NOTE: <br></br>
is valid in HTML 5, it will be thought of as two line breaks .
- If you are serving HTML5 as XHTML (i.e. content type application/xhtml+xml, with an XML declaration) then you must use a self closing tag like so:
<br/>
.
https://www.quora.com/What-is-the-difference-between-br-and-br-tag-in-HTML-Which-one-should-we-use
—
A lone <br>
is invalid in XHTML, since XML documents must close each tag they open. <br />
is semantically the same as <br></br>
in XML documents, and is referred to as a self-closing tag, so <br />
is used when writing XHTML, or HTML documents that will be read by an XML parser.
This applies to all other tags that do not have a closing tag in HTML, such as <hr />
and <meta />
.
Both are valid HTML, so there is no reason not to use <br />
, unless you are writing for a broken HTML parser.
—
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.
—
Simply <br>
is sufficient.
The other forms are there for compatibility with XHTML; to make it possible to write the same code as XHTML, and have it also work as HTML. Some systems that generate HTML may be based on XML generators, and thus do not have the ability to output just a bare <br>
tag; if you’re using such a system, it’s fine to use <br/>
, it’s just not necessary if you don’t need to do it.
Very few people actually use XHTML, however. You need to serve your content as application/xhtml+xml
for it to be interpreted as XHTML, and that will not work in old versions of IE – it will also mean that any small error you make will prevent your page from being displayed in browsers that do support XHTML. So, most of what looks like XHTML on the web is actually being served, and interpreted, as HTML. See Serving XHTML as text/html Considered Harmful for some more information.
—
Some elements, however, are forbidden from containing any content at all. These are known as void elements. In HTML, the above syntax cannot be used for void elements. For such elements, the end tag must be omitted because the element is automatically closed by the parser. Such elements include, among others, br, hr, link and meta
HTML Example:
<link type="text/css" rel="stylesheet" href="style.css">
In XHTML, the XML syntactic requirements dictate that this must be made explicit using either an explicit end tag, as above, or the empty element syntax. This is achieved by inserting a slash at the end of the start tag immediately before the right angle bracket.
Example:
<link type="text/css" href="style.css"/>
Authors may optionally choose to use this same syntax for void elements in the HTML syntax as well. Some authors also choose to include whitespace before the slash, however this is not necessary. (Using whitespace in that fashion is a convention inherited from the compatibility guidelines in XHTML 1.0, Appendix C.)
—
In HTML (up to HTML 4): use <br>
In HTML 5: <br>
is preferred, but <br/>
and <br />
is also acceptable
In XHTML: <br />
is preferred. Can also use <br/>
or <br></br>
Notes:
<br></br>
is not valid in HTML 5, it will be thought of as two line breaks.- XHTML is case sensitive, HTML is not case sensitive.
- For backward compatibility, some old browsers would parse XHTML as HTML and fail on
<br/>
but not<br />
Reference:
—
https://stackoverflow.com/questions/1946426/html-5-is-it-br-br-or-br
https://www.w3schools.com/tags/tag_br.asp
https://www.sitepoint.com/community/t/should-i-use-br-or-br/215994/7
Do not use
<br>
to increase the gap between lines of text; use the CSSmargin
property or the<p>
element.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/br