September 08, 2003

A Middle Ground for HTML Layout

Web designers can be divided into two groups. In one group are those who want precise layout, who use design tools such as Dreamweaver, and who could care less about using CSS for page layout. You can easily recognize the HTML that these designers produce, as it contains deeply nested <table> elements. In the other group are those who prefer a more fluid, flexible layout based on CSS. The goal of the designers in this group is to create layouts that use <table> elements only for tabular data, and never for layout. Their mantra is "separation of content and presentation."

(I suppose I fall more into the second group of designers, though I would never claim to have real talent in graphical design.)

Those who insist on CSS layout claim that good layout without tables is possible. That's true. But layout without tables is hard! One of the reasons it's hard, is because Internet Explorer does not support the features of CSS that would make it easier. However, even if IE did have near-perfect support for CSS Level 2, layout with style sheets would still be hard. Anyone who has programmed graphical user interfaces for desktop applications understands this. In GUI development, the layout is controlled by program code, often by a layout manager. One of the most capable layout managers available to Java programmers is the GridBagLayout. What's interesting, is that the GridBagLayout provides layout capabilities that are very similar the layout capabilities of HTML tables.

So, considering that a grid -- or shall we say it? a table! -- is a useful layout device in GUI programming, why isn't it a useful layout device in HTML layout? The answer, of course, is that a table is a useful device for HTML layout. I think there is a bit of history behind the situation that we should consider. Yes, back in the early days of HTML, tables were for presenting tabular data. But since there was no <grid> element for layout, designers started using the <table> element for layout.

I don't think it will ever happen, but why don't we add a <grid> element to HTML? Then, we could have a decent layout manager for HTML pages. Current HTML provides frames, which divide up the browser window into discrete areas. Couldn't future HTML provide a grid layout, with appropriate tags, that similarly divides the browser window? Constraints could be specified as attributes to the HTML elements. If implemented correctly, a grid layout would make it simple to create many of the most commonly used web page layouts, such as the popular three column layout with a header and a footer.

Posted by Doug Sauder at September 8, 2003 07:15 PM