Table tag in HTML

Table tag in HTML

The table tag a very important tag in the HTML language. A table consists of rows and columns. The data in a table is more readable and easy to understand. In the table, we can present the data in sort form. There are three main elements in HTML for building tables. These are the tags <th>, <tr> and <td> is used in the table tag.

The <th> is used to define the table heading. The <tr> is used to define the table rows and the <td> is used to define the table column. The table tag is used to define a table. <tr> tag is used to define a row in a table and <td> tag is used to define a data cell. <th> tag is used to define the header row of the table.

Attributes of Table Tag

AttributesDescription
AlignIt specifies the horizontal alignment of the table. Possible alignments are left, right, and center.
ValignIt specifies the vertical alignment of the table. Possible alignments are top, bottom, and middle.
WidthIt specifies the width of the table. It can be given as the number of pixels or as a percentage relative to the screen.
BorderIt specifies the thickness of the border of the table.
CellpaddingIt specifies the distance between data in the cell and cell boundaries.
CellspacingIt specifies the spacing between adjacent cells of the table.
col spanIt specifies the number of columns for a cell. It is used inside or tags. A cell may consist of many columns.
RowspanIt specifies the number of rows for a cell. It is used inside or tags. A cell may consist of many rows.



The <tr> tag

The <tr> tag is used to create a row in the table tag. TR stands for table row.

Attributes of <tr> tag:

Some important attributes of <tr> tag are as follows:

AttributeDescription
AlignIt specifies the horizontal alignment of the row. Possible alignments are left, right and center
Bg-colorBg-color It specifies the color of the background for the row
ValignIt specifies the vertical-align the content of the row. The possible values are top, middle or bottom

The <td> tag

The <td> tag is used to create cells in the row of a table tag. TD stands for table data. You can say that this tag is used to create the column fo the table tag.

Attributes of <td> tag

Some important attributes of <td> tag are as follows:

AttributesDescription
AlignIt specifies the horizontal alignment of the cell. Possible alignments are left, right and center.
BackgroundIt specifies the background image inside of the table cell
Bg-colorIt specifies the color of the background of the cell
col spanIt stretches the length of the cells to 2 or more cell lengths
HeightIt specifies the height of the cell in pixels
nowrapIt locks the content so that it all stays on the same line
RowspanIt stretches the height of the cells to 2 or more cells
ValignIt specifies the vertical alignment of the content of the cell. The possible values are top, middle or bottom
WidthIt specifies the width of the actual cell in pixels or percentage

Example

<!DOCTYPE html>
<html>
<head>
	<title>table in HTML</title>
</head>
<body>
	<h3>Tables in HTML</h3>
	<table border="1" width="200px" align="center">
		<tr>
			<th>Roll NO.</th>
			<th>Marks:</th>
		</tr>
		<tr>
			<td>1</td>
			<td>89</td>
		</tr>
		<tr>
			<td>2</td>
			<td>91</td>
		</tr>
		<tr>
			<td>3</td>
			<td>78</td>
		</tr>
	</table>
</body>
</html>

Output

table tag

Reference

If you want to learn more about HTML or image tag then visit the official website: Visit

Visit the HTML tutorial list. And make strong your HTML concept. Click here. wuschools.com is always written about the HTML concept for the HTML lover. Ang writes about how HTML makes your life easy if you are a web site developer. We help you to continue your learning.

Leave a Reply

Close Menu