Skip to main content

Tables in HTML

How to Use Table tag in HTML

In this blog we understand the table elements in HTML. How to Create a Tables in HTML
Firstly we understand table elements. 
1. when we create a table in editor type with <table>
2. after that we create a table row with <tr>
3. between <tr> we create table data <td>
see it into sublime text editor

<body>

<table border="1px">
<caption> Student Data</caption>
<tr>
<td> Name</td>
<td>Roll NO</td>
<td>Marks</td>
<td>total Marks</td>
<td>Percentage</td>
</tr>
<tr>
<td> JOhn</td>
<td>32655</td>
<td>250</td>
<td>500</td>
<td>50%</td>
</tr>
<tr>
<td> Carter</td>
<td>1254</td>
<td>250</td>
<td>500</td>
<td>50%</td>
</tr>
</table>

We use <caption> tag inside the Table. That means it is heading of table. it is automatically take a width in table.

What is Colspan & Rowspan

COLSPAN : it is used for merged two columns in one. 
ROWSPAN: it is used for merged rows in one.

Lets See in Example:
Without Colspan


With colspan


Code is Here for Colspan:
<table border="1px">
<caption> Student Data</caption>

<tr>
<td colspan="5" align="center"> STUDENTS OF OUR SCHOOLS </td>
</tr>
<tr>
<td> Name</td>
<td>Roll NO</td>
<td>Marks</td>
<td>total Marks</td>
<td>Percentage</td>
</tr>
<tr>
<td> JOhn</td>
<td>32655</td>
<td>250</td>
<td>500</td>
<td>50%</td>
</tr>

<tr>
<td> Carter</td>
<td>1254</td>
<td>250</td>
<td>500</td>
<td>50%</td>
</tr>
</table>

Let see Rowspan in HTML

With Rowspan


Code: <table border="1px">
<caption> Student Data</caption>

<tr>
<td colspan="5" align="center" bgcolor="#AAB7B8"> STUDENTS OF OUR SCHOOLS </td>
</tr>
<tr>
<td> Name</td>
<td>Roll NO</td>
<td>Marks</td>
<td>total Marks</td>
<td>Result</td>
</tr>
<tr>
<td> JOhn</td>
<td>32655</td>
<td>250</td>
<td>500</td>
<td rowspan="2" bgcolor="yellow">Pass</td>
</tr>

<tr>
<td> Carter</td>
<td>1254</td>
<td>250</td>
<td>500</td>
</tr>
</table>

Keep practice on table elements and do best :
Kindly follow my blog for a update

Comments