HTML TABLES



HTML Table represents data in a tabular form. It is composed of columns and rows of cells that contain data.

The <table> element defines an HTML Table.

HTML Table Elements

  • <thead> defines a table header 
  • <tbody> defines a table body
  • <tfoot> defines a table footer 
  • <tr> defines a table row. colspan attribute: defines how many columnsshould a cell span
  • <th> defines a table heading 
  • <td>: defines a table data/cell rowspan attribute: defines how many rowsshould a cell span; also works in <th>
  • <colgroup> : specifies a group of one or more columnsin a table
  • <col>: specifies column properties for each column in a colgroup (empty element)
  • <caption> defines a caption for a table.

HTML Table Attributes

  • align: defines the alignment of a table
  • bgcolor: defines the background color of a table
  • border: defines the size of the frame surrounding a table
  • cellpadding: defines the space between the content of a cell and its border.
  • Cellspacing: defines the space between two cells
  • frame: defines which side of the frame surrounding the table must be displayed
  • rules: defines where rules should appear in a table
  • summary: defines an alternative text that summarizes the content of the table 
  • width: defines the width of a table

Example:

<! DOCTYPE html> 

<html> 

        <head>

            <title> Tables</title>

        </head>

        <body>

            <table border="1">

                    <thead>

<th> First Name </th>

<th> Middle Name</th>

<th> Last Name <th>

                    </thead> 

                    <tbody>

                         <tr>

         <td> A</td>

        <td>Rama Krishna</td>

        <td> Reddy</td>

                         </tr>

                    </tbody>

            </table>

        <body>

<html>

Output:

First NameMiddle NameLast Name
ARama KrishnaReddy