Ask HN: Seriously, what's wrong with HTML tables?
15 points| anthonycerra | 15 years ago | reply
Can anyone give specific reasons why it's unwise to use tables for anything other than displaying tabular data?
15 points| anthonycerra | 15 years ago | reply
Can anyone give specific reasons why it's unwise to use tables for anything other than displaying tabular data?
[+] [-] ggchappell|15 years ago|reply
http://phrogz.net/CSS/WhyTablesAreBadForLayout.html
Not that I agree with him entirely. In particular:
> 6. Once you know CSS, table-based layouts usually take more time to implement.
For a sizable site with layouts reused over multiple pages, yes. For a single page, or a site with differing layouts for each page, in my experience, no. Actually, I'd extend that first sentence of mine into a new reason: with CSS you can specify your layout once, and not have to redo it for every page. Doesn't work with tables.
> 7. Tables are semantically incorrect markup for layout.
My response: So what? (Yes, I know about the problems with screen readers, but that's a different reason, one I happen to agree with.)
And then, on the other hand, there are the things no one wants to say: the advantages tables have over CSS. In particular, it's obvious to me that CSS was not designed with modern layouts in mind. The fact that it works at all is really just an accident: it turned out that you can make columns using floats (how 'bout that?). Yes, using tables for layout is a kind of jury-rig, but to be honest, so is using CSS. And at least tables have a mechanism for producing columns, that was designed with columns in mind.
And then there are the browser rendering inconsistencies. With modern browsers, these problems are fading, but for older ones, the inconsistencies with CSS seem to be much more troublesome than those with tables.
[+] [-] rimantas|15 years ago|reply
And anyone who thinks that tables are easier to deal with either did not work enough with CSS or did not care enough. In 1996-2003 I was building stuff tables way, in 2004 I went full CSS and never looked back.
[+] [-] anthonycerra|15 years ago|reply
[+] [-] patio11|15 years ago|reply
[+] [-] zackattack|15 years ago|reply
[+] [-] absconditus|15 years ago|reply
http://stackoverflow.com/questions/83073/why-not-use-tables-...
[+] [-] anthonycerra|15 years ago|reply
[+] [-] alanh|15 years ago|reply
[+] [-] ltbarcly3|15 years ago|reply
Look at the source to amazon.com, netflix.com, google.com, bing.com. It's hard to find any big site that doesn't use tables for at least some layout tasks.
CSS is a really, really shitty method of doing layout. Fanboys will come out of the woodwork to try and prove that statement wrong, but in my opinion, it's true. I'm not sure how we ended up with such a terrible tool.
There are times when I have spent 10 hours trying to do some trivial bit of layout done with CSS, and finally resorting to a little table got it done instantly.
There are entire classes of things that you can't do with CSS, or you have to resort to bizarre hacks to get done (negative padding, etc).
I'm not claiming that tables solve every problem, but presented with the choice of spending hours figuring out some css hack and testing it in the dozens of browsers / mobile browsers that are out there now, and just making a table, I will just make the table and move on.
Edit: You should use CSS 90% of the time. Tables often let you do something easily that CSS has lots of trouble with, and I recommend resorting to them at that point.
[+] [-] pbhjpbhj|15 years ago|reply
Amazon doesn't declare a doctype or character encoding. They have 7 blocks of inline CSS, there page is a dog to load. They have nested tables for non-tabular data, the don't encode entities (&, etc), they use non-existent (in spec) attribute values, don't declare all script types, don't add all alt attributes, they use a mixture of XHTML and HTML (mixed use of self-closing tags and unclosed tags), etc., etc..
So I guess big sites just don't care about web standards.
I can't imagine how insane it would drive you trying to navigate Amazon's site with a screenreader.
[+] [-] drivebyacct2|15 years ago|reply
[+] [-] bsk|15 years ago|reply
- At one point the design becomes a nightmare to maintain. I've worked on some web apps, where we had pages with 15 levels deep tables in tables in tables ...
- Separating the semantic information in .html from the design in .css. Can help with SEO, screen readers, cashing.
[+] [-] rimantas|15 years ago|reply
[+] [-] rycole|15 years ago|reply
[+] [-] dgreensp|15 years ago|reply
There are only two big uses for tables that I would avoid, and which are probably how this all started:
- Don't put all your content in giant tables for multiple columns, etc. Browsers do have to go to some effort to calculate column widths and such, and may delay rendering the contents of the table, e.g. until all the dependencies like inline images are loaded.
- Don't try to use big hairy pixel-precise tables for freeform layout, like when designers would carve up a mock in Photoshop, export the "slices" as 14 different images, and reassemble them using tables. This is a maintainability and usability nightmare and will come back to bite you.
People can get really dogmatic about not using tables. Perhaps you could find some forms you like and see what kind of mark-up they use.
[+] [-] barrydahlberg|15 years ago|reply
In the past we've seen huge messes of tables nested upon tables which creates bloated, inflexible HTML. This is usually done by people who would create huge bloated messes of divs anyway. What you should really be focusing on is creating clean, valid markup written with a sense of style and care.
CSS frameworks like Blueprint can make getting started with layout a lot easier for you if don't mind having an argument about the abuse of CSS as well.
[+] [-] anthonycerra|15 years ago|reply
[+] [-] hasenj|15 years ago|reply
Now adays these things can happen with CSS, and you should use css to get spacing and positioning done right.
However, for layout, I completely disagree with the mainstream idea that "divs and css are better than tables for layout".
#1 argument, they say, is that tables are semantically incorrect for layout.
Well then, are divs semantically correct for layout? Absolutely not. Actually, tables are semantically correct for layout.
How else do you express stacking elements vertically and horizontally?
Floating divs to create layout is a horrible hack, and it's not maintainable at all.
Use tables to get the basic layout, but do all the styling with css.
[+] [-] pbhjpbhj|15 years ago|reply
Adding a div adds no semantic meaning to the page. Adding a table tells you that the elements in the different columns and rows relate to one another, that the rows or columns duplicate data types that the td have relationships with one another as data.
Tables are semantically correct for arranging data that is related correctly when presented in a table; but this is not "layout" in terms of visual appearance. The semantics of the data table aren't necessarily related to the layout - imagine a table of <name,image,date> tuples that you arrange as floating polaroid imges using some javascript.
>How else do you express stacking elements vertically and horizontally?
If ordering is important for the meaning of the data then use lists (ol) if 2D ordered data is being presented then you have a table and using the table element is expected.
The web is not print media and was designed to convey information (to myriad different UA) and not to give rigid print-like presentation of that same information.
[+] [-] icey|15 years ago|reply
Tabular data goes in tables (including forms for the most part). Everything else goes in a DIV (or SPAN, I guess).
That being said, all of my tables are put inside of DIVs for layout.
(Also, I'm not a designer)
[+] [-] robenkleene|15 years ago|reply
The dogmatic view, that marking up your document with as few, strictly semantic tags as possible is ideal, has died down in recent years. I advocate the following approach: create your design and initial as-semantic-as-possible HTML. Starting doing the CSS, you run into problems that a table would help with? Either adapt the design, or just put in the table -- your guiding light should be semantic markup is great, but it isn't worth adding hard-to-maintain HTML/CSS hacks to your design in order to keep your markup perfect.
In otherwords, HTML/CSS hacks are worse than some bad markup here and there.
Always keep in mind that the HTML/CSS revolution was a _blogging_ movement. Usually keeping the markup strictly semantic is easy for a blog, as blogs are textual documents -- the type of data that and HTML/CSS were originally designed for.
I personally mainly work on web applications (think lots of buttons and forms), HTML/CSS perform far worse in this context. And I've wasted a lot of time extrapolating what is good advice for a blog to web applications were it can be terrible advice.
[+] [-] qeorge|15 years ago|reply
But the larger reason, the why, is that its easier for a computer to parse. If you want to be part of the Semantic Web[1], you should make your pages as machine-readable as possible. Makers of screen readers will thank you too.
<table> means tabular data, not layout. But since no one follows that, parsers first have to determine which way you meant <table>. This is an unneeded complication. If everyone used the right tags (<div> and <span> for layout, everything else is semantic), writing a parser would be insanely easy and we could spend our time on more interesting problems.
[1] http://en.wikipedia.org/wiki/Semantic_Web
[+] [-] _b8r0|15 years ago|reply
I'm sure some day someone will come up with some sort of standard that allows a regular website to look good on multiple devices with multiple capabilities, perhaps some sort of file containing style information that could tell the browser how to structure different sections.
[+] [-] DjDarkman|15 years ago|reply
You can't easily change complex table-based layouts, because you get lost in the td-s and tr-s.
You can make forms even easier with some clever CSS.
[+] [-] stephenou|15 years ago|reply
Or, imagine building Facebook/Twitter using <table></table>.
[+] [-] abrudtkuhl|15 years ago|reply
Tables != Layout
[+] [-] sammcd|15 years ago|reply
Tables became bad, and CSS became good. So much that some people where using divs to show data for a while just because they hated tables so much.
[+] [-] JustinSeriously|15 years ago|reply
Same reason that, when you code, you want to include comments, have good variable names, use reasonably-sized functions, etc. It makes maintainability and future extension much easier.
Forget about semantic purity. CSS has survived all these years because it's been very useful in a very practical sense.
[+] [-] towndrunk|15 years ago|reply
[+] [-] julianz|15 years ago|reply
[+] [-] notahacker|15 years ago|reply
[+] [-] zoomzoom|15 years ago|reply