– Table Body Section
<tfoot> are HTML elements that structure tables into header, body, and footer sections for better organization and semantics. 1. <thead> contains column headers using elements and appears once per table, improving accessibility and styling; 2.
<tbody> holds the main data rows with elements and is often added automatically by browsers if omitted; 3.
<tfoot> defines summary or total rows, must be placed after <thead> but before
<tbody> in HTML, yet renders visually at the table’s bottom, supports repeated footers in print, and enhances usability for large tables. These elements improve accessibility, enable targeted CSS styling, aid JavaScript manipulation, and help maintain clarity in complex tables, making them a best practice in HTML table design.
The <thead>, <code><tbody>, and <code><tfoot> are HTML elements used to divide a table into logical sections: the <strong>header</strong>, <strong>body</strong>, and <strong>footer</strong>. They help structure tables in a more organized and semantically meaningful way—especially useful for accessibility, styling with CSS, and scripting with JavaScript.<img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/175381304633448.jpeg" class="lazy" alt="What are <thead>, <tbody>, and <tfoot> in tables?">, </tfoot>
<tbody>, and </tbody>
<tfoot> in tables?" /><p>Here’s what each one does:</p>
<hr>
<h3><code><thead> – Table Header Section<ul>
<li>Wraps the <strong>header rows</strong> of the table (usually the column titles).</li>
<li>Should contain one or more <code><tr> elements with <code><th> (header cells).<li>Appears <strong>once</strong> per table, and must be a direct child of <code><table>.<li>Even if you don’t use it, browsers often add it automatically in the DOM.</li>
<p><strong>Example:</strong></p>
<img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/175381304711716.jpeg" class="lazy" alt="What are <thead>, <tbody>, and <tfoot> in tables?">, <tbody>, and </tbody>
<tfoot> in tables?" /><pre class='brush:php;toolbar:false;'><thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
</thead></pre><hr /><h3 id="code-tbody-code-Table-Body-Section"><code><tbody>
– Table Body Section
- Contains the main data rows of the table.
- This is where most of your
<tr>
rows go. - If you don’t include
<tbody>
in your HTML, browsers usually insert it automatically.
Example:
<tbody>
<tr>
<td>John</td>
<td>28</td>
<td>New York</td>
</tr>
<tr>
<td>Sara</td>
<td>32</td>
<td>Los Angeles</td>
</tr>
</tbody>
<tfoot>
– Table Footer Section
- Used for summary or totals rows (e.g., sums, averages).
- Should come after
<thead>
but before <tbody>
in the HTML (yes, really!). - Despite being defined early in the code, it renders at the bottom of the table.
- Also useful for repeating footers when printing long tables.
Example:
, <tbody>, and <tfoot> in tables?" /><tfoot>
<tr>
<td>Total:</td>
<td>60</td>
<td></td>
</tr>
</tfoot>
Why Use These Sections?
- Accessibility: Screen readers can better interpret table structure.
- Styling: You can style header, body, and footer differently:
thead th {
background-color: #003366;
color: white;
}
tfoot td {
font-weight: bold;
}
- Long Tables: Browsers can keep the header/footer visible when scrolling.
- Printing: Footers can repeat on each printed page.
Full Example:
<table>
<thead>
<tr>
<th>Product</th>
<th>Price</th>
<th>Stock</th>
</tr>
</thead>
<tfoot>
<tr>
<td>Total</td>
<td>$150</td>
<td>45</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>Laptop</td>
<td>$100</td>
<td>20</td>
</tr>
<tr>
<td>Mouse</td>
<td>$50</td>
<td>25</td>
</tr>
</tbody>
</table>
Note: Even though <tfoot> appears before <tbody> in the code, it will display at the bottom of the table.
So, in short:
<thead> = header rows (column titles)<tbody> = main data rows<tfoot> = footer/summary rowsUsing them makes your tables cleaner, more maintainable, and more usable—especially for complex or large datasets. Basically, it's a best practice for well-structured HTML tables.
The above is the detailed content of What are , , and in tables?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Beginner's Guide: How to Read HTML Tabular Data with Pandas Introduction: Pandas is a powerful Python library for data processing and analysis. It provides flexible data structures and data analysis tools, making data processing simpler and more efficient. Pandas can not only process data in CSV, Excel and other formats, but can also directly read HTML table data. This article will introduce how to use the Pandas library to read HTML table data, and provide specific code examples to help beginners

We can easily add HTML tags in the table. HTML tags should be placed inside <td> tags. For example, add paragraph <p>…</p> tags or other available tags inside the <td> tag. Syntax The following is the syntax for using HTMl tags in HTML tables. <td><p>Paragraphofthecontext</p><td>Example 1 An example of using HTML tags in an HTML table is given below. <!DOCTYPEhtml><html><head&g

How to convert an array into an HTML table in PHP In web development, we often encounter the need to present data in table form. As a powerful server-side scripting language, PHP provides many convenient functions for operating arrays and generating HTML. We can use these functions to convert arrays into HTML tables. Below, we will introduce a simple method to achieve this function. First we need to have an array containing data. Here is an example array: $data=[['Nam

Create titles using tags in HTML. Tags in HTML are used to specify title cells or headers in tables. Here are the properties: Property Value Description abbrabbbreviated_text Deprecated - Specifies an abbreviated version of the content in the header cell. alignrightleftcenterjustifychar DEPRECATED - Alignment of content in header cells. axis name is deprecated - specifies the category of this th. bgcolorrgb(x,x,x)#hexcodecolorname Deprecated - Specifies the background color of the header cell. char deprecated - The character that specifies the alignment of the text. When align="char&qu

When you need to break a line, you can use the word-break property in CSS to change the line break. Text line breaks usually appear only in specific positions, such as after a space or hyphen. Following is the syntax for word-break:normal|break-all|keep-all|break-word|initial|inherit; Let us read this article in depth to get a better understanding of how to prevent word breaks in HTML tables. Before that, let's take a quick look at HTML tables. HTML tables Web designers can use HTML tables to organize information such as text, images, links, and other tables into rows and columns of cells. <tabl

Use the rowspan property to set the number of rows a table cell should span. To merge cells in HTML, use colspan and rowspan attributes. The rowspan attribute is used to specify the number of rows the cell should span, while the colspan attribute is used to specify the number of columns the cell should span. Example<!DOCTYPEhtml><html> <head> <style> &

There is a well-supported but little-known, extremely useful CSS property that applies to tables. It changes the way tables are displayed so you can have a more reliable, consistent layout. Formatting tables appropriately is beneficial as it makes the web page more user-friendly and helps users understand the information in the table more clearly. This article will teach you how to prevent table formatting "errors" in HTML. Before we dive into this article, let’s take a quick look at tables in HTML. HTML tables HTML tables are created using the <table> tag, where the <tr> tag is used to create table rows and <td&

PHP's implode() function: How to connect array elements into an HTML table, specific code examples are required. PHP is a scripting language widely used in web development. It has powerful capabilities for processing data. When developing web applications using PHP, we often need to connect elements in arrays and render them into HTML tables. At this time, PHP provides a very useful function implode(). This article will introduce how to use this function to connect array elements into HTML.
