<div class='clear'></div>
/*which comes out to be below one in FF (seen via firebug) */
<div class='clear'/>
/*is this the last empty div declaration is semantically valid ? */

- 914,110
- 126
- 1,211
- 1,335

- 572
- 6
- 21
-
i am talking about XHTML – Gaurav Mishr Nov 17 '09 at 12:44
-
@Gaurav: then go for the former one. `` – Rakesh Juyal Nov 17 '09 at 12:46
7 Answers
In XHTML, the construct is valid (and identically equivalent to your original source) but not HTML compatible.
HTML compatibility doesn't matter when it comes to viewing a representation of the DOM as seen by the browser. It does matter when writing markup.
As an aside, adding empty elements purely for styling purposes is ugly and should be avoided if possible. See http://www.ejeliot.com/blog/59 for some alternative methods for containing floats.

- 914,110
- 126
- 1,211
- 1,335
If you're asking if those two tags are equivalent and valid: yes, yes they are.
See this question for practical considerations.

- 1
- 1

- 12,458
- 3
- 39
- 44
-
1Not for pure HTML, though. There the latter one would be utterly invalid :-) – Joey Nov 17 '09 at 12:34
-
-
I switched away from XHTML in 2002 when I came to the conclusion that writing HTML compatible XHTML was more trouble then it was worth when I could just write HTML instead. – Quentin Nov 17 '09 at 12:50
-
What's the benefit to writing HTML-compatible XHTML? (Most of the things I do on the web use only simple (X)HTML constructs, I'm not an expert in this area) – Cory Petosky Nov 17 '09 at 12:59
-
1HTML compatible XHTML works when you serve it as text/html. If you use the correct content type (application/xhtml+xml) then Internet Explorer will ask if you want to open it in another application or save it to disk. – Quentin Nov 17 '09 at 13:00
Yes, why wouldn't it be?

- 71,481
- 13
- 158
- 186
-
-
@Crises of Identity - agreed if it's XHTML, but that wasn't specified. – David M Nov 17 '09 at 12:33
A DIV is a block level container. The second example can't contain anything... so my bet would be no (for an HTML4 doctype)
If you want to use a dummy element for clearing purposes - have you considered <br />
?
Edit
There are more effective ways of clearing than using using a block level container. Applying a clear class to <br />
is one example - but 'overflow: hidden' on the parent element is usually much more elegant.

- 8,876
- 3
- 25
- 34
-
A div does get used to clear in a container. If you have items floating, without a clearing div your container will not expand to the height of the floating divs within it. So yes, a div like this is useful, and yes I believe this is valid syntax. – Zoidberg Nov 17 '09 at 12:32
-
yes i have considered
too but i was wondering forCool ! stack overflow is damn fast– Gaurav Mishr Nov 17 '09 at 12:32 -
1@Zoidberg: there are more effective ways of clearing than using using a block level container. Applying a clear class to
is one example - but 'overflow: hidden' on the parent element is usually much more elegant. – codeinthehole Nov 17 '09 at 12:36 -
We never stop learning! I took a course and the CSS instructor had said to use a DIV, he was a smart guy, but perhaps being a CSS guy, you don't have your head in HTML standards as much. – Zoidberg Nov 17 '09 at 12:48
-
Basically, I think there are many ways of achieving the same thing - preference comes into it, but there are core principles that are worth sticking to. One that I like to follow, is to try to use mark-up only for marking content .. which had always made me feel using extra syntax for clearing was undesirable, so I avoid doing so whenever possible. I don't envy people who are instructing on courses, because available techniques move so quickly. – codeinthehole Nov 17 '09 at 12:59
Whether this is valid or not depends on the DOCTYPE of the document you are writing. I would suggest to get a definitive answer you try the here:

- 1,763
- 1
- 13
- 32
<div class='clear'></div>
and
<div class='clear'/>
both are same. Though i prefer former one over the later.

- 35,919
- 68
- 173
- 214