1

I like to follow standards and use table-less div based layouts. However using tables to align form fields/textareas and submit buttons is so much easier than using anything else. So is it acceptable from a strict standard perspective?

I see Google, Facebook among others use tables in their registration pages.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Kalen
  • 21
  • 1
  • 3
  • 1
    despite my personal convictions about this I'm marking it "subjective". There are going to be people dropping in to say "Use tables if you want and don't listen to anybody who says otherwise", with consequent flames from people like me :-) – Pointy Feb 25 '10 at 19:45
  • http://stackoverflow.com/questions/83073/why-not-use-tables-for-layout-in-html – Javier Feb 25 '10 at 19:47
  • 2
    ON SECOND THOUGHT I AM GOING WITH TABLES. I LIKE DIVS AND CSS - I REALLY DO AND HAVE BEEN USING THEM FOR YEARS BUT THIS DOGMATIC VENDETTA MOST FRONT END DEVELOPERS HAVE AGAINST TABLES EVEN WHEN PRACTICALITY AND EASE ISN'T ON THEIR SIDE IS DOWNRIGHT SILLY. WITH TABLES I CAN ALIGN FORMS IN A MINUTE WHEREAS IT TAKES A LOT LONGER WITH CSS TO DO MINUTE POSITIONING/ALIGNING. PLUS IN THIS CASE TABLE POSITIONED FORMS ARE MORE CROSS BROWSER COMPATIBLE THAN THE CSS ALTERNATIVE. SO IN ADDITION TO TABULAR DATA I THINK TABLES ARE ALSO FOR ALIGNING FORMS WITH EASE. IMHO. – Kalen Feb 25 '10 at 21:52
  • thanks for your comment, but please turn off your caps lock, your text is hard to read this way. – Marcel Korpel Feb 26 '10 at 04:18
  • When using tables, your form will not be rendered progressively in IE, unless you define certain attributes: http://www.iamseree.com/application-development/7-tips-made-rendering-html-faster-do-it-lately/ (tip 6) – Marcel Korpel Feb 26 '10 at 04:36

10 Answers10

3

Tables are for tabular data, that's all. Period.

Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176
  • I remember getting into a huge spitting match about this very topic on the worsethanfailure.com forum, it go pretty ugly, apparently some are very passionate about this HORRIBLE way of styling pages. – Zoidberg Feb 25 '10 at 19:46
  • And for html emails. Many email clients hate css. – Brian Feb 25 '10 at 20:07
  • Yes, I agree. Emails too, but that's not really a "web page". Yeah, some complex multi-column crazy forms need it too, unfortunately. – Diodeus - James MacFarlane Feb 25 '10 at 20:11
2

My position focuses more on web accessibility, and using tables for layout is not recommended by the W3C and it can be difficult for screen readers at times, especially when they are nested tables.

HTML should be used for structure and CSS for presentation. I'm currently battling another developer regarding eliminating layout tables unless it's absolutely needed. He insists that the forms require tables and do not work without them, but that's a crock. To me, it's just pure laziness since it means redesigning the entire website.

The formatting of web pages will eventually be done purely in CSS, so why work around it now and not doing it by following the standards? I used to hate CSS, but not I love the fact that applicable text of a page/site can be modified by just one little change within the style sheet. It saves a lot of time in the end.

JaW
  • 21
  • 1
2

You can use <dl> lists, with a little CSS work. In some ways it's less convenient (because you have to size your "label" column manually, pretty much), but in the end the markup is a lot cleaner and it's easier to deal with overall.

With tables, you're forced to group fields according to the layout, and it's totally static once it's on the page. When you use more flexible markup (and smart CSS rules), you can group your form inputs based on their natural relationships.

Pointy
  • 405,095
  • 59
  • 585
  • 614
  • +1 Because Robert nailed it. This is the case with most people, "just learn CSS" they say without explaining the reason. – the_drow Feb 25 '10 at 20:19
2

Tables are prefectly fine to display tabular data.

Styleing a form(fields/textareas and submit buttons) however is best to be done using CSS.

Spend the time to really learn HTML and CSS and it will be worth it. Eventually it will be as easy as using a table once you fully understand CSS.

ctrlShiftBryan
  • 27,092
  • 26
  • 73
  • 78
2

I take a pragmatic approach to these things. I avoid using tables for layout and use CSS if I can get away with it. I fall back to tables though, under some circumstances:

  1. I have to have the form layout correct on a lot of different browsers. CSS is easy to learn. But learning all of the idiosyncrasies of all CSS implementations and how to work around them, and how to have them work together, that can be a nightmare.
  2. There are some logical form layouts that simply cannot be expressed in CSS as it currently stands, but that CAN be expressed in tables. If you have to implement one of these layouts, you don't have much choice but to go with tables.
swestrup
  • 4,079
  • 3
  • 22
  • 33
1

Don't use tables for layouts. Use tables to store data in a chart. HTML is not a presentation language. Presentation is what stylesheets are for.

Google's code is incompetent. Its homepage is intentionally incompetent to conserve bandwidth by limiting characters in its HTML code. Its other HTML code is incompetent, because it is written by incompetent people who don't care about the value of conversing their data to the end user.

  • Ah yes, that's a good argument. Google made how many billions last year? And how many PhD's are on their staff? They must know *something.* – Robert Harvey Feb 25 '10 at 19:53
  • That is not a valid argument. Credibility does not mean anything if the results are crap. Instead of fantasizing about certifications try running their code through a validator. Apparently the PhDs on their their staff are not web developers. –  Feb 25 '10 at 19:57
  • Do you want to be *correct,* or do you want to make money? What *results* are you referring to? – Robert Harvey Feb 25 '10 at 19:58
1

I use tables for tabular data, but I also use them for data input forms, where there are a lot of data-entry fields. While this may not be considered semantically correct by some, I just find that it is damned near impossible to get everything lined up correctly without using some major CSS gyrations and hacks.

I don't use tables for structural layout, but I will use them for aligning things if it's Just SimplerTM

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
1

By introducing tables into your HTML, you make the maintainability of your code and future use a little less valuable. Browsers are constantly pushing towards an all CSS world and tables are GUARANTEED to always work for tabular data. It's just a COINCIDENCE that tables are easy to use now for formatting. The easiest way to look at it is like this:

Tables --> Tabular data and reporting
CSS --> Design and formatting (use  DIVs)
HTML --> Structure and data/text

While the tables may be easier now, think about how much maintenance it will create down the road, when browsers change their behavior with rendering tables.

Also think about mobile browsers, they tend to render tables differently. A table layout may look awesome on a PC and completely fall apart on a mobile browser.

That being said, at the end of the day you have to use CSS to design the tables, so why not start with CSS and Divs.

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
sidney.andrews
  • 5,146
  • 3
  • 23
  • 29
  • I upvoted, but I'm not sure I buy the argument that rendering for tables in future browsers is going to change much, if at all. – Robert Harvey Feb 25 '10 at 20:07
  • It's my personal opinion. I think with the advent of HTML 5, the push to pure CSS websites will be harder... I'm also putting my money on browser's giving notoriously crappy legacy HTML code support. But it's just an opinion – sidney.andrews Feb 25 '10 at 20:50
1

Tables can ease the burden in certain forms. I find pure CSS great for single-column forms, however often times I'm dealing with very complex forms with multiple columns and/or require notes, hints, indicators that make using just CSS difficult. For most forms however, pure CSS is the best route to go.

Here's a great getting started with CSS forms tutorial:

http://www.webcredible.co.uk/user-friendly-resources/css/css-forms.shtml

Keith Adler
  • 20,880
  • 28
  • 119
  • 189
1

What is the <TABLE/> good for besides tabular data? One thing I like to use it for is 9-slice buttons, so you can easily give things irregular edges or rounded corners while maintaining a center area for content. The following dummy HTML should be easy enough to follow, bearing in mind that top, left, right, and bottom images will have their repeat-x and repeat-y styles set as appropriate to allow them to expand vertically or horizontally:

<table style="border-collapse:collapse">
  <tr>
    <td><img src="top_left.png"></td>
    <td><img src="top.png"></td>
    <td><img src="top_right.png"></td>
  </tr>
  <tr>
    <td><img src="left.png"></td>
    <td> <!-- YOUR EXPANDABLE CONTENT HERE --></td>
    <td><img src="right.png"></td>
  </tr>
  <tr>
    <td><img src="bottom_left.png"></td>
    <td><img src="bottom.png"></td>
    <td><img src="bottom_right.png"></td>
  </tr>
</table>

Some will think this heresy, but I think it's damned convenient. It's layout, but on a micro level. My position is, if it works, use it.

Robusto
  • 31,447
  • 8
  • 56
  • 77
  • Heresy, and yuck! This is imho NOT convenient. Using the Sliding Doors technique with proper css is far lighter, easier to maintain, doesn't require breaking your image up into tiny chunks, and can easily accommodate DHTML events like :hover etc. – ghoppe Feb 25 '10 at 20:16
  • @ghoppe: Well, in fact the Sliding Doors technique does require you to break up your image, and what I wrote above just extends the SD concept vertically as well as horizontally. ExtJS uses the above technique and Flex implements a form of 9-slice scaling that amounts to basically the same thing (though in the Flex case without HTML tables, of course). Cheers. – Robusto Feb 25 '10 at 20:25
  • 2
    I have seen javascript lightbox plugins use this technique to ensure that the display is consistent, and admittedly it's easy to do programmatically, but I can't fathom how anyone can argue it's not easier and quicker to build a button image _once_ in CSS and simply put something like `My Fancy Button` rather than copying and pasting a bunch of heavy, bloated table HTML code. Best. – ghoppe Feb 25 '10 at 23:01
  • Quicker and simpler, perhaps. But that's not really the question, is it, when you really want something to look a certain way exactly, is it? – Robusto Feb 26 '10 at 00:44