Tables Or Lists - The HTML Calendar Debate
Posted on Wednesday, June 25th, 2008
Lists are semantic, tables are bad, right?
What seems to be the view of some in web development is now finally coming under scrutiny as mistakes are made. Put it this way, tables aren’t always bad and lists aren’t always semantic, context is important. The examples that have brought this to my attention have been quite surprising because of the amount of effort it has taken to create them.
CSS Calendars
First, a week ago Rob Glazebrook posted a list based CSS calendar at CSS Newbie and that was followed up by Chris Coyier and Tim Wright’s elastic, list based CSS calendar at CSS Tricks. Hacks and unsolved problems aside my belief is that their solutions are taking both the creators and the readers of the respective blogs down the wrong path (though thankfully Tim and Chris did finish with a disclaimer it was perhaps a little bit too far into the small print for the first few commenters who thought it was a great idea).
While I don’t disagree that a month is a ordered list of days I don’t think the markup chosen is as semantic as it can be for the presentation Rob, Tim and Chris were aiming for. As it happens there are physical calendars that are set out in a vertical list and it is perfectly reasonable to set things out as a list of days. However, grid based calendars are, well, a grid. A grid where the columns relate to days of the week as well, so why not take advantage of that.
Use the right tool for the job
I won’t say any more for now, just show some examples that I thought I’d come up with to illustrate the point. Here is a calendar using Rob’s list markup (minus the invalid clearing div as a child of the ordered list) followed by the same calendar created using a table. As you can see, with no CSS, the table is already part of the way towards the layout the list based calendars were aiming for and, because I added days of the week at the top as <th> with a scope of col a screen reader will read out the day of the week for each cell in the table it reads adding to the accessibility. To show why using the correct tool for the job makes life a lot easier, I even tidied up the table based calendar with just 4 CSS rules.
When you are creating a list of days in a month, a list is perfect, when you are creating a grid of columns of days a table suits the job. Just because you can use something else doesn’t mean you have to, the right tool for the right job not only makes your life easier but makes more sense on the page too. Have a look at my examples and decide for yourself.
If you enjoyed this post, why not subscribe to Unintentionally Blank
1June 25th, 2008 at 1:32 pm
Mike Robinson Says:I completely agree with you! I never understood why people used lists to make calender tables. However, I’m keen to read your thoughts on lists as part of form mark-up, for more complex styling situations. :)
2June 26th, 2008 at 11:07 pm
Phil Says:Hi Mike, I’m glad to see you haven’t got caught up in the folly that all tables are bad! I’ll have a think about forms and lists and send out a post next week with what I come up with.
Pingback by On Calendars, Lists, Tables and Semantics - CSSnewbie
July 3rd, 2008 at 1:59 am
Pingback by Nono Martínez » ¿Se han convertido las listas en las nuevas tablas?
July 10th, 2008 at 7:58 am
3August 16th, 2008 at 4:28 pm
Ojuicer Says:That list based CSS calendar mark-up looks awfully like a table already. When you start reinventing tables then it’s quite obviously the wrong tool for the job.
Pingback by Codigos Web » Blog Archive » ¿Se han convertido las listas en las nuevas tablas?
September 1st, 2008 at 5:54 pm
4September 15th, 2008 at 3:45 pm
xHTML Coding Says:I personally believe that there is NOTHING BAD in using lists as part of calendars.
There is a problem with mark-up tool redundancy problems, but the list type styling really does pep things up a bit!
5November 8th, 2008 at 4:53 pm
Webtlk Says:a month in an old fashioned list? ? i dont even know why people still use it! personally i go for the nice grid based calendars