<colgroup>


HTML <colgroup> Tag

Instance

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文网(php.cn)</title> 
</head>
<body>

<table border="1">
  <colgroup>
    <col span="2" style="background-color:red">
    <col style="background-color:yellow">
  </colgroup>
  <tr>
    <th>ISBN</th>
    <th>Title</th>
    <th>Price</th>
  </tr>
  <tr>
    <td>3476896</td>
    <td>My first HTML</td>
    <td></td>
  </tr>
  <tr>
    <td>5869207</td>
    <td>My first CSS</td>
    <td></td>
  </tr>
</table>

</body>
</html>

Run Example»

Click the "Run Instance" button to view the online instance


Browser support

1000.png

##All major browsers support the <colgroup> tag .


Tag definition and usage instructions

<colgroup> Tags are used to group columns in the table in order to format them.

By using the <colgroup> tag, you can apply styles to an entire column without having to repeatedly style each cell or row.

Note: can only be within the <table> element, after any <caption> element, and within any <thead>, <tbody>, < Use the <colgroup> tag before the tfoot> and <tr> elements.

Tip: If you want to define different attributes for a column in <colgroup>, please use the <col> tag inside the <colgroup> tag.


Differences between HTML 4.01 and HTML5

Most attributes from HTML 4.01 are no longer supported in HTML5.


Properties

PropertiesValueDescriptionalignleftcharcharoffspanSpecifies the number of columns that the column group should span. valigntopwidth
Right
center
Justify
char
HTML5 is not supported. Specifies the horizontal alignment of content in column combinations.
characterHTML5 Not supported. Specifies which character should be used to align the contents of the column group.
numberHTML5 Not supported. Specifies the offset of the first alignment character.
number
middle
bottom
Baseline
HTML5 is not supported. Define the vertical alignment of content in a column combination.
pixels %
relative_length
HTML5 Not supported. Specifies the width of the column combination.


##Global attributes

<colgroup> tag supports global attributes of HTML.

Event attributes

<colgroup> tag supports HTML event attributes.