It's not a lot more than curiosity,
which is the difference between <br> and <br /> ?

I see both of them widely used and abused, are they completely interchangeable ?

Dani AI

Generated

Short version: the two notations are about different serializations, not different rendering. As and pointed out, the slash-style is the XML/XHTML-friendly form. In practice, when a page is parsed as HTML (most sites using the HTML5 doctype), browsers accept either form. If a page is actually served as XML (true XHTML), empty elements must follow XML well-formedness and use the self-closing form.

How to tell which applies to your page:

<!DOCTYPE html>

means the document will be parsed with HTML rules. If the server sends the document with the MIME type application/xhtml+xml, it is parsed as XML and you must use XML syntax. A quick check:

curl -I https://example.com/page | grep -i content-type

A few practical notes and troubleshooting tips:

  • Consistency matters for validation and tooling. Pick the style that matches your chosen doctype/serialization and stick with it across the codebase.
  • The historical habit of adding a space before the slash was mostly cosmetic or for older quirks; modern browsers handle the forms reliably. ’s comment points to that history but it’s not something to rely on today.
  • Prefer semantic markup and CSS for spacing and layout instead of forcing line breaks; use the line-break element only when a true forced line break is the right semantic choice (addresses, poems, narrow inline breaks, etc.).

For authoritative details about how browsers treat empty/void elements and how HTML vs XML parsing differ, see MDN’s notes on the line-break element and the HTML spec’s section on void elements: MDN — Line break element and WHATWG HTML — Void elements.

Recommended Answers

All 9 Replies

This <br> tag is best used in HTML format using( .html extension ) and this <br /> tag goes with XHTML (or .xhtml saved document ).

It's not a lot more than curiosity,
which is the difference between <br> and <br /> ?

I see both of them widely used and abused, are they completely interchangeable ?

<br/> is used in XHTML which is a much stricter form of html :) .

So in any case there are no cons using <br/> instead of <br> even in "simple" HTML ?
<br/> is the same withot space btw 'r' and '/' ?

<br/> <!-- or --> <br /> it doesn't matter as long as you are using it with the correct doctype.

<br/> <!-- or --> <br /> it doesn't matter as long as you are using it with the correct doctype.

I don't get it, can you please show me with an example the relation to the doctype?

This < LINK > will provide you brief information about doctypes.

The space is there in <br /> to make the self-closing tags compatible with IE 6 and earlier. IE renders it wrong without the space.

the main difference between <br > and <br /> is <br> is used html earlier versions and <br /> is used in the latest version like the below tags also

<img src="" > ------------- <img src=""  />
<b> </b>---------------- <strong> </strong>
<i> -------------- <em> </em>

Ok, so it's definitely better to use <br /> in any case from my pov...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.