Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why is <br /> different from <br></br> in XHTML?

Tags:

html

xhtml

Here's the complete source of an HTML page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
           "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head></head>
<body>
one<br>
two<br />
three<br></br>
four    
</body>
</html>

Can anyone explain why an extra blank line appears between the "three" and the "four" when I view the page in IE8 or chrome?

I thought standards were supposed to make all browsers look the same and as far as I can see this page conforms to the XHTML transitional standard

like image 581
Andy Avatar asked Nov 28 '22 22:11

Andy


2 Answers

Because the XHTML spec HTML Compatability Guidelines specify that br must should be self closing. Apparently Chrome and IE8 are not follwing the spec and closing the open one for you, thus creating a second line break.

like image 125
Rob Stevenson-Leggett Avatar answered Dec 04 '22 07:12

Rob Stevenson-Leggett


Some good answers already, but just to point out that HTML5 actually specifies that <br></br> should be parsed as two <br> start tags when parsing as text/html.

See An end tag whose tag name is "br" in http://dev.w3.org/html5/spec/tokenization.html#parsing-main-inbody

Firefox 3.x only does this in quirks mode, but Firefox 4 does this in Standards mode as well.

like image 43
Alohci Avatar answered Dec 04 '22 05:12

Alohci