HTML Table

You use html table to represent any data in a structured form. By adding tables to your webpage, you can also make it look structured toward it and attractive.

Student Name Class Roll No.
Rohit 10 th 032
Mohit 12 th 036
Ram 12 th 037
Raman 12 th 039
Kajal 10 th 040
Madhuri 10 th 041
Neha 10 th 042
Nidhi 12 th 044
Rupali 10 th 046

To create tables in HTML, you use <table> tags. This tag has a sub tag called table row tag. The <table> tag also has a sub tag called table data tag.

Example

[html]<!DOCTYPE html>
<html>
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}

td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}

tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>

<table>
<tr>
<th>Student Name</th>
<th>Class</th>
<th>Roll No.</th>
</tr>
<tr>
<td>Rohit</td>
<td>10 th</td>
<td>032</td>
</tr>
<tr>
<td>Mohit</td>
<td>12 th</td>
<td>036</td>
</tr>
<tr>
<td>Ram</td>
<td>12 th</td>
<td>037</td>
</tr>
<tr>
<td>Raman</td>
<td>12 th</td>
<td>039</td>
</tr>
<tr>
<td>Kajal</td>
<td>10 th</td>
<td>040</td>
</tr>
<tr>
<td>Madhuri</td>
<td>10 th</td>
<td>041</td>
</tr>
<tr>
<td>Neha</td>
<td>10 th</td>
<td>042</td>
</tr>
<tr>
<td>Nidhi</td>
<td>12 th</td>
<td>044</td>
</tr>
<tr>
<td>Rupali</td>
<td>10 th</td>
<td>046</td>
</tr>
</table>

</body>
</html>[/html]

Creating Tables in HTML

Any table is made of row and columns. Therefore, to create a row after tag, you use tag. The more you want to create the rows, define the same tag.

After creating rows you create columns in rows. The tag is used to create columns. You define as many tags as you want to create tags.

An example of this is being given below.

[html]<!DOCTYPE html>
<html>
<head>
<title>HTML Table</title>
</head>
<body>
<table border="1">
<tr>
<td>First row first column</td>
<td>First row second column</td>
</tr>
<tr>
<td>Second row first column</td>
<td>Second row second column</td>
</tr>
</table>
</body>
</html>[/html]

The above script generates the given web page.