Alex Rivera | Logout

Can HTML table have variable number of cells on rows?

Asked 2010-08-14T19:22:11.373
23

Or should the total amount of cells equal to columns * rows?

A table with different amount of cells on different rows seems to pass the W3 Validator.

Edit
Report

1 Answer

4

Yes, it can. In table > tr > td, td is contain the content. Td reference here: http://www.htmlcodetutorial.com/tables/_TD.html. In that reference, you can see that TD has 2 attributes that is: colspan and rowspan. By using those 2 attributes, a table can have different amount of cells on different rows.
Demo:

<table border="1">
     <tr>
          <td>a</td>
          <td>b</td>
     </tr>
     <tr> 
          <td colspan="2">c</td>
     </tr>
</table>

And

<table border="1">
     <tr>
          <td rowspan="2">a</td>
          <td>b</td>
     </tr>
     <tr> 
          <td>c</td>
     </tr>
</table>
answered 2010-08-14T19:28:43.527

Your Answer