HTML Tags Web development basics

HTML Table

HTML Table is build using HTML <table> element.

HTML Table Tag

Tag Description
<table> Defines a table
<th> Defines a header cell in a table.Text in <th> is displayed in bold.
<table> <th>Header value </th> </table>
<tr> Defines a row in a table. It is the container for table data elements. A row is collection of cells.
<table> <tr> <td> data</td> </tr> </table>
<td> Defines a cell in a table.
<table> <td>data value </td> </table>
<caption> Defines a table caption.
<caption> caption..</caption>
<colgroup> Specifies a group of one or more columns in a table for formatting.Eg.
<colgroup> <col span="2" border="4"> </colgroup>
<col> Specifies column properties for each column within a <colgroup> element
<thead> Groups the header content in a table
<tbody> Groups the body content in a table
<tfoot> Groups the footer content in a table

Attributes for <table> element

Here we will discuss only the attribute in basic HTML

Colspan attribute

Colspan attribute defines the number of column that a cell should span.



colors Unit
red Yellow 2

Rowspan attribute

rowspan attribute defines the number of rows that a cell should span.



3A 2D

Bgcolor attribute

Add a background color to td or table elements.

colors Unit
Green 2

Frame attribute

It is used to control the display of the outermost border of the table. It has precedence over the border attribute.


colors Unit
Green 2

Values it can hold are:

Value Description
void The outside borders are not shown
above The top outside border is shown
below The bottom outside border is shown
hsides The top and bottom outside borders are shown
vsides The left and right outside borders are shown
lhs The left outside border is shown
rhs The right outside border is shown
box The outside borders are shown on all four sides
border The outside borders are shown on all four sides


The border attribute is used to define width of the table border. By default, table has no border. When we apply border attribute, a border appears. The default thickness of border is "1".



One Two
Three Four


Sets horizontal alignment of the text.Possible values are Right, Left, Center.



Determines the width of the table. Possible value can be defined in terms of pixels or percentages. It can also be used to determine width of a column i-e in <td> element



Defines the space between the cell content and the border of the table.



Defines space between two cells within the table.