Are the space and the / required in the <br /> tag?

I remember writing many a webpage without using / in the tag.

I have great news for you! You don't need no steenking / any longer. Again, I mean.

Why?

Because ...

What changed?

XHTML, an implementation HTML serialized as XML. XML has a very strict set of syntax requirements. One of those requirements is that you can't leave a tag open. The syntax <tag/> is called a self-closing tag, in that it opens itself and closes itself at once.

Also, is the space "required?"

One of the more interesting things about XHTML is that it's kind of backwards compatible with HTML. You can throw a legal XHTML document at an HTML parser and it should be able to make sense out of it. However, not all HTML parsers can do so. Old, old, prehistoric, no-longer-used versions of Netscape and other browsers would see the self-closed <br/> tag not as a br, but as a tag named br/, which is bogus. Putting a space before the forward slash became best practice.

There's a fatal flaw with XHTML. Because it requires the XML parsing rules, that also means it requires the XML error handling rules, which mandate that parsing halt immediately upon a syntax error. In other words, if there's a single parse error in the document, the browser must not show the document to the user.

That's kind of a show-stopper. XHTML served as XML never caught on because some browser vendors (like Microsoft) refused to add support due to the must-die-immediately nature of error handling.

XHTML still caught on because it was full of awesome best practices, even if the documents didn't end up being served as XML.

Now, earlier I said that you don't need it any longer. That is true for both HTML4 and the upcoming HTML5. They've gone through the effort of actually specifying how HTML5 should be parsed now, and that forward slash is going to be considered an error. Thankfully XHTML5 is a thing, and if you really want to use the XML syntax rules instead of the HTML5 syntax rules, you can go right ahead.


It's required for XHTML compliance:

Broadly, the XML rules require that all elements be closed, either by a separate closing tag or using self closing syntax (e.g. br /), while HTML syntax permits some elements to be unclosed because either they are always empty (e.g. input) or their end can be determined implicitly ("omissibility", e.g. p).

Read the section under the heading: "Relationship to HTML" for more info.


<br/> is used on pages with XHTML Doctype. The reason was that XHTML was based on XML and XML required all tags to have a closing tag.

like

<tag> </tag>

In the case where there was no closing tag (like single tags as <br>) XHTML requires the "/" for standard compliance.

As for the space: It is not required.

And when it comes to what changed. It is all about HTML itself. As HTML 5 gains more popularity every day people are using
.

In HTML 5 <br> is used. Also <BR> is acceptable too .

Tags:

Html