<table> tag

HTML <table> tag

The <table> tag defines a table in the HTML document.

Table is a collection of cells, rows, columns etc.

You must use the tags below inside the <table> tag.

<tr> – To define a row of the table.

<td> – To define the data cell of the table.

<th> – To define the table heading. By default, it is bold and center.

Less important tags which are optional

<caption> – To define the caption for the table heading.

<thead> – To group the header content.

<tbody> – To group the body content.

<tfoot> – To group the footer content.

<colgroup> – To group one or more columns of the table for formatting.

<col> – To define properties of each column inside the <colgroup>.

Syntax:

The Syntax of Column width:
td {
     width: value(valid width values);
}
The Syntax of Column height:
td {
     height: value(valid height values);
}
The Syntax of Row Height:
tr {
     line-height: value(valid height values);
}

Example

<table width ="50%" border ="4">
  <caption> TutorialBrain Courses </caption>
  <tr>
    <th>BIG DATA </th>
    <th>DIGITAL MARKETING</th>
    <th>MAINFRAME </th>
  </tr>
  <tr>
    <td>Spark</td>
    <td>SEO Analytics</td>
    <td>COBOL</td>
  </tr>
  <tr>
    <td>Scala</td>
    <td>Social Media Marketing </td>
    <td>DB2</td>
  </tr>
</table>

How Browser will display

BLOCK Level.

Difference between HTML4.01, XHTML and HTML5

HTML4 XHTML HTML5
None None HTML5 does not support these attributes - align, bgcolor, border, cellpadding, cellspacing, frame, rules, summary and width.

Attributes used with <table> tag

Attribute Description
align Describes the alignment of elements based on nearby elements.
(HTML5 does not support this attribute with this tag).
abbr Sets the abbreviation for the content of the HTML Document
(HTML5 does not support this attribute with this tag).
bgcolor Describes Background color of the elements.
(HTML5 does not support this attribute with this tag).
border Border of the elements is defined.
(HTML5 does not support this attribute with this tag).
cellpadding sets the padded space betwee the boundary of the cell to the boundary of the content.
(HTML5 does not support this attribute with this tag).
cellspacing Space between consecutive cells.
(HTML5 does not support this attribute with this tag).
summary Sets the summary of the content of the table
(HTML5 does not support this attribute).
width Width of the table
(HTML5 does not support this attribute).

Global Attributes

The <table> tag supports Global attributes.

Event Attributes

The <table> tag supports Event attributes.

Supporting Browsers

supporting-browsers for tags

Default CSS Values

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

     

Related Tags

<tr><td><th><caption><thead><tfoot><colgroup><col> tags.

Tutorials for all brains!