Forum Moderators: open

Message Too Old, No Replies

<br /> OR <br/>? (XHTML)

Space or no space

         

Birdman

5:18 pm on Jul 31, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I learned XHTML about a couple years ago and I could swear that you were supposed to add an extra space before the closing slash on empty elements.

<img src"=..." alt="" />
<hr />
<br />
etc...

So, I'm perusing the W3C specs to figure out what to do with a <param> tag that I'm getting errors on, and guess what I see?

Empty elements must either have an end tag or the start tag must end with />. For instance, <br/> or <hr></hr>. See HTML Compatibility Guidelines for information on ways to ensure this is backward compatible with HTML 4 user agents.

CORRECT: terminated empty elements

<br/><hr/>

INCORRECT: unterminated empty elements

<br><hr>


[w3.org...] (section 4.6)

What gives?

GaryK

5:41 pm on Jul 31, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can't find the thread where we discussed this awhile back. The space is necessary to accommodate some browsers that do not otherwise properly recognize a self-closing tag.

ADDED: Since the leading white space is irrelevant in terms of validation I think the distinction is meaningless in terms of adherence to the standards. Both methods will validate in all the validation checkers I've ever used.

Span

5:50 pm on Jul 31, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Include a space before the trailing / and > of empty elements, ...

is on the same page: [w3.org ]

encyclo

1:34 pm on Aug 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you're doing "real" XHTML with the mime-type
application/xhtml+xml
, then you should use the version without the space. The space is required when serving the markup to legacy browsers with the mime type
text/html
, as some older browsers crash when encountering the version without the space.

When you leave a gap and serve the file as

text/html
, the slash is considered by the parser as an invalid attribute and discarded.

Birdman

1:46 pm on Aug 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks all! I thought I had lost my mind.

Birdman