Chapter 6 - Table Tags
Chapter 6 - Table Tags
HTML Table:
HTML table tag is used to display data in tabular form (row * column). There can be many columns in
a row. We can create a table to display data in tabular form, using <table> element, with the help of
<tr> , <td>, and <th> elements. In Each table, table row is defined by <tr> tag, table header is defined
by <th>, and table data is defined by <td> tags. HTML tables are used to manage the layout of the
page e.g. header section, navigation bar, body content, footer section etc. But it is recommended to
use the div tag over the table to manage the layout of the page .
Tag Description
S
<tbody>
<thead>
<tfoot>
<caption>
It is used to group the body content in a table.
Example:
<table>
<tr>
<th>First_Name</th>
<th>Last_Name</th>
<th>Marks</th>
</tr>
<tr>
<td>Sonoo</td>
<td>Jaiswal</td>
<td>60</td>
</tr>
<tr>
<td>James</td>
<td>William</td>
<td>80</td>
</tr>
<tr>
<td>Swati</td>
Table Attributes:
1) Border Attribute: You can use the border attribute of table tag in HTML to specify the
border.
Example:
<table border="1">
2) Cell Padding and cell spacing: There are two attributes called cellpadding and
cellspacing which you will use to adjust the white space in your table cells. The cellspacing
attribute defines space between table cells, while cellpadding represents the distance
S
Example:
between cell borders and the content within a cell.
3) Colspan and rowspan attribute: You will use the colspan attribute if you want to
merge two or more columns into a single column. Similarly you will use rowspan if you want
IIC
to merge two or more rows.
Example:
<table border = "1">
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
<tr>
<td rowspan = "2">Row 1 Cell 1</td>
<td>Row 1 Cell 2</td>
<td>Row 1 Cell 3</td>
</tr>
<td colspan = "3">Row 3 Cell 1</td>
</tr>
</table>
4) Bgcolor: You can set background colour for the whole table or just for one cell.
Example:
<table border = "1" bordercolor = "green" bgcolor = "yellow">
5) Height and width attribute: You can set a table width and height using width and
height attributes. You can specify table width or height in terms of pixels or in terms of
percentage of available screen area.
Example:
<table border = "1" width = "400" height = "150">
7) Colgroup element:
Example:
<table>
<colgroup>
<col span="2" bgcolor=”red”>
</colgroup>
S
IIC