Home 〉 HTML Tutorials 〉 HTML Table Tag Tutorial with Examples | HTML th, td, tr, colspan, rowspan Explained
HTML Table Tag Tutorial with Examples | HTML th, td, tr, colspan, rowspan Explained !
Want to display tabular data in your web pages? This complete guide on the HTML table tag helps you understand how to structure data using '<table>', '<th>', '<td>', and other . With examples, syntax breakdown, and styling tips, you'll learn how to create clean, responsive tables. From 'colspan' and 'rowspan' to 'thead', 'tbody', and 'tfoot', every element is explained in detail. This detailed blog post on HTML table tag is as follows.
In HTML, the '<table>' tag is used to display data in a structured, tabular form — like a spreadsheet. Tables are extremely useful for organizing content and presenting information in rows and columns. Understanding HTML tables is crucial for web development as it lays the foundation for displaying and formatting data effectively.
Syntax ✍
<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
<th>Header 3</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
</tr>
</table>
Attribute
Description
View Demo
frame
Specifies which outer borders to show. Values: void, above, below, hsides, vsides, lhs, rhs, box, border.
View DemoNote: Some of the above (like 'bgcolor', 'border', 'align', 'cellpadding', etc.) are deprecated in HTML5, which means they still work in browsers but are not recommended anymore. Instead, use CSS for styling.
The '<tr>' tag defines a row in a table.
Attribute
Description
View Demo
The '<td>' tag defines a data cell (normal cell with content).
Attribute
Description
View Demo
colspan
Merges the cell across multiple columns. Example: 'colspan="2"' makes the cell span 2 columns.
View DemoThe '<th>' tag defines a header cell (bold and centered by default).
Tag | Purpose | Most Useful Attributes |
---|---|---|
'<tr>' | Table row | 'class', 'style', 'bgcolor' (deprecated), 'id' |
'<td>' | Table data | 'colspan', 'rowspan', 'align', 'style', 'id' |
'<th>' | Table header | 'scope', 'colspan', 'rowspan', 'style', 'id' |
Attributes:
Example:
Example 📄
<th colspan="2">Heading</th>
Meaning: This header spans 2 columns.
Example:
Example 📄
<td>Apple</td>
Meaning: Displays "Apple" inside a data cell.
Example:
Example 📄
<tr><td>Row Content</td></tr>
Meaning: Adds a new row with one cell.
Example 📄
<thead>
<tr><th>Name</th><th>Age</th></tr>
</thead>
This Defines the table header area, usually styled differently.
Example 📄
<tbody>
<tr><td>John</td><td>30</td></tr>
</tbody>
This Defines the main data portion of the table.
Example 📄
<tfoot>
<tr><td colspan="2">Total</td></tr>
</tfoot>
The Footer for the table, useful for totals or summary.
Example 📄
<caption>Employee Details</caption>
Displays a title for the table above the content.
Example with both 'colspan' and 'rowspan' is as follows:
Example 📄
<td colspan="2" rowspan="2">Merged Cell</td>
The cell spans across 2 columns and 2 rows.
Example 📄
<colgroup>
<col span="2" style="background-color: lightgray;">
</colgroup>
Styles columns together within the group.
<!DOCTYPE html>
<html>
<body>
<table>
<caption>Table Caption</caption>
<tr>
<th>Header 1</th>
<th>Header 2</th>
<th>Header 3</th>
<th>Header 4</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<p class="ap">This table has border of '5', you can change the values and see the output. </p>
<table border="5">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
This table has border of '5', you can change the values and see the output.
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table cellpadding="5px" border="1">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table cellspacing="10" border="1">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table width="600px" border="1">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table height="150px" border="1">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table align="left" border="1">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table align="center" border="1">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table align="right" border="1">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table bgcolor="yellow" border="1">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table frame="above" border="1">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table rules="rows" border="1">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table rules="cols" border="1">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table rules="all" border="1">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table rules="none" border="1">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table bordercolor="yellow" border="5">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table title="HML Table Tag" border="2">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table background="\images\image3.jpg" border="2">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table border="2">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr bgcolor="yellow"><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table border="2">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr valign="top"><td>Data 1 <br> Data 2 <br> Data 3</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 Data 2 Data 3 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table border="2">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr valign="middle"><td>Data 1 <br> Data 2 <br> Data 3</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 Data 2 Data 3 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table border="2">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr valign="bottom"><td>Data 1 <br> Data 2 <br> Data 3</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 Data 2 Data 3 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table border="2" width="500px">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr align="right"><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
The 'align' attribute does not works. If it works then try value like (left, center, right). Deprecated in HTML5
<!DOCTYPE html>
<html>
<body>
<table border="2" width="500px">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr background="\images\image3.jpg"><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table border="2" width="500px">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td background="\images\image3.jpg">Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table border="2" width="500px">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td colspan="2">Data 1 / Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 / Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table border="2" width="500px">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td rowspan="2">Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td> Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table border="2" width="500px">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td bgcolor="yellow">Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table border="2" width="500px">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td background="/images/image3.jpg">Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<body>
<table border="5">
<caption>Table Caption</caption>
<thead>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
</thead>
<tbody>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</tbody>
<tfoot>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</tfoot>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
<!DOCTYPE html>
<html>
<head>
<style>
.table1 { background: rgb(249, 111, 106 ); border-collapse: collapse; width: 600px; margin: auto; }
.table1 th, .table1 td, .table1 tr { border: 1px solid lightblue; padding: 10px 20px; }
.table1 caption { border: 1px solid lightblue; padding: 10px; background: rgb(139, 228, 97 ); font-weight: bold; text-align: center; }
.table1 th { background: rgb(232, 119, 145 ); }
</style>
</head>
<body>
<table class="table1">
<caption>Table Caption</caption>
<tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
<tr><td>Data 1</td><td>Data 2</td><td>Data 3</td><td>Data 4</td></tr>
</table>
</body>
</html>
output 📌
Header 1 | Header 2 | Header 3 | Header 4 |
---|---|---|---|
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
Data 1 | Data 2 | Data 3 | Data 4 |
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
The '<table>' tag and its related elements such as '<tr>', '<th>', '<td>', '<thead>', '<tbody>', and '<tfoot>' play a key role in organizing and displaying data in HTML. With attributes like 'colspan' and 'rowspan', you can customize the layout of table cells for better readability and structure. Understanding tables helps you create more interactive and visually organized websites.
Yes, '<table>' is a block-level element.
Yes, tables can be styled using CSS properties like 'border', 'padding', 'width', 'text-align', etc.
'<th>' is used for headers and is bold by default, while '<td>' is used for regular data.
Yes, using 'rowspan' and 'colspan' attributes.