Nervous Breakdown

Don’t replace tables with divs

Posted by: nervous on: November 1, 2006

How many times we’ve heard this phrase: stop using tables for layout, use divs instead?

This is the most common misleading phrase that can be told to a webdeveloper who still uses tables for layout.
Every standard-semantic acknowledged webdeveloper knows the downside effects of using divs as replacement for tables. Overuse of divs, commonly known as divitis, results in non-semantic markup as well as that of tables, probably worse.

When you design using tables, you implicitly say that your text or images or whatever you put on your page, is indeed data. This is because tables are meant to contain data. On the other side, divs are meaningless containers that implicitly mean nothing. So whatever you put in a div, is just some unidentified content.
That’s why I think we shall never say that tables can be replaced by divs in order to avoid confusion.

Table layout design, is not only common because of practical reasons, but mostly because very few webdevelopers truly studied HTML during their learning phase, only relying on its relative ease of use and on tag soup parser’s leniency (without even knowing they were exploiting it).

Ignorance of the meaning of each HTML tag together with the wrong attitude of exploiting tags presentational defaults values, gave us this legacy of br’s used to space blocks of text in table cells or whole tables and so on.
If we replace tables with divs, but we keep using divs the same way we used tables, semantic is still a mirage.

So divs, in the new course of correct, semantic markup, shall be used only when proper HTML tags cannot be directly addressed with style, or when several tags need to be grouped together. In addition to that, divs can be used, together with semantically wise ids and classes, when a proper HTML tag does not exist for the purpose.

Same thing when you hear someone saying that he wants to switch from a table based layout to CSS. Pretty much as saying you want to change your car’s (crappy) engine and chassis with a new colorful paint.

What webdevelopers should do to leave the dark side of tables layout and, more in general, of ignorant web-making, is to study HTML tags one by one, thoroughly, and reading and watching around how renowned webdevelopers use those tags in their websites. Once they have a proper understanding of the use of HTML tags, semantic and its uncountable advantages will pretty much come along straightforward.

There is nothing new in this brief post, and I certainly didn’t go too deep into the problem. Tons of similar information are available in the net, but according to many of my favorite authors, still not enough. I agree with that, and little by little, I will give my contribution.

8 Responses to "Don’t replace tables with divs"

Nice :D i totally agree

[...] I read this Plus I’m a noob, so I ain’t that good with DIVs yet…. Though I’ll give it a [...]

Wise up, you don’t have a clue what your on about! Using css (divs) allows for accessibility issues where using tables don’t, never mind the extra loading times ect!!! Read up at a list apart and many other sites online!!

Hi Micky, thank you for your contribution, I thought this blog was dead but hey, you never know. ;)

Anyway, would you mind extending your comment to explain what you mean?

It looks like you didn’t even read through my post and you’re judging it but the (provocative) title.

I truly hope it is not so…

Using tables for layout is bad practice. I have read the article and from my understanding what you are saying is using divs and css is no better than using a table?

Like any HTML tag the table has a particular use, which is displaying tabular data like league tables or something similar. It was not designed or intended for layout purposes.

If you are really interested then there are countless articles on the web just look up the benefits of CSS over table-based design.

ps this and all wordpress themes use css to the best of my knowledge.

Micky, I’m sorry but you got all wrong.

My point was (still is) that the habit of replacing tables with divs in a “unaware of semantics” way, typical of those who abandon table layout because they were told to use “css and divs” instead, is a dangerous one.

Dangerous because it causes people to end up using divs the same way they used tables.
I’ll make an example to clear things up.

If you code a header this way:
<div id="header">Header Title</div>
you are doing nothing better than using tables the old way.

What I was trying to criticize with my article is that habit of telling those who were still coding in tables to switch to a css + divs layout without explaining what is the proper use they have to make of divs.

How many times have you seen people switch only to end up nesting dozens of divs or using divs in the place of headings, paragraphs, lists… you name it?
(and I don’t mean when they are used to achieve rounded borders and stuff like that which is awful in my opinion but is another matter.)

I am fully aware and supportive of full separation of content from presentation through css, but, before that, I am advocating the correct semantic use of html tags, which, in my opinion, is completely ruined by the misleading casual saying “use css and divs instead“.

I hope I made myself clear.

OK, you’re absolutely right that many people just replace tables with divs and their code isn’t much better.

This is a big problem and exactly why I cringe whenever I hear “don’t use tables, use divs”.

Everyone should be using semantic HTML and CSS. Use a div where you have a structural DIVision in the page (sidebars, banners, footers, etc). This is what needs to be explained – use of divs in a similar way to the use of fieldsets in forms (meaningful, structural division of elements).

But we should encourage people to not use tables for layout everywhere and at all times. In fact, anyone still using tables for layout in 2008 needs to look into a new line of work.

Your article does sort of read (at first at least) like “go ahead and use tables, they’re fine”. They’re not – unless you’re marking up tabular data.

Hi Patrick,
thank you for your comment.

As I wrote on the DesignersTalk forum (right after your comment), I admit this article is prone to misunderstanding.
I should have thought better that a casual reader might not get what I was talking about.
Indeed, in my mind, I was ideally talking to professionals and not to beginners.
I was talking to those who actually say things like “use divs instead”, not those who act on that advice.

bye

Leave a Reply