HTML <table> Tag


Exemple

Un tableau HTML simple, contenant deux colonnes et deux lignes :

<table>
<tr>
<th>Mois</th>
<th>Économies</th>
</tr>
<tr>
<td>Janvier</td>
<td>$100</td>
</tr>
</table>
Essayez-le vous-même »

Plus d'exemples "Essayez-le vous-même" ci-dessous.


Définition et Utilisation

La balise <table> définit un tableau HTML.

Un tableau HTML se compose d'un élément <table> et d'un ou plusieurs éléments <tr> , <th> , et <td> .

L'élément <tr> définit une ligne de tableau, l'élément <th> définit un en-tête de tableau, et l'élément <td> définit une cellule de tableau.

Un tableau HTML peut également inclure des éléments <caption> , <colgroup> , <thead> , <tfoot> , et <tbody> .


Support des Navigateurs

Élément
<table> Oui Oui Oui Oui Oui

Attributs Globaux

La balise <table> prend également en charge les Attributs Globaux en HTML .


Attributs d'Événement

La balise <table> prend également en charge les Attributs d'Événement en HTML .



Plus d'Exemples

Exemple

Comment ajouter des bordures collapsées à un tableau (avec CSS) :

<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<body>

<table>
<tr>
<th>Mois</th>
<th>Économies</th>
</tr>
<tr>
<td>Janvier</td>
<td>$100</td>
</tr>
<tr>
<td>Février</td>
<td>$80</td>
</tr>
</table>

</body>
</html>
Essayez-le vous-même »

Exemple

Comment aligner un tableau à droite (avec CSS) :

<table style="float:right">
<tr>
<th>Mois</th>
<th>Économies</th>
</tr>
<tr>
<td>Janvier</td>
<td>$100</td>
</tr>
<tr>
<td>Février</td>
<td>$80</td>
</tr>
</table>
Essayez-le vous-même »

Exemple

Comment centrer un tableau (avec CSS) :

<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
table.center {
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<body>

<table class="center">
<tr>
<th>Mois</th>
<th>Économies</th>
</tr>
<tr>
<td>Janvier</td>
<td>$100</td>
</tr>
<tr>
<td>Février</td>
<td>$80</td>
</tr>
</table>
Essayez-le vous-même »

Exemple

Comment ajouter une couleur de fond à un tableau (avec CSS) :

<table style="background-color:#00FF00">
<tr>
<th>Mois</th>
<th>Économies</th>
</tr>
<tr>
<td>Janvier</td>
<td>$100</td>
</tr>
<tr>
<td>Février</td>
<td>$80</td>
</tr>
</table>
Essayez-le vous-même »

Exemple

Comment ajouter du padding à un tableau (avec CSS) :

<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}

th, td {
padding: 10px;
}
</style>
</head>
<body>

<table>
<tr>
<th>Mois</th>
<th>Économies</th>
</tr>
<tr>
<td>Janvier</td>
<td>$100</td>
</tr>
<tr>
<td>Février</td>
<td>$80</td>
</tr>
</table>

</body>
</html>
Essayez-le vous-même »

Exemple

Comment définir la largeur d'un tableau (avec CSS) :

<table style="width:400px">
<tr>
<th>Mois</th>
<th>Économies</th>
</tr>
<tr>
<td>Janvier</td>
<td>$100</td>
</tr>
<tr>
<td>Février</td>
<td>$80</td>
</tr>
</table>
Essayez-le vous-même »

Exemple

Comment créer des en-têtes de tableau :

<table>
<tr>
<th>Nom</th>
<th>Email</th>
<th>Téléphone</th>
</tr>
<tr>
<td>John Doe</td>
<td>john.doe@example.com</td>
<td>123-45-678</td>
</tr>
</table>
Essayez-le vous-même »

Exemple

Comment créer un tableau avec une légende :

<table>
<caption>Économies mensuelles</caption>
<tr>
<th>Mois</th>
<th>Économies</th>
</tr>
<tr>
<td>Janvier</td>
<td>$100</td>
</tr>
<tr>
<td>Février</td>
<td>$80</td>
</tr>
</table>
Essayez-le vous-même »

Exemple

Comment définir des cellules de tableau qui s'étendent sur plus d'une ligne ou d'une colonne :

<table>
<tr>
<th>Nom</th>
<th>Email</th>
<th colspan="2">Téléphone</th>
</tr>
<tr>
<td>John Doe</td>
<td>john.doe@example.com</td>
<td>123-45-678</td>
<td>212-00-546</td>
</tr>
</table>
Essayez-le vous-même »

Pages Associées

Tutoriel HTML : Tables HTML

Référence DOM HTML : Objet Table

Tutoriel CSS : Styliser les Tables


Paramètres CSS par Défaut

La plupart des navigateurs afficheront l'élément <table> avec les valeurs par défaut suivantes :

Exemple

table {
display: table;
border-collapse: separate;
border-spacing: 2px;
border-color: gray;
}
Essayez-le vous-même »