Skip to content

Commit 2ff29e0

Browse files
authored
[Edit] HTML: <tfoot> (#7642)
* [Edit] HTML: <tfoot> * Update tfoot.md ---------
1 parent 8997adf commit 2ff29e0

File tree

4 files changed

+114
-21
lines changed

4 files changed

+114
-21
lines changed
Lines changed: 114 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,45 @@
11
---
22
Title: 'tfoot'
3-
Description: 'Groups the footer content in a table. '
3+
Description: 'Defines a footer section for a table.'
44
Subjects:
5-
- 'Web Development'
65
- 'Web Design'
6+
- 'Web Development'
77
Tags:
8-
- 'Tables'
8+
- 'Data'
99
- 'Elements'
10-
- 'Web Development'
10+
- 'Tables'
11+
- 'Tags'
1112
CatalogContent:
1213
- 'learn-html'
1314
- 'paths/front-end-engineer-career-path'
14-
- 'paths/full-stack-engineer-career-path'
1515
---
1616

17-
Groups the footer content in a table.
17+
The HTML **`<tfoot>`** [element](https://www.codecademy.com/resources/docs/html/elements) is used to define a footer section for a table. It typically contains summary information, totals, or notes related to the data presented in the table body.
1818

19-
## Syntax
19+
## HTML `<tfoot>` Syntax
2020

21-
```html
22-
<tfoot>
23-
<!-- Takes in footer content -->
24-
</tfoot>
21+
```pseudo
22+
<table>
23+
<thead>
24+
<!-- Header rows -->
25+
</thead>
26+
<tbody>
27+
<!-- Main data rows -->
28+
</tbody>
29+
<tfoot>
30+
<!-- Footer rows -->
31+
</tfoot>
32+
</table>
2533
```
2634

27-
**Note:** The `<tfoot>` element is usually used along with `<tbody>` and `<thead>`. which provides useful semantic information.
35+
> **Note:** The HTML `<tfoot>` element is usually used along with [`<tbody>`](https://www.codecademy.com/resources/docs/html/tables/tbody) and [`<thead>`](https://www.codecademy.com/resources/docs/html/tables/thead), which provides useful semantic information.
2836
29-
## Example 1
37+
## Example 1: Simple Footer Using HTML `<tfoot>`
3038

31-
Grouping the footer content in an HTML table.
39+
This example uses HTML `<tfoot>` to define a simple footer for a table:
3240

3341
```html
34-
<table>
42+
<table border="1">
3543
<thead>
3644
<tr>
3745
<th>Items</th>
@@ -48,7 +56,6 @@ Grouping the footer content in an HTML table.
4856
<td>10,000</td>
4957
</tr>
5058
</tbody>
51-
<!-- All footer content will be inside the <tfoot> element -->
5259
<tfoot>
5360
<tr>
5461
<td>Total</td>
@@ -58,8 +65,94 @@ Grouping the footer content in an HTML table.
5865
</table>
5966
```
6067

61-
| Items | Cost |
62-
| ----------------------------- | ------- |
63-
| Model 3 | $50,000 |
64-
| 1 giant rubber debugging duck | $10,000 |
65-
| Total | $60,000 |
68+
Here is the output:
69+
70+
![Simple footer for a table, created using HTML <tfoot>](https://raw.githubusercontent.com/Codecademy/docs/main/media/html-tfoot-1.jpg)
71+
72+
## Example 2: Adding Notes in Footer
73+
74+
This example uses HTML `<tfoot>` to create a footer for a table that contains a note about the table's data:
75+
76+
```html
77+
<table border="1">
78+
<thead>
79+
<tr>
80+
<th>Month</th>
81+
<th>Sales</th>
82+
</tr>
83+
</thead>
84+
<tbody>
85+
<tr>
86+
<td>January</td>
87+
<td>$500</td>
88+
</tr>
89+
<tr>
90+
<td>February</td>
91+
<td>$450</td>
92+
</tr>
93+
</tbody>
94+
<tfoot>
95+
<tr>
96+
<td colspan="2">* Data is provisional and may change.</td>
97+
</tr>
98+
</tfoot>
99+
</table>
100+
```
101+
102+
Here is the output:
103+
104+
![Footer for a table containing a note about the table's data, created using HTML <tfoot>](https://raw.githubusercontent.com/Codecademy/docs/main/media/html-tfoot-2.jpg)
105+
106+
## Example 3: Complex Table with Multiple Columns
107+
108+
This example uses HTML `<tfoot>` to create a footer for a table that summarizes the marks in it with a total score:
109+
110+
```html
111+
<table border="1">
112+
<thead>
113+
<tr>
114+
<th>Subject</th>
115+
<th>Marks</th>
116+
<th>Grade</th>
117+
</tr>
118+
</thead>
119+
<tbody>
120+
<tr>
121+
<td>Math</td>
122+
<td>90</td>
123+
<td>A</td>
124+
</tr>
125+
<tr>
126+
<td>Science</td>
127+
<td>85</td>
128+
<td>B</td>
129+
</tr>
130+
</tbody>
131+
<tfoot>
132+
<tr>
133+
<td>Total</td>
134+
<td>175</td>
135+
<td>-</td>
136+
</tr>
137+
</tfoot>
138+
</table>
139+
```
140+
141+
Here is the output:
142+
143+
![Footer for a table summarizing the marks in it with a total score, created using HTML <tfoot>](https://raw.githubusercontent.com/Codecademy/docs/main/media/html-tfoot-3.jpg)
144+
145+
## Frequently Asked Questions
146+
147+
### 1. What is `<tfoot>` in HTML?
148+
149+
The HTML `<tfoot>` element defines a footer section for a table. It is mainly used to display summary information, totals, or notes that apply to the table data.
150+
151+
### 2. What are the `<thead>` and `<tfoot>` tags used for in HTML?
152+
153+
- `<thead>`: Defines the header section of a table, usually containing column titles.
154+
- `<tfoot>`: Defines the footer section, often used for summaries or totals.
155+
156+
### 3. Is `<tfoot>` required in every HTML table?
157+
158+
No, it's optional to use `<tfoot>` in an HTML table. You only need it if you want to display footer information such as totals or notes.

media/html-tfoot-1.jpg

28.3 KB
Loading

media/html-tfoot-2.jpg

31.4 KB
Loading

media/html-tfoot-3.jpg

23.1 KB
Loading

0 commit comments

Comments
 (0)