Recently, I was building a small HTML page and stumbled upon something simple: I needed a line break.
I knew that the <br> tag does that, but then I noticed that many people write
<br/> instead. The slash at the end confused me, so I decided to figure out what the difference is.
At first, I thought one of these options might be outdated or that browsers treat them differently. But the more I researched, the more confused I became. Eventually, I sorted it all out - here is what I learned.
No actual difference in how they work
When you write:
Hello<br>
world!
and when you write:
Hello<br/>
world!
The page looks exactly the same. Browsers treat both versions as the same line break.
This surprised me because I expected some kind of difference. But the real story is more about standards than rendering.
So why are there two versions?
After reading several articles, I found out that it all depends on the standard you are using.
In normal HTML (which everyone uses today)
The correct version is simply:
<br>
The <br> tag is a void element - an element that cannot have any content.
Because of that, there is nothing to close, so the slash is unnecessary.
In XHTML - you need <br/>
There used to be a stricter variant of HTML called XHTML, which followed XML rules. XML requires either a closing tag or a self-closing form:
<br/>
That's why <br/> existed: it was required in XHTML.
And that habit simply carried over into modern HTML, even though browsers no longer need it.
Browsers don’t care - but the standard does
Modern HTML5 officially uses only <br>.
The version with a slash is tolerated purely for backward compatibility, but it has no special meaning.
What should you use today?
-
If you're writing HTML5 - use
<br> -
If you're working with old XHTML markup - use
<br/>
Since XHTML is mostly gone today, the version without the slash is the standard choice.
My personal takeaway
It’s funny, but I spent almost an hour trying to understand a simple line break tag. On the surface there’s no difference, but it feels good to finally understand what’s happening “under the hood.”
Now, whenever I see <br/>, I know it’s just a leftover from older standards, not some special HTML trick.
If you want, I can also break down other HTML tags in the same simple, beginner-friendly style.
Top comments (0)