<br>
or </br>
Which one should we use for a line break? Furthermore, which is correct <hr />
or <hr>
I tried both tags, and it shows the same results. Nevertheless, I am perplexed as on an online platform they say using </br>
will be best compared to <br>
. Furthermore, it is necessary to use space in <hr />
or we can simply write <hr/>
.
2
Answers
<br>
is fine;<br/>
works but the / is pointless.</br>
is nonsense.Similarly,
<hr>
works,<hr/>
works but the / is pointless.Now, some contexts require XML-like tag closing, so sometimes
<br/>
is what you want, but HTML5 parsers do not care.Both
and
are used to create a line break in HTML, but their usage and compatibility can differ slightly.
"
" This is the original and traditional way of writing a line break in HTML. It is an empty tag that doesn’t require a closing tag. You can simply use
to indicate a line break.
example:
This is the first line.
This is the second line.
: This is a self-closing version of the line break tag that is compatible with XHTML, a stricter version of HTML. It’s also valid in regular HTML, but it’s less common and not necessary.
example:
This is the first line.
This is the second line.
above summary : you can use
for a line break in HTML. If you’re using XHTML or want to be consistent with XML-style self-closing tags, you can also use
.