bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/HTML/HTML Foundations
HTML•HTML Foundations

HTML Table Colgroup

The <colgroup> element is used to style specific columns of a table.

HTML Table Colgroup

If you want to style the first two columns of a table, use the <colgroup> and <col> elements.

MONTUEWEDTHUFRISATSUN
1234567
891011121314
15161718192021
22232425262728

The <colgroup> element should be used as a container for the column specifications.

Each group is specified with a <col> element.

The span attribute specifies how many columns get the style.

The style attribute specifies the style to give the columns.

Note

There is a very limited selection of legal CSS properties for colgroups .

Example

Formatted code
  <table>
  <colgroup>
    <col span="2"
  style="background-color: #D6EEEE">
  </colgroup>

    <tr>
    <th>MON</th>
    <th>TUE</th>

  <th>WED</th>
    <th>THU</th>
...

Live preview

Note

The <colgroup> tag must be a child of a <table> element and should be placed before any other table elements, like <thead> , <tr> , <td> etc., but after the <caption> element, if present.

Legal CSS Properties

There is only a very limited selection of CSS properties that are allowed to be used in the colgroup:

width property visibility property background properties border properties

All other CSS properties will have no effect on your tables.

Multiple Col Elements

If you want to style multiple columns with different styles, use more than one <col> element inside the <colgroup> :

Example

Formatted code
  <table>
  <colgroup>
    <col span="2"
  style="background-color: #D6EEEE">
    <col span="3"
  style="background-color: pink">
  </colgroup>
  <tr>
    <th>MON</th>
    <th>TUE</th>

  <th>WED</th>
    <th>THU</th>
...

Live preview

Empty Colgroups

If you want to style columns in the middle of a table, insert an "empty" <col> element (with no styles) for the columns before:

Example

Formatted code
  <table>
  <colgroup>
    <col span="3">

  <col
  span="2"
  style="background-color: pink">
  </colgroup>
  <tr>
    <th>MON</th>
    <th>TUE</th>

  <th>WED</th>
    <th>THU</th>
...

Live preview

Hide Columns

You can hide columns with the visibility: collapse property:

Example

Formatted code
  <table>
  <colgroup>
    <col span="2">
    <col span="3"
  style="visibility: collapse">
  </colgroup>

    <tr>
    <th>MON</th>
    <th>TUE</th>

  <th>WED</th>
    <th>THU</th>
...

Live preview

Previous

HTML Table Styling

Next

HTML Lists

This chapter

Overview
56

Lessons

191m

Read time

1. HTML Tutorial2. HTML Introduction3. HTML Editors4. HTML Elements5. HTML Attributes6. HTML Headings7. HTML Paragraphs8. HTML Styles9. HTML Text Formatting10. HTML Comments11. HTML Colors12. HTML RGB and RGBA Colors13. HTML HEX Colors14. HTML HSL and HSLA Colors15. HTML Styles - CSS16. HTML Links17. HTML Links - Different Colors18. HTML Links - Create Bookmarks19. HTML Images20. HTML Image Maps21. HTML Background Images22. HTML <picture> Element23. HTML Favicon24. HTML Page Title25. HTML Tables26. HTML Table Borders27. HTML Table Sizes28. HTML Table Headers29. HTML Table Padding & Spacing30. HTML Table Colspan & Rowspan31. HTML Table Styling32. HTML Table Colgroup33. HTML Lists34. HTML Unordered Lists35. HTML Ordered Lists36. HTML Other Lists37. HTML Block and Inline Elements38. HTML Div Element39. HTML class Attribute40. HTML id Attribute41. HTML Buttons42. HTML Iframes43. HTML JavaScript44. HTML File Paths45. HTML - The Head Element46. HTML Layout Elements and Techniques47. HTML Responsive Web Design48. HTML Computer Code Elements49. HTML Semantic Elements50. HTML Style Guide51. HTML Entities52. HTML Symbols53. Using Emojis in HTML54. HTML Encoding (Character Sets)55. HTML Uniform Resource Locators56. HTML Versus XHTML

On this page

HTML Table ColgroupLegal CSS PropertiesMultiple Col ElementsEmpty ColgroupsHide Columns