HTML Tables.
What is HTML Tables?
Tables are a technique of arranging and displaying data and digital information on a web page in a structured grid or tabular style in row and column order using HTML. Tables are made up of rows (rows) and columns (columns) in any table. Whereas a table cell is the term used to describe each intersection of a row, row, and column. Table cells are used to enter or show data and information. Any website may utilize any HTML table to analyze comparative data and information as well as multiple kinds of basic data and information.
Creating tables with <table>, <tr>, <th>, and <td>.
Rows, columns, and cells are used in combination to form every table in an HTML web page. The <table>, <tr>, <td>, and <th> table elements are the main components of a straightforward HTML table.
Here, each element of an HTML table is thoroughly explained.
- <table> – The HTML element known as “table” serves as a digital information storage space for a whole table. This tag specifies the table start and table end tags for a new HTML table.
- <tr> – A table’s new row is represented by the <tr> table row tag element. Individual rows inside a table are grouped and defined in a table structure using table row tags.
- <td> – A blank table cell within a table row is represented by the <td> table data tag element. The actual information or content that appears in a table or column is digitally saved and presented.
- <th> – The <td> table data tag is comparable to the <th> table header element. However, the header cell that is visible at the top of the table is defined by the table heading tag. Table header cells are used to mark columns or rows in the heading at the top of a table. They commonly show text and information in strong and big font sizes.
Here’s a basic example of a simple HTML table.
<!DOCTYPE html>
<html>
<head>
<title>Html table tag example</title>
<link rel=”stylesheet” href=”styles.css” />
</head>
<body>
<table border=”1″ bgcolor=”yellow”>
<tr>
<th>Table Heading 1</th>
<th>Table Heading 2</th>
<th>Table Heading 3</th>
</tr>
<tr>
<td>Table cell 1</td>
<td>Table cell 2</td>
<td>Table cell 3</td>
</tr>
<tr>
<td>Table cell 4</td>
<td>Table cell 5</td>
<td>Table cell 6</td>
</tr>
</table>
</body>
</html>
In the HTML table example above.
- <table> – The table tag denotes the beginning and the end of a new table.
- <tr> – In HTML tables, the table row element is used to add additional table row rows.
- <th> – Tag for table header a header cell for any HTML table that shows heading information in bold language.
- <td> – The table data tag shows an empty data cell in an HTML table for digital text and information content.
- table border – In an HTML table, a table border is used to display a border around each row, each column, and each cell.
Table headers, captions, and styling.
By including table headers, and captions, and applying unique CSS styles to the top row of the table, you may enhance the commercial and visual appeal of your current HTML tables, just as you can with any straightforward HTML table.
Therefore, let’s include table heads in an HTML table.
Table header (<th>) tag.
To show heading information labels in a table row or column, header elements are used in HTML tables. Table heads are by default shown in strong font. Any HTML table header cell may be created by using the <th> table heading element inside the <tr> tag element.
The HTML table heading tag is an example.
<!DOCTYPE html>
<html>
<head>
<title>Html table Heading tag example</title>
<link rel=”stylesheet” href=”styles.css” />
</head>
<body>
<table border=”1″bgcolor=”pink”>
<tr>
<th>#. </th>
<th>Model Name</th>
<th>Brand</th>
<th>Processor</th>
<th>Manufacture year</th>
<th>Price</th>
</tr>
<tr>
<td>1. </td>
<td>Dell Xps Laptop</td>
<td>Dell</td>
<td>13th gen intel core i5 processor</td>
<td>2023</td>
<td>1,12000</td>
</tr>
<tr>
<td>2. </td>
<td>Apple Macbook Pro M2</td>
<td>Apple</td>
<td>13th gen intel core i9 processor</td>
<td>2023</td>
<td>2,50000</td>
</tr>
</table>
</body>
</html>
Table Caption (<caption>) Tag.
A heading title or table description is displayed for the full planned table in an HTML table caption. It may be shown either immediately before or just after the HTML table you generated.
How to use captions in html table.
<!DOCTYPE html>
<html>
<head>
<title>Html table Caption tag example</title>
<link rel=”stylesheet” href=”styles.css” />
</head>
<body>
<table border=”1″ bgcolor=”aqua”>
<caption><strong>Programming Course Table</strong></caption>
<tr>
<th>#. </th>
<th>Course Name</th>
<th>Duration</th>
<th>Price</th>
<th>Medium</th>
</tr>
<tr>
<td>1. </td>
<td>Html Web Development</td>
<td>30 Days</td>
<td>599</td>
<td>English</td>
</tr>
<tr>
<td>2. </td>
<td>Css Web Development</td>
<td>50 Days</td>
<td>799</td>
<td>Hindi</td>
</tr>
</table>
</body>
</html>
Html Table Example.
<!DOCTYPE html>
<html>
<head>
<title>HTML Table Example</title>
<style>
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 2px solid #FF5722;
text-align: center;
padding: 10px;
}
th {
background-color: #00FFCC;
}
tr:nth-child(even) {
background-color: #26A69A;
}
tr:nth-child(odd) {
background-color: #FFEB3B;
}
</style>
</head>
<body>
<h1>Student Report Card</h1>
<table>
<caption><strong>Student Report</strong></caption>
<thead>
<tr>
<th>#. </th>
<th>Student Name</th>
<th>Class</th>
<th>Address</th>
<th>Contact</th>
<th>Percentage</th>
<th>Board</th>
</tr>
</thead>
<tbody>
<tr>
<td>1. </td>
<td>Amit Jain</td>
<td>10th</td>
<td>Sirohi</td>
<td>112235334</td>
<td>89%</td>
<td>Rbse</td>
</tr>
<tr>
<td>2. </td>
<td>Vinay Sharma</td>
<td>12th</td>
<td>Jodhpur</td>
<td>331137334</td>
<td>91%</td>
<td>Cbse</td>
</tr>
<tr>
<td>3. </td>
<td>Anita Kothari</td>
<td>10th</td>
<td>Jaipur</td>
<td>685559766</td>
<td>97%</td>
<td>Cbse</td>
</tr>
</tbody>
</table>
</body>
</html>
In the HTML table example above.
- <table> – The HTML table tag element <table> denotes the start and end tags for the table.
- <caption> – The table’s caption is shown using the HTML caption tag element.
- <thead> – The table header rows in a table are grouped together using the HTML thead element, while the table data rows are grouped together using the tbody table tag.
- <th> – The header cell in the table is shown via the HTML table heading tag element.
- <td> – An HTML table data tag element that shows an empty table.
In HTML tables, basic formatting is applied using CSS styles. for instance, table borders, backdrop colors, and text alignment for various effects.