Base de conocimientosCentro de exámenes
ESEspañol
Elegir idioma13

CKTIS / HTML

concepto HTML: tables

Las tablas HTML describen datos cuyo significado surge de cruces fila-columna, no del mero alineamiento visual.

Versión: WHATWG HTML Living Standard; index snapshot date recorded separately

Sintaxis

<table><caption>…</caption><thead>…</thead><tbody>…</tbody></table>

table contiene un caption opcional, grupos thead, tbody, tfoot y filas tr con celdas th o td; orden y contexto siguen modelos de contenido.

rowspan puede ser rowspan="0" para abarcar las filas restantes de su grupo; sus otros tramos y colspan son positivos y las celdas no deben solaparse.

En encabezados simples, scope usa row o col; una tabla compleja vincula headers con valores id. Una tabla no sirve para maquetar páginas.

El ejemplo lee caption, las colecciones rows y tBodies, cellIndex y los headers y scope explícitos.

Ejemplos

<!doctype html>
<meta charset="utf-8">
<table id="prices">
  <caption>Prices</caption>
  <thead><tr><th id="product" scope="col">Product</th><th id="amount" scope="col">Amount</th></tr></thead>
  <tbody><tr><th id="widget" scope="row">Widget</th><td id="price" headers="widget amount">9</td></tr></tbody>
</table>
<output id="result"></output>
<script>
const table = document.querySelector("#prices");
const cell = document.querySelector("#price");
result.textContent = `caption=${table.caption.textContent}; rows=${table.rows.length}; bodies=${table.tBodies.length}; cellIndex=${cell.cellIndex}; headers=${cell.headers}; rowScope=${widget.scope}`;
</script>

Resultado

caption=Prices; rows=2; bodies=1; cellIndex=1; headers=widget amount; rowScope=row

El resultado confirma cuadrícula DOM y asociaciones declaradas; no simula un lector de pantalla ni encabezados complejos.

Fuentes