tags:

views:

765

answers:

16

I have been pondering on this over the last couple of days. I'm currently writing a web application (actually adding a screen to an existing, extensive application). I know that using "tables" for layout is a big no-no. But in this app, all of the pages use tables for layout. I decided to do my new page using divs instead. But I came across 2 hurdles.

  1. A lot of the layout stuff that I need to do were already done on the other pages and if I use divs instead, I cant reuse any of that (CSS's and JS and that kinda stuff). That leads to more work and pushes out my completion date.

  2. Some of the more complex parts of the layout are really difficult to do using divs and are really easy to do using tables. Maybe its just me being "old-school"y as I am not much of a web/html kinda guy (I get by).

So, why can't I use tables? I'm not trying to be argumentative, just want to see if there are any compelling arguments beyond the "Its the right thing to do" type stuff. I know it is the right thing to do. I'd like to know why?

+5  A: 

Doing css layouts make it easier to change the layout of your page later on. Tables also make your html harder to read and edit.

According to this page..

  • make your redesigns more efficient and less expensive
  • help you maintain visual consistency throughout your sites
  • get you better search engine results when you minimize your markup and use header tags properly. This reduces ratio of code to content.
  • make your sites more accessible to all viewers and user agents.
  • your pages load faster, file sizes will be smaller because table information isn't needed in every page.
  • and give you a competitive edge (that is, job security) as more of the world moves to using Web standards.
Bolt_Head
+1 for readability
fluffels
Lowers your hosting costs? why, because of b/w? Better search engine results? Why, because you can put relevant content up top then position elsewhere via CSS? more accessible? More info on how these things apply would be really useful.
Ian Suttle
@Ian Suttle, because you can extract common elements of you design and reduce the page size of each page of your website. When serving up these pages thousands of times, that can save a lot of bandwidth.
Simucal
The only thing you reduce without using tables is the difference between <table><tr><td> tags and a <div> tag for instance. Then again I see most <div> tags with more nested <div> tags. Not sure this is a point valuable enough to heavily influence a decision.
Ian Suttle
I changed it up a little, images are will are surely the most influential aspect of page loading time. But that isn't to say that we should neglect everything else.
Bolt_Head
+1  A: 

Tables also affect the behaviour of search engines. Using CSS instead of tables is actually an SEO technique as well. The reason I heard for this is that search engines stop indexing after a certain level of tags, and layout using tables can become very deeply nested.

fluffels
Design with tables doesn't need to become nested, especially if you have decent a visual designer (like Dreamweaver) which can easily handle the rowspan and colspans nicely. Nested tables are mostly to keep the code clean and seperate. Oops, sounds like divs to me (just with alot more code).
Matthew Scharley
@monoxide: Doesn't need to become nested, but they do tend to, in my experience. Note that I said "*can* become very deeply nested."
fluffels
A: 

CSS layouts make it easier to alter the layout through stylesheets (separation of data from display).

Also, browsers often can't render a table until the </table> tag has been parsed. This can be a problem if you are using a table with a large amount of content. CSS layouts can often be rendered as they go.

Garry Shutler
+2  A: 

If you have the kind of constraints you mentioned, deadline looming, large existing code base, then use tables, the universe won't implode, but in the long term using css and welformed markup will allow you to create a nicer, cleaner, more maintainable website.

Peter Coulton
The pragmatic approach is often the correct one, but saving time now is kind of a false economy when it comes to de-tabling later, beware of that.
annakata
+7  A: 

Implementing your layout with divs, spans, etc, offers a ton more flexibility over tables. Consider floating, auto wrapping of block content vs. horizontal scrolling, specifying where an element should exist on a page, etc. Content is just plain easier to manipulate via CSS when not using tables.

When using tables you're pretty locked in to a strict structure.

Now that doesn't mean it's absolutely the wrong thing to do. From your information I'd likely stick with the theme of the application for consistency sake and implement using tables. Make the best choice for the situation vs. following "the rules" on what's popular right now.

Hope that helps! Ian

Ian Suttle
+1  A: 

Using CSS for layout, rather than HTML tables provides a level of separation between your page content and the layout of that content.

With tables, your HTML markup has both your content and layout intermingled within the HTML code. This means is you ever want to have a different layout for the same content, you'll need to edit the intermingled code heavily.

By using a CSS stylesheet over your HTML markup you separate the code that provides the content (HTML) from the code that provides the layout (CSS). This makes it far easier to completely change the layout aspect of a web page without having to edit the content code.

The best example of this is the CSS Zen Garden website.

All that said, it's still far easier to do some layout techniques in tables rather than CSS, so there's definitely a "balancing act" there. (For example, even Google uses tables in it's page layouts!)

CraigTP
+4  A: 

They are also bad for accessibility reasons i.e. screen readers don't read them correctly, but this is only if the data you are representing is not tabular data.

Saying that, due to deadlines etc. (the real world) I've resorted to using them for form layout because it's just so much easier.

marktucks
I used to struggle with CSS forms as well, there are some excellent techniques out there for getting them to behave, I havent regretted taking some time out to build a generic form stylesheet, which I can apply to most situations.
Neil Aitken
+1 this is the big deal
annakata
Agree with Neil, I've had the same issues in the past, but after taking some time to look into it correctly, I too have sorted forms with CSS.
Ian Devlin
I have also sorted *simple* forms with CSS, but if there's anything that's not the norm, or is just going to take some fiddling, then it's just easier and takes a lot less time, leaving more time to ficus on the actual functionality and the fun stuff.
marktucks
+1  A: 

By using tables for layout you tie the content to the formatting, this is the main point that most of the disadvantages come from. It messes up the source, complicates site-wide formatting updates that could be easily done with CSS, etc. Using tables for layout also often means slicing images on weird places just to fit them in the cells, yuck.

zoul
+2  A: 

Tables are pretty ugly if you want to support text to speech readers (if you've got any kind of accessibility requirements, you pretty much have to use tables for tables and nothing else).

There is an SEO aspect of this as well. For SEO, it's better to have your content at the top of the page than at the bottom. (Sadly, studies suggest appears that putting a menu first is actually a good idea for accessibility, so the two imperatives clash.)

If you are having trouble with cross-browser support, I can suggest that you develop using Firefox. Its support for CSS development is much better than other browsers, and it's more standards-compliant (and hence more predictable). Later on, you can patch up for down-level browsers.

And, as Peter says, the universe won't implode. But using CSS for layout is cleaner in the long term. Redesigning something with the layout hard-coded can be a real pain. Check out the CSS Zen Garden for examples of what you can do. Of course, in the future, we'll have CSS table layouts, the best of both worlds.

Julian Birch
+4  A: 

Because the tag <table> implies it should contain tabular data.

Like Peter said, the universe won't implode if you do create table-based layout, but semantically, this should be avoided.

Semantics become increasingly important, since web pages are not always shown in a desktop browser anymore. Web standards are developing in a way that HTML describes the semantic structure of the document, not the markup; and as said: using <table> tags for tabular data is semantically correct.

Interesting related reads:

Aron Rotteveel
That thread had a lot of points that resonated with me. We don't use tables for all layout, just for the macro grid. All other "formatting" is done using CSS/divs within the tds. I played with floats/positions and I spent an hour just getting a basic 4 column form style page to look barely decent.
Adnan
+1  A: 

you can use tables, but divs have more advantages. but it's all in perspective. Like you say, you are precious for time, so probably (on short notice) tables will be the choice to make. However, if you manage to make it div-wise, you will have a more maintable page, which you can use to refactor the other pages as well.

Mafti
+3  A: 

First, you can usually convert a table layout to divs without too much trouble once you know the necessary CSS.

But more to the point, some of the reasons why tables are bad:

  • Not all your users are going to see the page using the browser's rendering engine. Some are going to use a screen reader, which may assume that when it encounters a table, it should actually read the contents out as tabular data. Essentially, you should think of it as a coincidence that tables have a certain layout "look" in a browser.
  • tables can't be rendered until the table and all its children have been parsed. A div can be rendered independently of its children, so you avoid the page contents jumping up and down on the page as the page is parsed, and get to show contents sooner.

There are good and valid reasons to prefer tables, but when you're used to tables, there's also a certain learning curve, so if you're pressed for time, this might not be the time to make that switch.

jalf
+1  A: 

Jeffrey Zeldman wrote a great book on this topic: Designing With Web Standards. This book should be mandatory reading for every web designer.

Here are some reasons why tables for design are bad

  • Tables generate more markup -> More bandwidth usage
  • Tables makes it harder for search engines to index your pages -> Your site becomes less "searchable"
  • Tables makes it harder to change and tweak the visible appearance of your site -> More costly redesigns
  • ...But most importantly: using tables for design adds presentation logic to your markup

That is bad because you want to separate your presentation from your content! HTML should only define WHAT your content is, not HOW it should look.

If you obtain this level of separation your site will...

  • ...be more accessible by different kinds of browsers and other kinds of user agents.
  • ...make redesigns much easier
toxvaerd
+1  A: 

The best you do not listen to the fanatics of CSS. These purists live in some imaginary world and will feed you the arguments of some abstract purity, semantics and the rest. You would not want to have this kind of people in your team. For now I've only seen yellow-mouth students to run around with "pure CSS design" ideas. They'll show you examples of very primitive CSS-designed sites, ignoring you whenever you ask them how you can accomplish some complex enterprise software design with it. Experienced developers already know this perfection is not possible.

What should you do? Follow the KISS principle. If CSS can help you implement your particular design idea, fine, the problem is solved. If you need to resort to some relatively uncomplex hack, it may be okay. But when it comes to some huge piece of code with dozens of rules to make a basic thing, which you easily and naturally achieve with tables, drop it.

It serves no purpose to create an incredibly complex and sophisticated tricky CSS design that noone else (and yourself after a couple of months) will be able to understand and support.

As for the "easy redesign", unless you only want to change colors and fonts, you will enevitably have to restructure your markup whether it is done with tables or without them. In the latter case, a high portion of your markup will serve no purpose except implement CSS trickery which will be useless for you new redesign idea.

Honestly, it's not your fault that the people responsible for further development of HTML/CSS don't do their job properly. You should not waste your and other people's time trying to find workarounds for something that should have been there ages ago.

HTML/CSS is a good example of how poorly some committee could do their job and brake the development of technology as compared to a single company with resources and commitment.

User
I don't even know what "yellow-mouth" means, but you're way off the res here. It is every developers job in every field of development to ensure maintainability.
annakata
It means "unexperienced" und willingly ignorant of this.
User
Interesting. Google just says it's some sort of a fish and a disease - where does this expression originate?
annakata
Sorry, I should have probably not used this expression, it could well be culture-specific. I remember some birds have ther youngs with their beak inners of the yellowish color until they mature a little bit. :)
User
+4  A: 

I'm going to post a contrarian view, just so you have some ammo. I realize this doesn't answer your question (why not use tables) but it does address the other responses you will see.

So be practical.

That said, most of my designs use pure CSS. Nearly everything can be done in CSS just as easily as with tables (or even easier.) Start with the assumption that DIVs can do it, and maybe fall back on 1 table for a tricky multi-column layout. Even then, someone has probably found a solution for your layout so search first.

Steve Eisner
Your second link is based on misconceptions, the third is a lemming argument, and your point about display:table is very useful but is an argument in favour of CSS, not tables. The whole display:table thing solves *everything* if only we can speed it along.
annakata
Isn't that exactly the point? I totally agree with you about display:table, but we're building HTML now, not next year. (I happen to disagree with your unsubstantiated terms "misconceptions" and "lemming" but understand why you might feel that way)
Steve Eisner
It is the point, but it's a point for CSS, not for table elements. It's too big to cover here (and belongs on that blog anyway) but justifying the use of tables on the grounds that google does is outright giving up. That's no answer at all. And the "I'll write an API if I want to" is quite ignorant.
annakata
+1  A: 

"The right thing to do" depends on your situation.

Yes, divs offer more flexibility, but at the end of the day, do you really need it? As far as the number of lines of code goes, I have found that a simple table is often quite a bit smaller that an equivalent div design.

It's faster to put together, and it works as reliably as possible in pretty much all browsers, which means you don't have to write a zillion hacks to make it work consistently AND it doesn't break down when a new display engine comes out.

Using tables for display is technically a hack, but it does the job, is easy to understand and maintain and is to a large degree future proof, so for a simple layout, considering that the rest of the website already uses tables for layout, I would keep using tables.

Besides, turning a Table into a "div" table which uses the new "display=table" attributes can easily be done with a few regexes (if you rack your brains, you can probably even do it with a single pass). If you know your regexes, you can replace a table with divs through an entire website in a matter of minutes, so the whole issue of flexibility is really not that big: when (if) you actually need to use divs and CSS positioning, just run a few regex, and you are set. And if you need more control than what you can handle from regex, you can spend a couple hours to write a quick & dirty parser that will convert your tables to div exactly as you want them.

Bottom line is that despite the stigma, for simple layouts, tables still do the job, they do it fast and are reliable, and if you don't have to contend with CSS purists, you can save yourself a lot of work.

Sylverdrag