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?

2
  • Duped many times as indicated in Wayne K's post.
    – annakata
    Apr 28, 2009 at 7: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, 2009 at 9:55

16 Answers 16

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.

5
  • 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, 2009 at 7:57
  • Chill annakata! No one will die if a table is used for layout. Well, no one important anyway. Apr 28, 2009 at 8: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, 2009 at 9: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, 2009 at 16:07
  • 1
    That is an awesome graphic....and it is so true. Apr 28, 2009 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?

1
  • 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, 2009 at 9: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

4
  • 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 :) Apr 28, 2009 at 7: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, 2018 at 22:42
  • @mwilson Bear in mind that this question was asked in 2009, before CSS Grid and Flexbox were readily available. Jul 12, 2023 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, 2023 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.

1
  • Good answer that shows the stupidity of all these "tables vs divs" questions!
    – roryf
    Apr 28, 2009 at 9:23
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.

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.

1
  • 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! Apr 28, 2009 at 8: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.)

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.

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.

2
  • 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 <thead>, <tbody> structure.
    – roryf
    Apr 28, 2009 at 9:28
  • "Easiest" depends upon many factors, amongst them your css knowledge and what browsers you program for. I have often implemented a nice-looking layout in css, only to fall back to a table because i couldn't persuade IE6 to display it correclty ;-)
    – mfx
    Apr 28, 2009 at 12:57
1

Table is always the right choice when you have the need to present data in a grid.

1

Quoting Sitepoints's book HTML Utopia: Designing Without Tables using CSS If you have tabular data and the appearance of that data is less important than its appropriate display in connection with other portions of the same data set, then a table is in order. If you have information that would best be displayed in a spreadsheet such as Excel, you have tabular data.

1

I would say no for using tables to construct your layout. Tables make sense only for actual tabular data you need to represent. If you spend enough time figuring the CSS out you will find its easier then using tables for a layout. Just remember: Tables for displaying data. CSS for page layouts.

0

Tables are just that: Tables.

They are frowned upon because they should not be used for layout, as has been the fashionable thing to do before browsers could position stuff properly.

If what you want to markup is, in fact, a table, then use a table. Other than that, try to stay away.

One small thing: Aligning two parts of text to the exact same line that won't move apart (think, username and post date). There using a table is IMHO an option.

1
  • 2
    You don't need to use tables for that: if you know how to float elements correctly, you can make perfectly aligned columns with just CSS.
    – hbw
    Apr 28, 2009 at 6:58
0

First get it working. Then get it perfect.

Get the layout done in some way before making it perfect or better.

How many people per day will go to the page you are working on? A million? or 20 ?

How much time are you going to spend on CSS issues instead of other issues? Does your boss want you to spend this much time on the issue? Does he/she know what you are doing?

0

Absolutely. I don't know where CSS zealots invented the idea that tables are not naturally used for "layout". Tables have been used for laying things out since their invention, whether those things be numbers, words, or pretty pictures. That's what they do. Moreover, table is part of all versions of (X)HTML so there are no deprecation concerns.

6
  • I think you're confusing the <table> with grids.
    – roryf
    Apr 28, 2009 at 9:25
  • I think you wildly misunderstand the difference between intent and necessity.
    – annakata
    Apr 28, 2009 at 9:41
  • No, I'm not confused. <table> is a very effective way to implement a table, which is the most common form of grid. Apr 28, 2009 at 10:10
  • 3
    And nothing whatsoever to do with laying out anything which isn't a table.
    – annakata
    Apr 28, 2009 at 10:17
  • Perhaps they got the idea from W3C specifications. Please, don't forget about POSH: 456bereastreet.com/archive/200711/posh_plain_old_semantic_html
    – fregante
    Nov 8, 2010 at 12:43
-5

Absolutely.

All that HTML offers was originally intended for you to define the markup of your page. In my book, absolute and relative positions of elements on a page belong to markup. So both divs and tables are very much suited for this task. Pick up what works best for your particular need.

CSS adds many styling possibilities and also layout tricks but it complements HTML options not replaces them.

There is actually a very fine line between seeing something as a markup or styling issue. CSS proponents would say that with CSS you can relocate and reshuffle completely all big and little pieces of a page. I cannot however imagine putting header below, footer above and making things appear in reverse order.

Take an example. You design a notebook. You know where to place major components, mainboard, cooling system, keyboard, display and ports. You may certainly wish to rearrange a little bit port connectors, on whic side and in which sequence they appear, but you don't really expect to put display where the keyboard is, put keyboard on the lid, make fans blow to your face and have all connectors on the botom to be reached through holes on your desk.

Using tables can make it slightly difficult to rearrange elements on a page. This might be true. However, in most cases you know in advance how approximately your page should look like and you would not want to change everything drastically. if you can't say it before your begin your work you probably have no clear idea what you are doing and what for.

Moreover, only tables possess elastic properties, which allows the to stretch to the width/height of their content. Nothing else of HTML/CSS can be used to do that.

CSS design on one side allows you to create quite adjustable designs. On the other hand, it locks you out from designing a page adjustable to its content. Both wins and losses.

Table is also the only tool to make very complex and precise interfaces. For example, the page SO is very simple. It probably can be done with pure CSS. In the meantime, have you seen any enterprise-class software like CRMs, SRMs etc? That multitude of buttons, text field, check boxes, dropdownlists all precisely located on a screen? Good luck achieving that kind of complexity with just CSS. And these layouts migrate from desktop applications into web each day (keyword: software-as-a-service).

So choose what suits best your current need and don't trust those CSS lovers. Actually don't trust any fanatics at all.

1
  • 1
    Seriously I thought we were done advocating table-based layouts in 2003/2004. How were you 5 years behind the curve on that, still espousing dated information and opinions in 2009? I certainly hope you've changed your mind since then. I don't want to downvote, but will check back to see if this answer still exists, and if it does, hopefully downvote this into oblivion. It's not even useful for historic info. Mar 29, 2017 at 21:47