HTML Tables

Posted by admin at August 11, 2021

Define an HTML Table

The <table> tag defines an HTML table.

Each table row is defined with a <tr> tag. Each table header is defined with a <th> tag. Each table data/cell is defined with a <td> tag.

By default, the text in <th> elements are bold and centered.

By default, the text in <td> elements are regular and left-aligned.

Creating a basic table

The basic structure of an HTML table consists of the following tags:

  • Table tags:  <TABLE> </TABLE>
  • Row tags:   <TR> </TR>
  • Cell tags:    <TD> </TD>

Constructing an HTML table consists of describing the table between the beginning table tag, <TABLE>, and the ending table table tag, </TABLE>. Between these tags, you then construct each row and each cell in the row. To do this, you would first start the row with the beginning row tag, <TR>, and then build the row by creating each cell with the beginning cell tag, <TD>, adding the data for that cell, and then closing the cell with the ending cell tag, </TD>. When you finish all of the cells for a row, you would then close the row with the ending row tag, </TR>.Then, for each new row, you would repeat the process of beginning the row, building each cell in the row, and closing the row.

Simple Example:

    <th>Favorite Color</th>


Name Favorite Color
Bob Yellow
Michelle Purple

Complex Example:

<!DOCTYPE html>
      table {
        font-family: arial, sans-serif;
        border-collapse: collapse;
        width: 100%;

      th {
        border: 1px solid #dddddd;
        text-align: left;
        padding: 8px;

      tr:nth-child(even) {
        background-color: #dddddd;
    <h2>HTML Table</h2>

        <td>Alfreds Futterkiste</td>
        <td>Maria Anders</td>
        <td>Centro comercial Moctezuma</td>
        <td>Francisco Chang</td>
        <td>Ernst Handel</td>
        <td>Roland Mendel</td>
        <td>Island Trading</td>
        <td>Helen Bennett</td>
        <td>Laughing Bacchus Winecellars</td>
        <td>Yoshi Tannamuri</td>
        <td>Magazzini Alimentari Riuniti</td>
        <td>Giovanni Rovelli</td>


HTML Table

Company Contact Country
Alfreds Futterkiste Maria Anders Germany
Centro comercial Moctezuma Francisco Chang Mexico
Ernst Handel Roland Mendel Austria
Island Trading Helen Bennett UK
Laughing Bacchus Winecellars Yoshi Tannamuri Canada
Magazzini Alimentari Riuniti Giovanni Rovelli Italy


Write a Reply or Comment