Table (td/th) Attributes: colspan & rowspan

The colspan and rowspan attributes are available if you need to make a td or th take up more than one cell. colspan specifies the number of columns a cell spans -- expanding the cell horizontally (it's counterintuitive if you don't think about it). Likewise for rowspan. Be careful: these are used more often with table layouts than normal data tables. Table layout should generally be avaoided in favor of absolute positioning or other layouts. The other use, as in Lab 7, is avoidable with the <caption>

Basic example

colspan rowspan ex

Things to note:

  • The 2nd row has only 4 cells (don't forget that th...)
  • The 4th and 5th rows all lose a cell to the td with rowspan on the 3rd row.
  • The 2x2 square 9 in the bottom right has both colspan and rowspan set.
See also Box Model, border-collapse, td, th, caption , tr, and <table>.
Back to Knowledge Dump