: Are the space and the / required in the tag? Back in the day, I remember writing many a webpage without using / in the tag. What changed? Also, is the space "required?"
Back in the day, I remember writing many a webpage without using / in the tag. What changed? Also, is the space "required?"
More posts by @Rambettina238
5 Comments
Sorted by latest first Latest Oldest Best
<br /> is still the most compatible tag form across all current browsers and doctypes. That's why you'll still see it used on sites like Wikipedia. Don't ask me why, ask Microsoft, Mozilla, Netscape, Opera, and the other browser vendors why their tag support is so bizarre.
<br /> is the most compatible because some mobile browsers require a closing tag whereas older desktop browsers fail on closing tags, hence the extra space as a compromise.
As has been said, the trailing slash is used to close empty elements (e.g. br, hr, img), and is required when writing pages using the XHTML doctype. The space is not required, but was commonly used since some older browsers (I think including Netscape 4) did not like empty elements having a trailing slash without the space. So the space became common use to accommodate the browsers that didn't fully understand XHTML. It's not required now.
<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 .
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.