tags:

views:

94

answers:

11

Hey,

I've noticed a variation of convention when it comes to using DIV tags instead of TABLE to separate/organize content on a web-page. In what situation is one more appropriate to use than the other?

Clarification: This question is both general, and specific in that I'm mainly looking for which would be more ideal for page layout.

Thanks.

+8  A: 

As a rule of thumb — if every cell in a row has something in common, and every cell in a column has something in common, then you should use a table. If you don't have a thead with some th elements providing column headings, then there is a good chance you are doing something wrong. If you don't have multiple data rows and multiple data columns, then … ditto.

The choice is, however, not between a div and a table. Use the markup that has the semantics that best describes the content. There are plenty of elements in HTML: http://www.w3.org/TR/html4/index/elements.html

David Dorward
+1 for mentioning that `div` isn't some kind of universal solution.
You
Sorry, I was a little unclear in the OP, I was mainly referring to which would be more ideal for page layout. I didn't mean to convey that they were the only solutions to organizing data in general.
Jengerer
A: 

IMHO, a table is for the display of tabular data and related things, not for general layout of a page itself.

Some do not hold this purist opinion, and so use tables for laying things out because they seem easy to use.

Andrew Barber
They think that tables are easier until using DIVs... So much simpler for page layout.
Saladin Akara
+2  A: 

Use tables only with semantically tabular data. Is each row other than the header representing the same "type" of "thing"? Does each column header have below it a set of items that are described accurately by the column header? If yes to both, then use a table. Avoid tables for styling whenever possible.

fearpi
A: 

Use div when you want to make your page more syntactically correct, use less bandwidth, make changes easily,make sites more accessible and more search engine friendly. In all other cases use tables (well except when you want to show some tabular data). Here are more details.

Teja Kantamneni
A: 

Well, as far as I know, a table is used to organize a group of objects into set places ... say three pictures side by side all separated by some text. And a is a "section" of a webiste. This can include anything, even tables! So I guess the answer to your question would be: if you need to set up an organized array of images, text, etc. you might want to use a table (like an excel spreadsheet), but if you simply want to divide your website into sections, use tags. By the way, as of late, tables are being used less and less and there seems to be a tendency to using different CSS layout techniques instead of tables. Good luck!

akseli
+1  A: 

Table should be used to display tabelaric data ( like in excel for example) When Div tag is a container and should be used to organize content.

You can drive a nail with a screwdriver but proper tool is a hammer.

zgorawski
A: 

What I see a lot (and my biggest pet peeve), is people using a single column table to separate page elements or lists. Like:

<table>
  <tr><td>
  List item 1 
  </td></tr>

  <tr><td>
  List item 2
  </td></tr>
</table>

instead of using <li>, <p> or <div> (if its more like content)

The moral, its fine to use table where thy make sense- tabular data, etc. Never for lists, blocks. People complain about using it for layout, but sometimes it just works so that is the only place I make an allowance for abusing tables.

James Connell
A: 

i use table only to display database fields and records. i mainly use div for page layout.

ricky
A: 

Simple.

Use a table for tabular data. Use a div to separate content.

Dan
A: 

Probably the only scenario where I'd use a table for layout over a div (other than for tabular data) is when creating HTML for an email. Emails clients aren't great at displaying HTML properly, so often using tables is the only way to get pages to display consistently.

It makes me die a little every time I have to do it :(

What
A: 

It does concern me that people are suggesting that table should be used for anything except tabular data, even in IE6. I think the only legitimate use of tables for non tabular data is in html emails, it's not the correct usage but the rendering in email clients is so awful you have little choice.

Semantics on your HTML have always been important, but I think it is only going to get more so especially with the new HTML5 tags that are being proposed... I can see more confusion over the use of article and section

DJ Forth