WebGUY
WebGUY

Reputation: 101

Divs vs tables for tabular data

Yes, another divs vs tables questions...

I read all over the place that "try to use divs instead of tables", but I have an application that displays data that is tabular, basically my entire web application displays tables (with different columns and data) but everything is tabular... Should I use struggle to use divs? If yes, why?

Upvotes: 10

Views: 7108

Answers (6)

anw
anw

Reputation: 410

No! If tables were not to be used at all for your code, they would have been taken out. Tables have a proper use, and that use is for tabular data! This is the time to use them (not for presentation or design). So by all means, use tables!

I would recommend to provide a caption tag within your tables to give people who may be using screen readers (such as blind Web surfers) proper context, too.

Example:

<table>
    <caption>Corporate Information of Current Employees</caption>
    <tr>
        <td class="employeeName">Jim Jones</td> 
...

Don't be afraid of current trends. Tables should be used for tabular data. You're doing it right :)

Dive Into Accessibility offers a lot of helpful tips, as well.

Upvotes: 6

Mo Valipour
Mo Valipour

Reputation: 13496

Don't use tables for your "LAYOUT" because of many reason you've already found on web. But for displaying "DATA" you still can use tables.

most of server side scripting languages like ASP.NET generate tables for gridViews so they are not "Absoutely wrong to use".

For layout I recommend you going through different insteresting layouts people have designed for a "Single HTML" in CSS Zen Garden.

Upvotes: 2

daveoncode
daveoncode

Reputation: 19588

No, you MUST use tables for tabular data! Tables exist for that purpose, you MUST avoid tables only for layout purposes by using divs instead.

Upvotes: 2

kinakuta
kinakuta

Reputation: 9037

Use tables for tabular data. The knock against tables has been when they've been used solely for layout purposes. They have their own purpose, and it's tabular data. Divs have no semantic meaning, and shouldn't be used for tabular data.

Upvotes: 30

Denis Biondic
Denis Biondic

Reputation: 8201

There is nothing wrong with tables correctly marked with CSS. For tabular data, tables are natural choice, don't try to emulate them using divs; except in few cases where divs can be cleaner.

Divs and tables are both just tools at your disposal. Learn when to apply right tool for the right job.

Upvotes: 3

Saad Imran.
Saad Imran.

Reputation: 4530

I don't think you should struggle to use div's because I personally wouldn't but maybe this will help.

Why not use tables for layout in HTML?

Upvotes: -1

Related Questions