Tables In HTML
Creating tables in HTML is a way to display tabular data in a structured format. HTML provides several elements for building tables, including the <table>
, <tr>
, <th>
and <td>
elements. Here's how to create a simple HTML table:
In this example,
<html>
<head>
<title>HTML Table Example</title>
</head>
<body>
<h2>Sample Table</h2>
<table border="1">
<tr>
<th>Heading 1</th>
<th>Heading 2</th>
<th>Heading 3</th>
</tr>
<tr>
<td>Row 1, Column 1</td>
<td>Row 1, Column 2</td>
<td>Row 1, Column 3</td>
</tr>
<tr>
<td>Row 2, Column 1</td>
<td>Row 2, Column 2</td>
<td>Row 2, Column 3</td>
</tr>
<tr>
<td>Row 3, Column 1</td>
<td>Row 3, Column 2</td>
<td>Row 3, Column 3</td>
</tr>
</table>
</body>
</html>
a). The '<table>' element is used to define the table.
b). For viewing purposes, the border="1" parameter creates a border around the table and its cells. It's not recommended for production use; CSS is preferred for styling.
c). The <tr> elements define table rows. Each '<tr>' represents a new row in the table.
d). The '<th>' elements define table headers, which are displayed in bold by default and centered.
e). The '<td>' elements define table data cells, which contain the actual data.
More rows and columns can be added as needed. You can also use CSS to style the table, change the border style, and format the table according to your design preferences.
Tables in HTML are commonly used to display data in a structured format, such as product listings, schedules, and data summaries. They are an essential part of web development for organizing and presenting tabular data.
Example:-
<html>
<head>
<title>HTML Table Example</title>
</head>
<body>
<h2>Example of Table</h2>
<table border="2" width=50% align=center bgcolor=yellow height=50% border-color=red cellspacing=10 cellpadding=20>
<tr bgcolor=orange>
<th>Roll No.</th>
<th>Name</th>
<th>Marks</th>
</tr>
<tr>
<td>101</td>
<td>herry</td>
<td>546</td>
</tr>
<tr>
<td>102</td>
<td>robin</td>
<td>489</td>
</tr>
<tr>
<td>103</td>
<td bgcolor=red>joy</td>
<td>800</td>
</tr>
</table>
</body>
</html>
Result:-
Table Attribute will be discussed later.