Tables

Estimated reading: 1 minute 118 views

Tables are a way to represent complex
information in a grid format.
Tables are made up of rows and
columns

<table>
 <tr>
 <th>Head</th>
 <th>Head</th>
 </tr>
 <tr>
 <td>Data</td>
 <td>Data</td>
 </tr>
</table>
HeadHead
DataData
Tables can be styled with CSS to add
zebra striping or to highlight important
rows/columns.
Extra functionality can be added to
tables like filtering or sorting rows and
columns.

Set the first column to 70% of the table width

Firstname Lastname Age
Jill Smith 50
Eve Jackson 94
John Doe 80
				
					<table style="width:100%">
  <tr>
    <th style="width:70%">Firstname</th>
    <th>Lastname</th> 
    <th>Age</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td>
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
  </tr>
  <tr>
    <td>John</td>
    <td>Doe</td>
    <td>80</td>
  </tr>
</table>
				
			

HTML Table - Colspan To make a cell span over multiple columns, use the colspan attribute:

Name Age
Jill Smith 43
Eve Jackson 57
				
					<table >
  <tr>
    <th colspan="2">Name</th>
    <th>Age</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td>
    <td>43</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td>
    <td>57</td>
  </tr>
</table>
				
			

HTML Table - Rowspan To make a cell span over multiple rows, use the rowspan attribute:

Name Jill
Phone 555-1234
555-8745
				
					<table>
  <tr>
    <th>Name</th>
    <td>Jill</td>
  </tr>
  <tr>
    <th rowspan="2">Phone</th>
    <td>555-1234</td>
  </tr>
  <tr>
    <td>555-8745</td>
</tr>
</table>
				
			

HTML Table Colgroup If you want to style the two first columns of a table, use the colgroup and col elements.

MON TUE WED THU FRI SAT SUN
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
				
					<table style="width: 100%;">
<colgroup>
  <col span="2" style="background-color: #D6EEEE">
</colgroup>
<tr>
<th>MON</th>
<th>TUE</th>
<th>WED</th>
<th>THU</th>
<th>FRI</th>
<th>SAT</th>
<th>SUN</th>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
</tr>
<tr>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
</tr>
<tr>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>19</td>
<td>20</td>
<td>21</td>
</tr>
<tr>
<td>22</td>
<td>23</td>
<td>24</td>
<td>25</td>
<td>26</td>
<td>27</td>
<td>28</td>
</tr>
</table>
				
			
Share this Doc

Tables

Or copy link