Friday, 13 April 2012

DIV vs TABLE tag: Which one to use?

<div> is the professional way of designing the webpage. It provides flexibility in web designing as you can make any kind of design using CSS. But the problem with CSS is that, its debugging is not easy and people find it hard to learn. That’s why they stick to <table>.<table> is easier to learn and implement as you have to only figure out the layout of rows and cells.

Tables were originally meant for tabular data like displaying a grid etc. Soon the developers realized that tables can also be used to format other data by setting border="0" and hiding the borders.

One limitation with using table is that, if whole page is designed under a single table, the page will not load until whole table is rendered by browser and the situation becomes worst when you use nested tables but same is not with using div.

Second limitation with table is SEO (Search Engine Optimization). Tables work fine for small web pages. But if the page contains a lot of data and sections, tables start nesting themselves and structure become creepy. SE spiders and bots when go on crawling the webpage, they find it difficult to pick actual content from that messy page and as a result indexing of that webpage is affected.

An analogy would be: I sometimes use a knife to open a screw (When I can't find a screwdriver). Knives were not built for this purpose but I can reach the ultimate goal of opening the screw. Now if I just put some effort in finding my screwdriver then opening the screw might be a little easier.

Browser Compatibility issue arises with both div and table. Mozilla and Chrome behaves same but IE6 (and above), Opera, Safari, Netscape may interpret CSS differently.

17 comments:

  1. The idea of there being some kind of 'non-professional excuse for tables' might have been true, 5 years ago.

    Debugging CSS is now very easy. All browsers now come with great tools for inspecting and visualising pages, and doing experimentation. Firefox even has a 3D visualiser now, to see how a page is constructed using a 3D viewer.

    Tables are arguably more unstable than CSS now. Some browsers align borders differently to other browsers (some put collapsed borders half a pixel each way around the extents of the box, some shift the table to show the border). That can cause weird problems with overflows and alignment. Different browsers handle column width differently, with respect to the col tag, width attributes, and applied CSS. There are options to control stretching (table-layout in CSS) but they are not applied consistently with respect to the different ways of setting widths. There is great scope for setting contradictory dimensions for cells, and the browsers may not agree on how to resolve that.

    IE8 and above are highly standards compliant. We're nearly on IE10, so supporting more than 3 versions old makes no sense anymore.

    Opera is extremely standards compliant and behaves just like Mozilla and Chrome, and IE8/IE9/IE10.

    The old things tables were useful for are not necessary since IE7. CSS2 was hard because it lacked a few key things. CSS2.1 and CSS3 have filled all theholes. We now have 'min-width' and 'min-height' in CSS which was pretty much the only useful thing left for a fake table tag.

    If people find CSS hard to learn, they really have no business doing web pages for anyone other than themselves. It really isn't, and I'd expect anyone working with web pages to have the basic skills.

    ReplyDelete
  2. Tables, are you serious? Don't give up the day job son.

    ReplyDelete
    Replies
    1. Many times when I try to use a DIV to do something I previously did with tables, I spend quite some time searching for that "just right" magic CSS potion to make it work, only to find out that it has some caveats (doesn't work with IE, or only works if column one is shorter than column two, etc, etc). Having learned how to use DIVs has, at least in some cases, made me long for the use of TABLE for its functionality. DIVs need improvement.

      Delete
  3. "The HTML table model allows authors to arrange data — text, preformatted text, images, links, forms, form fields, other tables, etc. — into rows and columns of cells."

    "Tables should not be used *purely* as a means to layout document content…"

    http://www.w3.org/TR/html401/struct/tables.html

    Arranging content clearly means layout. W3C suggests using style sheets, they do not however renounce tables as a method to apply layout.

    Oh and yes there are a couple of cases that cannot be easily solved without tables and extensive hacks. These are columns with dynamic equal height and vertical alignment. Use the best tool for the job.

    ReplyDelete
  4. table is more easy to learn.

    ReplyDelete
  5. I found a good post that talks about using divs over tables to future proof your website. With the increase number of people using mobile devices to browse the web, your website needs to be able to automatically adapt to fit the devices its been viewed on.

    http://www.limelightonline.co.nz/blog/using-divs-layout-your-site-more-important-than-think/

    ReplyDelete
  6. there is always this discussion... div vs table and there are table haters using divs with display table-cell to get same results... there are situations you will stick to tables, even for layout purpose...just like facebook does with its like-plugin iframe.

    ReplyDelete
  7. Play the Best Free Games! We've picked out the racing games, cooking games, candy crush, games shooting, fashion games, ...
    Thanks for sharing !
    Kizi 200
    Friv 1
    Y88
    Y9

    ReplyDelete
  8. You want to relax after a stressful working hours. Refer to our website. hope you get the most comfort.
    Thanks for sharing !
    Friv 100
    Friv 8
    Friv 2

    ReplyDelete
  9. You want to relax after a stressful working hours. Refer to our website. Hope you get the most comfort.
    Thanks for sharing !
    GirlsGoGames
    Kizi 100
    Frvi

    ReplyDelete
  10. invites you to play games for a chance to win cars Corolla Altis car

    Friv Games
    Kizi 100
    Games2Win
    Kizi 5

    ReplyDelete
  11. You need to have time to take care of the kids active. Please visit our website and play exciting flash games.
    Thanks you for sharing!
    Games2Girls
    Kizi 1000
    Frin
    Friv 3

    ReplyDelete
  12. Thanks for sharing this good stuff! Keep up the great work, we look forward to reading more from you in the future!
    Friv 100

    ReplyDelete
  13. Games are games of human intelligence.
    Join experienced talent with me yet! What are you waiting for?
    age of war 2
    gold Miner 2
    unfair Mario 2
    cubefield 2
    tanki Online 2

    Friv Games
    Y2
    Friv 200

    ReplyDelete
  14. Work anybody but take some time to relax every day work efficiency will be higher than that. Invite you to visit our website

    Friv 1
    GirlsGoGames
    Friv 4 School

    ReplyDelete