CKTIS / HTML
HTML element: col
The void column element represents one or more consecutive table columns, allowing their coverage and presentation to be described together.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
<colgroup><col span="2"></colgroup>col is permitted only as a child of a colgroup that has no span attribute; as a void element it has no children or end tag.
The span attribute specifies a covered count from 1 through 1000; a missing or invalid value gives the default coverage of one column.
col does not contain td cells or create header relationships; data semantics still come from th, scope, and headers.
Only a limited set of CSS properties affects columns, including background, conditional border, visibility, and the influence of width. The example uses querySelectorAll() and sums two spans.
Examples
<!doctype html>
<meta charset="utf-8">
<table id="matrix">
<colgroup id="layout"><col id="key"><col id="values" span="2"></colgroup>
<tbody><tr><td>Key</td><td>Low</td><td>High</td></tr></tbody>
</table>
<output id="result"></output>
<script>
const matrix = document.querySelector("#matrix");
const layout = document.querySelector("#layout");
const key = document.querySelector("#key");
const values = document.querySelector("#values");
const covered = [...layout.children].reduce((sum, column) => sum + column.span, 0);
document.querySelector("#result").textContent = `cols=${layout.children.length}; covered=${covered}; keySpan=${key.span}; valueSpan=${values.span}; children=${values.childNodes.length}; cells=${matrix.rows[0].cells.length}`;
</script>
Result
cols=2; covered=3; keySpan=1; valueSpan=2; children=0; cells=3
The result verifies two elements covering three cells and the empty content model; it does not assess the table width algorithm’s final layout.