Tables: Not As Evil As You Think

Jonathan wrote this on in . It has 19 comments.

Any web designer worth their salt knows the following aphorism to be true:

Tables are for tabular data. Using tables for layout is evil. If you use tables for layout, YOU are evil. Don't do it. Don't do it ever.
DON'T $*&^%ing DO IT!

A cursory Google search will return around 8 million results, most of them waxing long and poetic about the various failings and flaws of table-based layouts (although one notable site is hilariously short). To be honest, there is a great deal of truth to these articles – but not quite as much as some would have you believe.

But tables are bad, right?

Yes and no. For tabular data, no, of course they're not bad. That's why tables are there in the first place. CSS can do an excellent job of styling a properly-formatted table and the table structure provides a nice scaffolding for javascript calls.

Most of us know that. What we're talking about here is using tables for non-tabular data, or layout. Yes, using tables for layout.

So when should you use them, smart guy?

Sparingly. Let me give you a very recent example.

This fairly small piece of the new home page for a client was done with a table. Why? Because I lost almost nothing and gained quite a bit.

The bad: what did I lose?

Well, I lost the ability to arbitrarily restyle that section without touching the page code. That much is obvious and is a true downside – though in this case I gauged it to be a minimal one. I also lost, in a puritanical way, a perfectly semantic page: dig into the code and you won't find a nice little list, you'll find three rows with four cells apiece.

What would others say I lost that I didn't actually lose?

I Lost SEO

Wrong. The nugget of truth here, and it is only a nugget, is that a pure CSS layout forces you to write better markup. That could be true, but nothing is stopping you from writing a well marked-up table section. Search engines don't care about tables, or your CSS.

Don't believe me? Check out Google's Webmasters/Site Owners documentation and search for tables, or CSS. Then download this PDF and do the same. Then, for giggles, go back to that Google webmaster page and view source. Good stuff, huh?

It's not accessible!

You will probably hear some accessibility advocates say that layout tables are a bad idea, and that CSS layout techniques ought to be used instead. ... People with all kinds of disabilities can easily access tables, as long as the tables are designed with accessibility in mind.

http://www.webaim.org/techniques/tables/#cl

It's completely true that a totally table-based layout can mess up screen readers, because the reader will traverse across rows and your layout may have nothing to do with that. In my example above though, you know what the difference is to a screen reader between a table and a ul? Nothing. Not a single thing.

Screen readers don't ignore tables; if they did any sort of data-centric site would be meaningless. What screen readers do is make a judgement (generally based on the presence of a <thead> section) about whether a table is being used for data or for layout. Upon finding a table used for layout the screen reader does exactly what a search engine would do: ignores it and reads like it isn't there. There's a great article on WebAIM about writing accessible tables, and how screen readers behave when presented with a table. Whether you agree with me here or not you'd do well to read that article, if only for your data tables.

Longer page load time.

Wrong. A completely tables based layout would, in fact, be a larger page. That could be a bad thing, even if these days bandwidth is so cheap as to be almost meaningless. A sufficiently complex table would be a lot to parse and could slow down a large page – but we're not talking about a totally table-based layout (at least I'm not – if you are, well, we should talk some time). For small sections the bandwidth and load time difference is irrelevant, and in fact a sufficiently complex chain of CSS selectors can bring IE6 to its knees.

Alright, what do we gain?

Speed of development and testing. That table above took me about two minutes to write, and the equivalent CSS would have taken...maybe slightly longer but not by much. What pushed me over the edge though was the QA time I'd recover.

Let's not kid ourselves – we all develop in the shadow of IE6. IE6 hates CSS-based layouts, even IE7 managed to omit a handful of really useful selectors. I could have written that little section in CSS, and in everything from Firefox 2 up to Safari 3 and even IE7/8 I would have had almost no problem. And then I would have wasted half an hour getting IE6 to work the way it should.

The website Give Up and Use Tables I think maybe paints with too broad a brush but they are definitely on to something. If it takes more than an hour, say, to get your layout working in IE6 and a similar table based element would solve the problem for you in 5 minutes, what are you doing? In these cases you won't lose SEO, you won't lose accessibility and the hit to page load time is irrelevant. Are you just faffing around with CSS for fun? Be practical.

Bring it on!

I have no illusions about how some people, maybe the ones in my office, will feel about this. CSS is sacrosanct, and advocating a departure from the purity of CSS is tantamount to blasphemy. I'll be the first to admit that I want to do everything in CSS. I love CSS. It's an elegant means of styling markup, and in a perfect world we could use it for almost everything on the web. We don't live in a perfect world – we live in a world of deadlines, and old browsers, and frustration, and ill-supported standards.

Tables are not the enemy. They like so many other things are a tool we can use for good or ill. Used sparingly tables can save you a lot of headache and you'll sacrifice (next to) nothing. Use common sense. Be practical. It's possible to use a table now and then and not be a terrible person.

See more Product Engineering and Design Jobs on Job Board from ZURB.

19 comments

Jeremy (ZURB) says

Good to hear this coming from our team. It means we're shaking our puritanical markup phase and getting practical with our solutions. Tables are the right tool and the wrong tool to use, depending on the circumstances.

One you left off that I have continually run into is speed. When it's 10pm at night and you have five pages to design and build for a tradeshow the following morning, tables can be a lifesaver. The layout is going to be a dead-simple structure and your cross-browser bug risk shrunks. You know you've got something rock solid. This lets you focus on your content and interaction. Thank you tables!

That said, I know Mark is cooking up some good advice on how to achieve the same rapid build effect with a set of tools and defensive measures for IE6. Mark, take it away!


Jonathan (ZURB) says

@Jeremy I agree that speed is the primary reason to go this route (see: "Alright, what do we gain? Speed..." ;) but to me that speed gain is almost entirely in QA rather than development.

Sometimes a complex CSS structure will slow me down a bit, but I think as often the equivalent table structure would take as long to set up. QA is the killer - 99% of the time tables just work, and while in Safari or FF3 the same is true for CSS, in the IEs it's just not.

Glad you like that we're getting a little practical with these things - now when the rest of the office starts giving me crap I'm using you as backup :)


Levi Figueira (ZURB) says

Sorry to inform you that you completely missed a key point: multiple stylesheets! I shouldn't have to touch my code to have my site be more usable (not talking about accessible) on a phone or other mobile device and adjust itself to maximize its screen real estate. Also, print stylesheets are a PAIN if you layout with tables.

PLUS, what kind of person wants to go change the code AND the CSS to make some layout reconfigurations?

Tables kill agile development! Does it really make development faster? You're not taking into account the design phase. Tables make you have to worry about what you have on a page but also what else you possibly want to display there and do all that thinking up front. While that's fine for a designer worried about the LOOKS, it's living hell for any frontend/backend programmer, creating templates/backend logic. And that's where the implementation phase comes in and kills the "faster design time". I can put a layout pixel-perfect from PSD/PNG into HTML/CSS faster than you can into tables. I'll venture saying that you will not be able to give the designer the freedom he wants on the design stage. PLUS, you'll frontend developers can then worry about the usability and user experience. With tables, they can't change much without changing the whole design (or a lot of it).

Seriously: get over the "new-hype-tables-are-cool-after-all" and start coding some good, semantically sound code.

(...) pure CSS layout forces you to write better markup."

This is reason enough for me!

Let's not kid ourselves – we all develop in the shadow of IE6. IE6 hates CSS-based layouts (...)

That's a good reason to drop support for IE6 and encourage users to upgrade their browsers. Actually, it's a good argument against using tables: if IE6 did so well with them and bad with CSS and knowing how bad IE6 is... tables can't be good! :p

Well-versed CSS advocates won't use the arguments of "SEO", "accessibility" and "load times" to argue for CSS. But they'll use "agility", "usability" and "freedom". And I don't know about you, but I'll take those last 3 over the latter ANYTIME.

Tabular data? Use tables. Layout? Don't be lazy and learn proper ways not to use tables.

Thank you. Have a nice day.

NOTE: This is not a personal attack. I don't know the author of this post, his skills and portfolio. This is just a comment on the line of thought and argument presented on this blog post. I am a happy person and love arguments, hence the tone. :)


Paul Lloyd (ZURB) says

I appreciate where this argument is coming from, and from the work I've seen your company produce, I know that this is something you have thought long and hard about.

However, I think there are a number of other reasons why using table mark-up for layout should be discouraged:

  • It encourages laziness. Perhaps not within ZURB, but others following this approach might soon find themselves in the trap of 'well, I used tables for layout here, so I might as well use them here too…'.

  • It sets a bad example for others to follow. The most successful tool in encouraging people to move away from tables for layout, was progressive web developers proving that it could be done. Don't underestimate the power of 'View Source'!

  • Web developers like to preach that websites don't need to look the same in every browser (do they), and I would ask the question in this particular example: would users of IE6 mind if these icons appeared in a single column? I'm almost tempted to say would they even notice?

I'm uncomfortable with the idea of serving completely different sites to users of IE6 (45 Royale), or not serving up any styles at all (SimpleBIts), but I am fond of the idea of IE6 getting less glamorous versions of our designs (i.e. progressive enrichment).

The only way we are going to move this medium forward, is by encouraging users to upgrading their browser (remembering that this also brings better security and speed).

Of course we make these decisions based on the statistics we have about visitors to a site – if a large percentage still use IE6, then maybe your approach has more merit, but I would counter that by saying that gives good reason to spend a little more time developing a more flexible, future-proof document structure.

I'm all for pragmatism, indeed the more I have worked in the industry, the more I have come to except (and respect) the constraints it brings, but I'm not sure I'll be using this particular example in my own work. Call me old fashioned, but I remain a firm believer in the old adage 'if something is worth doing, it's worth doing well'!


Tiff (ZURB) says

This is an interesting topic. As Paul Lloyd rightly says, don't underestimate the power of 'View Source'. Back in the 1990's, when I realized this handy feature existed, I taught myself "How to Make a Website 101" purely on borrowed code. And since tables were the prevalent way of making layouts, that was part of my education.

This didn't change until years later when I got a job and my co-worker told me the new in thing was table-less layouts. And there I was introduced to now well-known argument that tables should only be used for tabular data. The argument is sound. Being new, I was not one to question and to be honest, it was actually fun learning how to make the same layouts I'd been making in tables with divs, positioning and floating. But a question kept popping up in my head, especially when small mundane pieces that needed to be finished yesterday presented itself - why was it necessary to use such manipulation to make the same exact thing one could make with a table with a lot less code and in a jiffy?

Well, no one ever really answered that for me and while I picked up some partial answers along the way - ones you and others have already mentioned so I won't bother typing them again. But I am inclined to agree with you - with the caveat of course that it should only be used when there are time constraints and for small simple sections of code. The advantages at these times outweigh the disadvantages. However, if you have the time, why not take that time to make it right? It's all about practicality in a fast-paced business.


Jerome (ZURB) says

There are times when using tables for layout just makes sense. What is best to use from the business perspective is what we should all ultimately decide. I wouldn't consider it lazy to use tables if you've considered the costs and benefits before making the choice - I'd call that smart.


Jonathan (ZURB) says

@Tiff Exactly right, and you touch on a point that should have been more explicit in the post itself. At ZURB we're all about Design Strategy, that sweet spot that brings together design and business. From a purely design perspective tables for layout are a terrible idea – messier code, harder to change, lost flexibility...Paul and Levi brought up excellent points about just those reasons.

What makes this something to consider is business: it's not just about clean code, it's about creating value for the client. 'If it's worth doing it's worth doing well' is completely correct, but we have to take a more holistic approach to what is 'doing well' for the client. Sometimes doing well for your client is saving hours on something that doesn't create value for them (like flexible, semantic code) and applying that time to areas they'll get more out of – maybe greater visual polish, or improved SEO.


Blair (ZURB) says

Although you were able to get by with a table in this instance, I would strongly advocate not using tables just because IE6 will take longer to code. The truth is, there are many ways to write that example in CSS and have it be cross browser compatible from IE6 up. Basically you make a div wrapper for each row. Within each row you have two div elements with float:left properties. Then before you close the row div, you add a empty div with a clear left property. Then add more rows if you need it with the same consistency as the first.

It's really that easy. Also, you must think of the semantic web and what a table actually means. A table is meant for storing tabular data and is composed of a head row and a body. You are not using a thead in this case so really, it's not a situation for a table. I think tables are great for showing a excel like spreadsheet of data, but for layout it becomes incredibly cumbersome to wade through tr td spaghetti. When your layout becomes larger, the more pain you will experience editing crusty old tables....


gavin (ZURB) says

Another world that gets a lot of mileage out of HTML tables is the email newsletter business. First, it is a big big business. Second, CSS gets butchered when delivered thru an email client. Think browser implementation differences are bad? Email clients (webmail included!) are horrible.

Often all you have available are good old-fashioned tables for layout.


Jonathan (ZURB) says

@gavin It's funny you mention email templates, another situation where business needs dictate the tools. It would be very easy to say 'using tables for layout in emails is impractical and obnoxious to re-style' but a well-crafted rich email will likely perform much better than flat text.

Again, none of this is about convenience or theoretical best-practices; it's all about business goals and doing what is best for the client. Every now and then that means table layouts.


Dawn Chatman (ZURB) says

I swear, I almost come to tears whenever I read someone say.. "really it's ok, use a table there".

I've worked for a large design studio for the last 10 years and recently switched to the senior designer position in a social networking design studio. And let me tell ya, testing is a HUGE part of our lives. I have multiple deadlines that can at times make me consume an entire bottle of Tums.

Whenever I use a table somewhere I imagine some 24 year old kid just out of college, that maybe creates 2 sites a year will disprove of my work. Well ya know what kid? Shove it! There I feel better now.

Great article. /thumbs up


ME (ZURB) says

I shake my head when I hear people say things like "drop support for IE 6 and force users to upgrade"...

I don't know about you, but some of us cater to CORPORATE users and their IT departments are slow to upgrade especially large masses of old computers that run pre-prepared images of volume licensed software. I can't tell my client base at multiple locations that he has to upgrade hundreds of machines because we're dropping support for IE 6 and forcing users to upgrade. We'd pretty much lose that contract.


Richard@Home (ZURB) says

Every couple of months, someone throws up an article about why it's Ok to use tables for layout.

And they are wrong.

They are wrong for exactly the same reasons the arguments before them were wrong.

If you don't understand why, please go read the many, many articles explaining why.

If you still don't understand why, go read them again ;-)

Your layout has nothing to do with tabular data and could have been created with LESS markup than if you used tables.

I see a group of 6 sections, each containing a heading, an image and some text. I do not see any tables.


James (ZURB) says

Fair point, but you missed the point of the "long page load time" argument. Obviously the number of bytes saved either way doesn't mean much, the important consideration is the render time, as some user agents wait until the closing table tag before rendering the table. Having said that, it is moot in this case given the small size of the table.


Nick (ZURB) says

Oh dear God. Graphic design considerations are the bane of computing. Take 10 steps back, outside of your world, and look at this conversation from a completely different point of view. What matters, really, is content. Presentation is just candy. Computing is being brought to its knees by concerns about how prettily data is displayed. Is this really the world that we live in? Some people spend their whole lives worrying about whether it's ok to use one graphic layout technique vs. another? This just seems inane to me.


Marcel (ZURB) says

Compromise is good and all, but where does it end..? Spacer-GIFs in between table columns and rows instead of using "that complex 'padding' thingy CSS wants us to use"?

Personally, I feel it's my job to stick with progress. It's my job to deliver something that works. And I can almost always do that without resorting to conditional comments, even for IE6. In your example I could achieve the exact same thing in perfectly semantic HTML and CSS. You'd take maybe 2 minutes less to do the same with tables, but if you ever want to restyle that page - say: put them all below one another - I'd simply remove the "float" from my CSS and tell it to "display: block;". You'd probably have to insert TR's.

Now, that doesn't sound like a lot of work. But by that time your table is just there to do absolutely nothing at all. It's wasted bandwidth. And if you have 100 visitors a day.. who cares. But if you have a few million visitors a day, every single byte of data turns into hard cash over the course of a year.

And if that isn't reason enough, I guess pride in your work and your reputation as a front-end developer should be reason enough to not use tables where they are clearly not necessary.

That said, it's all situational.. if time is short and you need quick results, go tables. Just add some HTML-comment to the page where you apologize to every single developer that takes the time to inspect your source, trying to figure out how you did that in CSS.


George (ZURB) says

Telling people to upgrade their browsers is at least as bad as using tables. At some point you have to be realistic - no one will ever upgrade his browser, because a website tells him to.

Still I for myself rather prefer to do it right and not use tables; I would rather change my design if I am not able to achieve what I want without hacking around forever; but then again, what I find really astonishing is when people show me their cool and nifty ways where they prevented to use tables when it would have been totally apropriate (better even!) to use tables!

And ultimately, emulating tables by putting wrapper divs around the content as Blair suggested is not really better than "being honest" and use a table right from the start.


hedge fund news (ZURB) says

yours truly just stopped by your site and thought yours truly would say hello. Bye


dating singles (ZURB) says

Hello There I am not going to be original this time, so all I am going to say that your site rocks, sad that I don't have such writing skills Me have a website aswell. Sincerly



Get a job, nerd!

via Job Board from ZURB