How to properly style HTML tables

Some folks would argue that you should never use tables. And, for the most part, I agree.

I believe that HTML markup should be meaningful, and therefore, you shouldn't use tags for something they weren't intended for (such as laying out a web page.) However, tables were put into the HTML standard for a reason, displaying tabular data.

For instance, if we have a database of employees and we want to print a report that contains our top performers, their salary, and contact information a table would be the perfect candidate.

Here's a fictitious example of what a web page might return from a database of employees.

<table id="employees">
    <th>First Name</th>
    <th>Last Name</th>

This, in my humble opionion is perfectly acceptable. We have tabular data that belongs in an HTML table. But, what do we do from here? The table returned is drab and needs some styling to look as sharp as the rest of the site. Let's add some style.

#employees {

#employees td, #runners th {
  border:1px solid #28647f;
  padding:3px 7px 2px 7px;

#employees th {

#employees tr.alt td {

Better! This turned our drab table from the 90's into something that looks clean and professional.

Remember, you should only use tables for displaying tabular data. If you want a good way to lay out the graphics on your web page, then check out this tutorial to help get you started.

You can view the entire web page here.

Creative Commons License

What do you think?