Mark table body with tbody element

Description

The tbody element marks the rows for table body as opposed to the header and footer rows.

The align, char, charoff, and valign attributes are obsolete.

Most browsers automatically insert the tbody element when they process a table element, even if it has not been specified in the document. CSS selectors that depend on table layout as written can fail.

For example, a selector such as table > tr won't work, because the browser has inserted a tbody element between the table and tr elements.

To address this, you must use a selector such as table > tbody > tr, table tr (no > character), or even just tbody > tr.

Example

The following code shows the addition of tbody element to the example table.


<!DOCTYPE HTML>
<html>
<head>
<style>
thead th {<!--  w ww .  ja v  a 2 s  .  c  o m-->
  text-align: left;
  background: grey;
  color: white
}

tbody  th {
  text-align: right;
  background: lightgrey;
  color: grey
}
</style>
</head>
<body>
  <table>
    <tbody>
      <tr>
        <th>Favorite:</th>
        <td>XML</td>
        <td>HTML</td>
        <td>CSS</td>
      </tr>
      <tr>
        <th>2nd Favorite:</th>
        <td>Java</td>
        <td>Javascript</td>
        <td>Oracle</td>
      </tr>
      <tr>
        <th>3rd Favorite:</th>
        <td>C#</td>
        <td>MySQL</td>
        <td>PHP</td>
      </tr>
    </tbody>
  </table>
</body>
</html>

Click to view the demo





















Home »
  HTML CSS »
    HTML »




HTML Introduction
HTML Document
HTML Section
HTML Group Content
HTML Text Marker
HTML Table
HTML Form
HTML Embed