Table Colgroup Span Column Styling

Apply column level styling and spanning using colgroup and col elements for efficient table layout control.

HtmlData Fetching

Code

htmlsnippet
14 lines
<table>
  <colgroup>
    <col style="width: 200px; background: #f0f0f0;" />
    <col span="2" style="text-align: right;" />
    <col style="width: 100px;" />
  </colgroup>
  <thead>
    <tr><th>Name</th><th>Price</th><th>Qty</th><th>Total</th></tr>
  </thead>
  <tbody>
    <tr><td>Widget</td><td>$10</td><td>5</td><td>$50</td></tr>
    <tr><td>Gadget</td><td>$25</td><td>3</td><td>$75</td></tr>
  </tbody>
</table>

What the code does

<colgroup>/<col> apply column-level width and styling without repeating attributes on every cell.

Statements that matter

<col style="width: 200px; background: #f0f0f0;" />
<col span="2" style="text-align: right;" />
<col style="width: 100px;" />

Interactive Tools for This Topic

FAQ

Which non-generic elements does the markup use?
`<table>`, `<colgroup>`, `<col>`, `<thead>`, `<tr>`, `<th>`, `<tbody>`, `<td>` — each carries native semantics (or a browser behavior) that generic containers do not.