Should we use <br>
or </br>
to create a line break? And what about the <hr>
tag, should it be written as <hr />
or just <hr>
?
I tested both <br>
and </br>
, and they seem to render the same. However, some online sources suggest that </br>
is better.
I’m a bit confused, especially regarding self-closing tags like <hr />
. Is spacing required in <hr />
, or is <hr/>
also acceptable?
What’s the correct and modern way to use the br tag and similar HTML elements?
Good question! The correct way to insert a line break in HTML is just <br>
.
You don’t need </br>
, in fact, that’s invalid HTML. <br>
is a void element, meaning it doesn’t have a closing tag. Same with <hr>
.
So the modern, valid way is simply <br>
and <hr>
.
If you’re writing XHTML or want to ensure stricter XML compatibility, you can use <br />
and <hr />
(with a space before the slash).
That’s why some sources recommend it. But in regular HTML5, both <br>
and <br />
work the same. The space in <hr />
isn’t necessary but makes it slightly more readable.
Also, I’ve seen folks use </br>
, and it’s a common beginner mistake - but it’s incorrect. Browsers are forgiving, so you don’t always see errors, but technically that’s invalid HTML.
Stick to <br>
for breaks and <hr>
or <hr/>
for horizontal rules. I usually prefer <br>
and <hr>
for cleaner, more modern-looking code.