Etiqueta HTML <td>


Ejemplo

Una tabla HTML simple, con dos filas y cuatro celdas de tabla:

<table>
  <tr>
    <td>Cell A</td>
    <td>Cell B</td>
  </tr>
  <tr>
    <td>Cell C</td>
    <td>Cell D</td>
  </tr>
</table>

Más ejemplos de "Pruébelo usted mismo" a continuación.


Definición y uso

La <td>etiqueta define una celda de datos estándar en una tabla HTML.

Una tabla HTML tiene dos tipos de celdas:

  • Celdas de encabezado: contiene información de encabezado (creada con el elemento <th> )
  • Celdas de datos: contiene datos (creados con el <td>elemento)

El texto de los <td>elementos es regular y está alineado a la izquierda de forma predeterminada.

El texto de los elementos <th> está en negrita y centrado de forma predeterminada. 


Compatibilidad con navegador

Element
<td> Yes Yes Yes Yes Yes

Atributos

Attribute Value Description
colspan number Specifies the number of columns a cell should span
headers header_id Specifies one or more header cells a cell is related to
rowspan number Sets the number of rows a cell should span

Atributos globales

La <td>etiqueta también es compatible con los atributos globales en HTML .


Atributos de eventos

La <td>etiqueta también es compatible con los atributos de eventos en HTML .



Más ejemplos

Ejemplo

Cómo alinear contenido dentro de <td> (con CSS):

<table style="width:100%">
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td style="text-align:right">$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td style="text-align:right">$80</td>
  </tr>
</table>

Ejemplo

Cómo agregar color de fondo a la celda de la tabla (con CSS):

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

Ejemplo

Cómo establecer la altura de una celda de tabla (con CSS):

<table>
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td style="height:100px">January</td>
    <td style="height:100px">$100</td>
  </tr>
</table>

Ejemplo

Cómo especificar que no se ajusten las palabras en la celda de la tabla (con CSS):

<table>
  <tr>
    <th>Poem</th>
  </tr>
  <tr>
    <td style="white-space:nowrap">Never increase, beyond what is necessary, the number of entities required to explain anything</td>
  </tr>
</table>

Ejemplo

Cómo alinear verticalmente el contenido dentro de <td> (con CSS):

<table style="width:50%;">
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr style="height:100px">
    <td style="vertical-align:bottom">January</td>
    <td style="vertical-align:bottom">$100</td>
  </tr>
</table>

Ejemplo

Cómo establecer el ancho de una celda de tabla (con CSS):

<table style="width:100%">
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td style="width:70%">January</td>
    <td style="width:30%">$100</td>
  </tr>
</table>

Ejemplo

Cómo crear encabezados de tabla:

<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>

Ejemplo

Cómo crear una tabla con un título:

<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>

Ejemplo

Cómo definir celdas de tabla que abarcan más de una fila o una columna:

<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 de HTML: tablas HTML

Referencia HTML DOM: objeto TableData

Tutorial de CSS: tablas de estilo


Configuración predeterminada de CSS

La mayoría de los navegadores mostrarán el <td>elemento con los siguientes valores predeterminados:

td {
  display: table-cell;
  vertical-align: inherit;
}