Eaf 1 de 2
Eaf 1 de 2
TABLES IN HTML
TABLES
Tables arrange data in rows and columns and provide an attractive
way to represent information.
Tables allow the users to organize data like text, images and links
etc.
<table> …. </table> To create the structure of a table. Each table begins with a <table> tag
and ends with the </table> tag.
<th>..</th> It gives a column heading in a table. It makes the text bold and place the
headings into center of the cell.
<tr>..</tr> It is used to create rows. Each row in table begins with the <tr> and ends
with the </tr>. Rows must be defined inside the table tag.
<td>..</td> The columns contain cells which stores data. It can contain HTML element
such as text, images, lists, other tables. <td> tag must always be present
inside the <tr> tag
<caption>..</caption> <caption> tag is used inside the <table> tag and must be inserted
immediatately after the <table> tag.
A table should have only one caption.
Example
<html>
<body>
<h2>This table has no borders:</h2>
<table>
<tr>
<td>100</td>
<td>200</td>
<td>300</td>
</tr>
<tr>
<td>400</td>
<td>500</td>
<td>600</td>
</tr>
</table>
</body>
</html>
<html>
<body>
<table>
<caption> Class X </caption>
<tr>
<th> Roll No </th>
<th> Name</th>
<th> Hobbies </th>
</tr>
<tr>
<td>1 </td>
<td>Manya</td>
<td> Football </td>
</tr>
<tr>
<td>2</td>
<td>Aryaman </td>
<td>Cricket </td>
</tr>
</table>
</body> </html>
ATTRIBUTES OF TABLE TAG
1. BORDER
This attribute draws a border around the table.
Border attribute specifies the width of the border of a
table.
If the border attribute is not specified with a table or
if its value is zero, then no border will be displayed.
The larger the value, the thicker will be the border.
◦ Syntax: <table border = “value”>
The border size applies only to the outer table border. The
inner cells will have a cell border that is always only one
pixel thick.
<html>
<body>
<table border>
<tr bgcolor="yellow">
<th colspan="3"> List of Players</th>
</tr>
<tr>
<td>1 </td>
<td>Manya</td>
<td> Football </td>
</tr>
<tr>
<td>2</td>
<td>Aryaman </td>
<td>Cricket </td>
</tr></table> </body> </html>
<html>
<body>
<table border = 15 bordercolor = "blue"
bgcolor="pink" cellpadding = 20 cellspacing=25
align=center rules="all" height=300 width=400>
<caption> Class X </caption>
<tr bgcolor="yellow">
<th colspan="3"> List of Players</th>
</tr>
<tr>
<td rowspan=2>1 </td>
<td>Manya</td>
<td> Football </td>
</tr>
<tr>
<td>2</td>
<td>Aryaman </td>
<td>Cricket </td>
</tr></table> </body> </html>
<html>
<body>
<table border = 15 bordercolor = "blue"
bgcolor="pink" cellpadding = 20 cellspacing=25
align=center rules="all" height=300 width=400>
<caption> Class X </caption>
<tr bgcolor="yellow">
<th colspan="3"> List of Players</th>
</tr>
<tr>
<td rowspan=2>Details</td>
<td>Manya</td>
<td> Football </td>
</tr>
<tr>
<td>Aryaman </td>
<td>Cricket </td>
</tr></table> </body> </html>
<THEAD> Tag
<THEAD> tag is used to group header and rows that define the
table’s header.
This tag should appear inside the <table> tag.
It is useful in case of large tables that span across multiple pages in
a document.
The table header defined by the <THEAD> tag will appear on each
page of the document where the table is displayed.
There can only be one <THEAD> element in a table which must
follow the main table command.
<html>
<body>
<table border = 15 bordercolor = "blue" bgcolor="pink"
cellpadding = 20 cellspacing=25 align=center>
<caption> Class X </caption>
<thead bgcolor="lightgreen"
<tr> <th> Roll No </th> <th> Name</th> <th> Hobbies
</th>
</tr> </thead>
<tr>
<td>1 </td> <td>Manya</td><td> Football </td>
</tr>
<tr> <td>2</td><td>Aryaman </td><td>Cricket </td>
</tr>
<tr><td>3 </td><td>Bhoomi</td><td> Football </td>
</tr><tr>
<td>4 </td><td>Avni</td><td> Football </td>
</tr>
</table> </body> </html>
We can specify the desired settings to multiple table
headers rows through various attributes defined in
<THEAD> tag.
All these three tags are useful for large tables where these tags
allow the browsers to scroll through the table body section while