views:

1349

answers:

7

I've frequently seen a space preceding the closing slash in XML and HTML tags. The XHTML line break is probably the canonical example:

<br />

instead of:

<br/>

The space seems superfluous. In fact, I think that it is superfluous.

What is the reason for writing this space?

I've read that the space solves some "backwards compatibility issues." Which backwards compatibility issues? Are those issues still relevant, or are we still adding extra spaces for the sake of, say, IE3 compatibility? Does there exist some spec with the definitive answer on this?

If not backwards compatibility, then is it a readability issue? Similar to the Great Open Curly Brace debate?

void it_goes_up_here() {

int no_you_fool_it_goes_down_there()
{

I can certainly respect differing stylistic opinions, so I'll be happy to learn that writing the space is simply a matter of taste.

A: 

I think that the white space is a way to reinforce the idea that this tag is empty and it closes itself.

Today i don't use the white space anymore because i never had a problem with no white space.

nicruo
"reinforce" is an apt word for "strong"
Hao
thanks for notice that. it's good to see that here we have people to ensure the quality of writing.
nicruo
+2  A: 

In XHTML, br tags must be closed, but the space is not necessary. It's a stylistic thing. In HTML, br tags cannot be closed, so both are wrong.

Pesto
+3  A: 

No, the space is not required but it is necessary for some older browsers to render those tags correctly. The proper way to do it is without the extra space as this is something XHTML inherited from XML.

Andrew Hare
Which older browsers specifically? I'm interested in learning whether we're talking about browsers with significant market share.
Greg Mattes
We're not. IE5 and older mostly.
jmucchiello
A: 

For me, it depends on what visual studio makes with my HTML/XML :-) It is not consistent, but it does not matter from a functional view (it's only a matter of style).

M4N
A: 

The space just makes the tags more readable. I am a big proponent of formatting for more readable code. Little things like that go a long way. Without the space the closing tag blends in with the opening tag. It takes just an instant longer for me to process it as I am quickly reading the code.

Jim Petkus
+11  A: 

The answer is people wish to adhere to Appendix C of the XHTML1.0 specification. Which you only need to do if you are serving XHTML as text/html. Which most people do, because XHTML's real MIME type (application/html+xml) does not work in Internet Explorer.

No current browser cares for the space. Browsers are very tolerant of these things.

The space used to be required to ensure HTML parsers treated the trailing slash as an unrecognised attribute.

Lee Kowalkowski
Can you be more specific about "used to be?" Year and/or browser version will do, thanks!
Greg Mattes
I think that http://www.w3.org/TR/xhtml1/#C_2 is a more precise link for this answer. So, it seems that XHTML 1.0 Appendix C2 is effectively obsolete and that writing the space is purely a matter taste.
Greg Mattes
Sorry, used-to-be, means "is" - with respect to making sure a HTML parser treats the trailing slash as an unrecognised attribute, not all HTML parsers are browsers. I wouldn't like to hazard a guess which browser version choked if any, but I don't remember IE4 or Netscape 4 complaining.
Lee Kowalkowski
actually the real mime type is application/xhtml+xml.
Mk12
Oh yes, didn't look it up and I never use it, because IE still chokes!
Lee Kowalkowski
+7  A: 

Are those issues still relevant or are we still adding extra spaces for the sake of, say, IE3 compatibility?

You were close - it is for Netscape 4.

It is interesting to see other rationalisations, but that's all it was meant for.

bobince
Thanks! Can you provide a reference for this?
Greg Mattes
Hmm, difficult to find primary sources this old... official W3 materials avoid mentioning any one UA, and discussion in the lists seems to take the situation as read. There probably were other UAs that also needed the space, but N4 was the last one, that caused webmasters trouble for years.
bobince