24

I am developing a "modern" website, and I'm having a lot of trouble getting the CSS to make everything line up properly. I feel like they layout would be a lot easier if I just used a table, but I've been avoiding <table> tags, because I've been told that they are "old-fashioned" and not the right way to do things.

Is it okay to use tables? How do I decide when a table is appropriate, and when I should use CSS instead? Do I just do whatever is easier?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • Duped many times as indicated in Wayne K's post. – annakata Apr 28 '09 at 07:45
  • 1
    Remember the KISS principle. Really use what is more simple. Using awkward CSS tricks can be cool for some contest but not for practical work. Your colleagues or other people involved might not like having to spend weeks trying to make out how you did this and that effect. – User Apr 28 '09 at 09:55

16 Answers16

28

The answer is yes, it's fine to use tables. The general rule of thumb is that if you are displaying tabular data, a table is probably a good way to go. You should generally try to style your table with css as much as you can though.

Also, this pie graph might help you:

alt text http://www.ratemyeverything.net/image/7292/0/Time_Breakdown_of_Modern_Web_Design.ashx

EDIT: Tables are fine. For displaying data. Just like my second sentence stated. The question was "is it ok to use tables". The answer is - yes, it is ok to use tables. It is not illegal.

Since even though it's implied to use tables for data in my general rule of thumb, apparently I must also state that the corollary is that it's not ok to use tables for anything else, even though the poster already seemed to grasp this concept. So, for the record, the general rule of thumb is to not use tables for laying out your site.

womp
  • 115,835
  • 26
  • 236
  • 269
  • 2
    Where did I say anything about inline styling? And tables are wholly appropriate for layout when needed, as 8 other responses on here will attest to. There's nothing "legacy" about tables, except for the fact that they were abused for years. – womp Apr 28 '09 at 07:57
  • Chill annakata! No one will die if a table is used for layout. Well, no one important anyway. – marcus.greasly Apr 28 '09 at 08:18
  • Look I really think you're overreacting - if it makes you feel better I'll delete my comments, but just to *further* clarify: your language is ambiguous and the subject is not. Now if I rescind my downvote will you go and take your retaliatory one off? It's just a downvote, I think we can all move on with our lives can't we? – annakata Apr 28 '09 at 09:01
  • Sorry. I was ultra-grouchy last night, I have two presentations to give today and someone on my team broke the build when I really needed it, so I was up until 2 AM. – womp Apr 28 '09 at 16:07
  • 1
    That is an awesome graphic....and it is so true. – Michael Kniskern Apr 28 '09 at 22:51
22

Tables should be used to represent tabular data. CSS should be used for presentation and layout.

This question has also been exhaustively answered here:

Why not use tables for layout in HTML?

Community
  • 1
  • 1
Wayne Koorts
  • 10,861
  • 13
  • 46
  • 72
  • 7
    Irony. Perhaps you'd like to raise a question so SO can solve the problems you've been having with CSS, Mastermind? – annakata Apr 28 '09 at 09:40
17

Essentially - if you have tabular data, then use a table. There's really no need now to use tables for layout - sure, they were often considered 'easier' but semantically the page is horrid, they were often considered inaccessible.

See some discussion: css-discuss

and a particularly comical URL - shouldiusetablesforlayout.com

Terry_Brown
  • 1,408
  • 10
  • 24
  • 7
    be sure to look at the source of that second link once you've marveled at the beauty of the page by the way :) – Terry_Brown Apr 28 '09 at 07:19
  • With the powers of CSS Grid and Flex Box, I don't see any use case that would present a scenario where a table-layout would be more beneficial. Like everything in this thread, only use a table for an actual (data) table. Not layout. – mwilson Jul 18 '18 at 22:42
  • @mwilson Bear in mind that this question was asked in 2009, before CSS Grid and Flexbox were readily available. – Charles Wood Jul 12 '23 at 19:54
  • Bear in mind it's 2023. Even the answer, which was answered in 2009, emphasizes on using a table for layout as bad practice. I should also say that flex box was out in 2009, and the first release of css grid was in 2007. so again, why use a table for layout purposes? – mwilson Jul 12 '23 at 20:21
8

In the 'modern' approach of tables it is not about using table tags or div tags, but about using the right tag for the right purpose.

The table tag is used for tabular data. There is nothing wrong with using it for that!

For using CSS, there are a lot of tutorials and guides (good and bad) around. Indicators of a bad tutorial are: lot of use of blocks (divs) that only make sense for the layout and not for the content. Good signs are the ones that advise to use the right tags for the right content and teach you how to make up that tags.

Peter Smit
  • 27,696
  • 33
  • 111
  • 170
4

Tables are only appropriate for tabular data. Imagine you have to add some spreadsheet like data, where you have clear row/column headers, and some data inside those rows. A product comparison, for example, is also a valid table item.

Gideon
  • 18,251
  • 5
  • 45
  • 64
4

I believe that tables are OK for display of rectilinear data of arbitrary rows and/or columns. That's about it. Tables should not be used for layout purposes anymore.

Glenn
  • 7,874
  • 3
  • 29
  • 38
  • Yours looks like the first post which actually makes an attempt to explain what 'tabular data' is. Ie, it is data in rows and columns. +1! – thomasrutter Apr 28 '09 at 08:15
3

In general, HTML markup should describe the structure and content of a web page—it should not be used to control presentational aspects such as layout and styling (that's what CSS is for). A <table> tag, like most have already said, should represent tabular data—something that would appear as a table of information.

The reason why people rag on tables so much is that in the old days, there was no such thing as CSS—all page layout was done directly in HTML. Tags were not thought of as describing content—all anyone really cared about was how a tag would make things look in a web browser. As a result of this, people figured that, since they could organize things into rows and columns, tables must be good for laying out elements of a web page. This became a really popular technique—in fact, I'd wager that using tables was considered the preferred method of laying out web pages for quite some time.

So when people tell you that tables are "old-fashioned," they are specifically referring to this abuse of the <table> tag that was so popular back in the old days. Like I said, there's nothing wrong with HTML tables themselves, but using them for web page layout just doesn't make sense nowadays.

(Plus, from a purely pragmatic standpoint, layouts done with HTML tables are very inflexible and hard to maintain.)

hbw
  • 15,560
  • 6
  • 51
  • 58
2

its ok to use tables when you are showing data in a grid / tabular format. however, for general structure of the site, its highly recommended that you use css driven div, ul, li elements to give you more lucid website.

If you anyways decide to work with tables, you must consider the following cons :

  • they are not SEO friendly
  • they are quite rigid in terms of their structure and at times difficult to maintain as well

you may be spending little extra time on div based website, but its worth every minute spent.

Vikram
  • 6,865
  • 9
  • 50
  • 61
2

The whole "anti-Table" movement is a reaction to a time when deeply nested tables were the only method to layout pages, leading to HTML that was very hard to understand.

Tables are a valid method for tabular (data) layout, and if a table is the easiest way to implement a layout, then by any means use a table.

mfx
  • 7,168
  • 26
  • 29
  • 2
    Define "easiest". For me using tables is harder because I don't know how to do layouts with them anymore, if they don't contain data I'm lost. Now give me some nice lists, paragraphs etc. and I fell right at home, same as a nice