Tag HTML <tabela>


Exemplo

Uma tabela HTML simples, contendo duas colunas e duas linhas:

<table>
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
</table>

Mais exemplos de "Experimente você mesmo" abaixo.


Definição e uso

A <table>tag define uma tabela HTML.

Uma tabela HTML consiste em um <table>elemento e um ou mais elementos <tr> , <th> e <td> .

O elemento <tr> define uma linha de tabela, o elemento <th> define um cabeçalho de tabela e o elemento <td> define uma célula de tabela.

Uma tabela HTML também pode incluir elementos <caption> , <colgroup> , <thead> , <tfoot> e <tbody> .


Suporte ao navegador

Element
<table> Yes Yes Yes Yes Yes

Atributos Globais

A <table>tag também suporta os Atributos Globais em HTML .


Atributos do evento

A <table>tag também suporta os atributos de evento em HTML .



Mais exemplos

Exemplo

Como adicionar bordas recolhidas a uma tabela (com CSS):

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

<table>
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
</table>

</body>
</html>

Exemplo

Como alinhar uma tabela à direita (com CSS):

<table style="float:right">
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
</table>

Exemplo

Como centralizar uma tabela (com 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>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
</table>

Exemplo

Como adicionar cor de fundo a uma tabela (com CSS):

<table style="background-color:#00FF00">
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
</table>

Exemplo

Como adicionar preenchimento a uma tabela (com CSS):

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

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

<table>
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
</table>

</body>
</html>

Exemplo

Como definir a largura da tabela (com CSS):

<table style="width:400px">
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
</table>

Exemplo

Como criar cabeçalhos de tabela:

<table>
  <tr>
    <th>Name</th>
    <th>Email</th>
    <th>Phone</th>
  </tr>
  <tr>
    <td>John Doe</td>
    <td>[email protected]</td>
    <td>123-45-678</td>
  </tr>
</table>

Exemplo

Como criar uma tabela com uma legenda:

<table>
  <caption>Monthly savings</caption>
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$80</td>
  </tr>
</table>

Exemplo

Como definir células de tabela que abrangem mais de uma linha ou uma coluna:

<table>
  <tr>
    <th>Name</th>
    <th>Email</th>
    <th colspan="2">Phone</th>
  </tr>
  <tr>
    <td>John Doe</td>
    <td>[email protected]</td>
    <td>123-45-678</td>
    <td>212-00-546</td>
  </tr>
</table>

Páginas relacionadas

Tutorial HTML: Tabelas HTML

Referência HTML DOM: objeto de tabela

Tutorial CSS: Estilizando Tabelas


Configurações padrão de CSS

A maioria dos navegadores exibirá o <table>elemento com os seguintes valores padrão:

Exemplo

table {
  display: table;
  border-collapse: separate;
  border-spacing: 2px;
  border-color: gray;
}