HTML Table, colgroup, col

By Xah Lee. Date: . Last updated: .

HTML table has a <colgroup> tag. It is used to indicate that several columns are a group.

<colgroup> has no effect on the rendering of the table, but is useful together with CSS to color columns (instead of adding a style to every td tag). [see CSS Basics]


1,1 1,2 1,3 1,4 1,5 1,6 1,7 1,8 1,9
2,1 2,2 2,3 2,4 2,5 2,6 2,7 2,8 2,9

Here's the source code:

<table border="1">
<colgroup span="1" style="background-color:silver"></colgroup>
<colgroup span="3" style="background-color:aqua"></colgroup>
<colgroup span="2" style="background-color:yellow"></colgroup>
<colgroup span="3" style="background-color:gray"></colgroup>


The colgroup tag must come before any {tr, thead, tbody, tfoot}. [see HTML Table, thead, tbody, tfoot]

Using 「col」 tag

Alternatively, you can also use the col tag instead of <colgroup span="…">.

1,1 1,2 1,3 1,4 1,5 1,6 1,7 1,8 1,9
2,1 2,2 2,3 2,4 2,5 2,6 2,7 2,8 2,9

Here's the relevant source code:

<colgroup style="background-color:silver"><col span="1" /></colgroup>
<colgroup style="background-color:aqua"><col span="3" /></colgroup>
<colgroup style="background-color:yellow"><col span="2" /></colgroup>
<colgroup style="background-color:gray"><col span="3" /></colgroup>

The col tag must always be used inside colgroup.

Alternatively, you can just repeat the col tag instead of using the span attribute. For example, write:

<colgroup><col /><col /></colgroup>

instead of:

<colgroup><col span="2" /></colgroup>

Browser Support

The colgroup and col tags are supported in all major browsers as of 2011-07-30.

HTML Basics

  1. HTML Basics
  2. HTML5 Tags
  3. Case Sensitivity
  4. Allowed Characters
  5. Charset and Encoding
  6. Self-Closing Tags
  7. Multiple Class Value
  8. HTML Entity List

HTML Table

  1. HTML Table Examples
  2. HTML Table, thead, tbody, tfoot
  3. HTML Table, colgroup, col
  4. Styling HTML Table with CSS
  5. CSS: 3 Columns Page Layout
  6. Pure CSS Table


  1. Viewport Meta
  2. the Root Element
  3. iframe
  4. video
  5. audio
  6. figure
  7. dl, dt, dd
  8. s strike del
  9. time
  10. meter
  11. progress
  12. q
  13. address
  14. canvas
  15. ruby
  16. HTML5 Custom Data Attribute
  17. Big Tag
  18. Image Maps
  19. Marquee, Scrolling Text
  20. How to Markup Subtitle
  21. Meta Language Tag Obsolete
  22. Browser Auto Refresh

HTML4 Frameset

  1. HTML: Split Windows; Frameset
  2. HTML Nested Frameset
Like it? Help me by telling your friends. Or, Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials