bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/HTML/HTML Foundations
HTML•HTML Foundations

HTML Table Colgroup

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind HTML Table Colgroup?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

<___ span="2"
3Order

Put the learning moves in the order that makes the concept easiest to apply.

Multiple Col Elements
Legal CSS Properties
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