JavaScript Tutorial

HTML Table

HTML table provides a way to derive or define the data such as text, images, links, etc in terms of rows and columns of cells. HTML Tables are used for formatting data using Rows and Columns. 

It is used to display data in tabular form (row * column). There can be many columns in a row. An HTML table consists of one <table> element and one or more <tr>, <th>, and <td> elements.

In Each table, the table row is defined by <tr> tag, the table header is defined by <th>, and table data is defined by <td> tags.

Tag

Description

<table>

This HTML Tag defines a table.

<tr>

This Tag defines a row in a table.

<th>

This Tag defines a header cell in a table.

<td>

This Tag defines a cell in a table.

<caption>

This tag is used for the table caption.

<colgroup>

It specifies a group of one or more columns in a table for formatting.

<col>

This HTML Tag is used with <colgroup> element to specify column properties for each column in HTML Table.

<tbody>

It is used to group the body content in an HTML table.

<thead>

It is used to group the header content in a table.

<tfooter>

It is used to group the footer content in a table.

Basic HTML Table Usage

A basic HTML Table will have all the attributes like <td, <tr>,<th>, and <table>.

 

Table Caption

The caption for the table is specified by using the <caption> tag. It is used to describe the table.

 

HTML Table Cell Spacing

The space of the table cells can be defined by using the "cellspacing" attribute. The "cellspacing" attribute specifies the space between table cells.

 

HTML Table Cell Padding

The padding of table cells can be defined using the "cellpadding" attribute. The "cellpadding" attribute determines the distance between the table cell border and the data within the cell.

 

HTML Table Colspan and Rowspan

Multiple HTML table rows can be merged into a single row by using the "rowspan" attribute, while multiple table columns can be merged into a single column by using the "colspan" attribute.

Setting colors for Table

To create a background color for a table, you can use the "bgcolor" attribute. To specify the border color for table cells, you can use the "border-color" attribute.

Table Height and Width

The height and width of the table can be set by using width and height attributes.

Nested Table

We can also embed one table inside another table known as a nested table.

Supporting Browsers

Element

“Google Chrome

Microsoft

Firefox

Opera

Safari

Table

Yes

Yes

Yes

Yes

Yes

Go back to Previous Course