See
<table>
for a complete table example introducing common standards and best practices.
This example demonstrates a basic table that includes a caption describing the data presented.
Such a "title" is helpful for users who are quickly scanning the page, and it is especially beneficial for visually impaired users, allowing them to determine the table's relevance quickly without the need to have a screen reader read the contents of many cells just to find out what the table is about.
HTML
A
<caption>
element is used as the first child of the
<table>
, with text content similar to a title to describe the table data. Three rows, the first being a header row, with two columns are created using the
<tr>
,
<th>
and
<td>
elements after the
<caption>
.
<
table
>
<
caption
>
User login email addresses
</
caption
>
<
tr
>
<
th
>
Login
</
th
>
<
th
>
Email
</
th
>
</
tr
>
<
tr
>
<
td
>
user1
</
td
>
<
td
>
user1@example.com
</
td
>
</
tr
>
<
tr
>
<
td
>
user2
</
td
>
<
td
>
user2@example.com
</
td
>
</
tr
>
</
table
>
CSS
Some basic CSS is used to align and highlight the
<caption>
.
caption
{
caption-side
:
top
;
text-align
:
left
;
padding-bottom
:
10px
;
font-weight
:
bold
;
}
table
{
border-collapse
:
collapse
;
border
:
2px solid
rgb
(
140 140 140
)
;
font-family
:
sans-serif
;
font-size
:
0.8rem
;
letter-spacing
:
1px
;
}
th,
td
{
border
:
1px solid
rgb
(
160 160 160
)
;
padding
:
8px 10px
;
}
th
{
background-color
:
rgb
(
230 230 230
)
;
}
td
{
text-align
:
center
;
}
Result