I\'ve tried checking other answers, but I\'m still confused — especially after seeing W3schools HTML 5 reference.
I thought HTML 4.01 was supposed to \"allow\" singl
IMHO it is better to use the regular notation (<br />
) instead of the forgiving notation (<br>
) for the following reasons:
In your HTML there is probably some SVG and SVG only support the regular notation (e.g. <rect />
).
It is not a case that frameworks like React and NativeScript use an XML notation.
Your markup code will be easier to parse.
The regular notation is easier to read and understand, even late at night.
Both <br>
and <br />
are valid HTML tags.
If you use a full-fledged text editor configure it to use the regular notation (which is called XHTML by Emmet).
For instance, in Visual Studio Code you just have to add the following line to your settings:
"emmet.syntaxProfiles": {"html": "xhtml"}
The elements without having end tags are called as empty tags. In html 4 and html 5, end tags are not required and can be omitted.
In xhtml, tags are so strict. That means must start with start tag and end with end tag.
<br>
is sufficient but in XHTML <br />
is preferred according to the WHATWG and according to the W3C.
To quote Section 8.1.2.1 of HTML 5.2 W3C Recommendation, 14 December 2017
Start tags must have the following format:
…
After the attributes, or after the tag name if there are no attributes, there may be one or more space characters. (Some attributes are required to be followed by a space. See §8.1.2.3 Attributes below.)
Then, if the element is one of the void elements, or if the element is a foreign element, then there may be a single U+002F SOLIDUS character (/). This character has no effect on void elements, but on foreign elements it marks the start tag as self-closing.
If you use Dreamweaver CS6, then it will autocomplete as <br />
.
To validate your HTML file on W3C see : http://validator.w3.org/
<br>
works just fine. The stricter versions like XHTML require you to add the closing, and really old versions of HTML that do not include a DOCTYPE
make <br>
a non-void tag, like <br></br>
.
Sum up: <br>
is fine. Other ones are also just fine.
works just fine in HTML5. HTML5 allows a little more leeway than XHTML
Just use <br>
. Do not use <br></br>
. <br>
is a special tag which doesn't need a closing unlike most tags.