Search code examples
htmlcsshtml-table

HTML table colgroup element is not working


I want different styles on each column of a table. I've read that you could do that by using <colgroup> or <col>, but I had no luck. I have an example here, and nothing seems to change. Am I doing something wrong? Will this work on XHTML?

I know I could add a "class" attribute on each <td>, but that seems weak.


Solution

  • That's correct. While colgroup itself is supported by all browsers, this isn't true for the attributes of the inner col element. Of possible attributes, only width is supported on all browsers. But unlike CSS, <col width=""> only supports pixel and percentage widths.

    Don't use it. Instead, create CSS classes and assign them to each td. Yes, it sucks.