Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
5.00/5 (5 votes)
See more:
Why is DIV better than TABLE?

I am very old and have used tables for yonks, but was told off recently.
Just wondering the reason why.
Posted
Updated 25-Aug-16 2:25am
v2

 
Share this answer
 
A lot of it depends on whether or not you want to reposition items; also, do you want your items to be able to be read using a screen reader. Screen readers generally have a terrible time with tables because they can end up reading things out of the order you intend them to be.

It all boils down to, use the tool that's appropriate for the job. If you want to display data as in a spreadsheet, use a table - positioning divs to do this is just a nonsense. If you want to reposition content or have a site that is more SEO friendly then consider using DIVS (SEO can also suffer the same issue as screen readers).
 
Share this answer
 
Dalek Dave wrote:
Why is DIV better than TABLE?


It isn't inherently. Tables are better at displaying tabular data. Divs are better at creating sections within your page. So it's horses for courses.

Dalek Dave wrote:
Just wondering the reason why


This is the subject of one of the many internicene wars in IT. The pro-div contention (and the one I agree with) is that, you can readily skin your HTML any way you want using CSS. Take a look at http://www.csszengarden.com/[^] (SFW), and look at the several desgins. This is the same HTML with different css applied. It also helps separate out the styling from the markup.

That said, for many applications tables are just simpler to implement.
 
Share this answer
 
Here[^] is a little helper also.
 
Share this answer
 
Comments
Dalek Dave 7-Jun-10 11:14am    
Thanks! :)
For Tabular data, Table is best. but we can handle DIV dynamically in JavaScript easily like show/hide/position/etc. I'm always using Table inside a DIV.
HTML
<DIV ID="divData">
 <Table>
  <Tr>
   <Td>blah blah</Td>
   <Td>blah blah</Td>
  </Tr>
 </Table>
</DIV>

<a href="javascript:hidediv()">hide div</a>
<a href="javascript:showdiv()">show div</a> 

function showdiv() {
document.getElementById('divData').style.visibility = 'visible';
}
function hidediv() {
document.getElementById('divData').style.visibility = 'hidden';
} 
 
Share this answer
 
v2
Thanks, it seems I am not alone in wondering!

I suspect further reading is advisable, something to do this evening.

I must admit I prefer tables as I can picture in my mind how something will appear before I start doing it.
 
Share this answer
 
when you use table , pages are display until all data are loaded,but in case of div it shown as it get loaded inspite of all page data.so conclusion is response time for div is faster as compare to table.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900