6. Tables
In some sections we'll need to show structured and ordered information: a table. Each one can include its own title, a title per column and, of course, its information. The only limitation we'll encounter is that all rows must be made up of the same number of columns.
Among the tags we'll make use of:
| Tag | <table> |
|---|---|
| Description | Container of the table. |
| Attributes | Global |
| Type | Block |
| Tag | <caption> |
|---|---|
| Description | Title of the table. |
| Attributes | Global |
| Tag | <tr> |
|---|---|
| Description | Definition of rows. |
| Attributes | Global |
| Tag | <td> |
|---|---|
| Description | Cell. |
| Attributes | Global |
| Tag | <th> |
|---|---|
| Description | Cell or column title. |
| Attributes | scope: Indicates the direction of the information row or col (column). |
| Tag | <thead> |
|---|---|
| Description | Header container. |
| Attributes | Global |
| Tag | <tbody> |
|---|---|
| Description | Data container. |
| Attributes | Global |
| Tag | <tfoot> |
|---|---|
| Description | Footer container. |
| Attributes | Global |
Simple
<table>
<thead>
<tr>
<th scope="col">Left column title</th>
<th scope="col">Right column title</th>
</tr>
</thead>
<tbody>
<tr>
<td>Left content</td>
<td>Right content</td>
</tr>
</tbody>
</table>
| Left column title | Right column title |
|---|---|
| Left content | Right content |
{: .advice }
For accessibility reasons, and the correct functioning of screen readers, tables must always carry header cells indicating the direction (scope="row" and scope="col").
Add a title
Use the caption tag inside table.
<table>
<caption>My table</caption>
<thead>
<tr>
<th scope="col">Left column title</th>
<th scope="col">Right column title</th>
</tr>
</thead>
<tbody>
<tr>
<td>Left content</td>
<td>Right content</td>
</tr>
</tbody>
</table>
| Left column title | Right column title |
|---|---|
| Left content | Right content |
Footer
Use the tfoot tag at the end of table.
<table>
<thead>
<tr>
<th scope="col">Left column title</th>
<th scope="col">Right column title</th>
</tr>
</thead>
<tbody>
<tr>
<td>Left content</td>
<td>Right content</td>
</tr>
</tbody>
<tfoot>
<tr>
<th scope="col">Left column title</th>
<th scope="col">Right column title</th>
</tr>
</tfoot>
</table>
| Left column title | Right column title |
|---|---|
| Left content | Right content |
| Left column title | Right column title |
Activity 1
Build the following web page.

Activity 2
Create a table with the information of your worst enemies or people you don't like.
It will have a title, caption, and the following columns.
- First name
- Last name
- Age
- Gender
- Why is it my enemy?
Activity 3
With everything you've learned so far, create your Curriculum Vitae. As a minimum it must show.
- Image.
- Basic data.
- Experience.
- Skills.
This work is under a Attribution-NonCommercial-NoDerivatives 4.0 International license.
Desafíos de programación atemporales y multiparadigmáticos
Te encuentras ante un librillo de actividades, divididas en 2 niveles de dificultad. Te enfrentarás a los casos más comunes que te puedes encontrar en pruebas técnicas o aprender conceptos elementales de programación.
Buy the bookWill you buy me a coffee?
This is how I keep writing without ads or paywalls.
Sure, it's on me!
Comments
There are no comments yet.