HTML Tutorials

Applying borders to the table element

The table element defines the border attribute. When you apply this attribute, it tells the browser you are using the table to represent tabular data, rather than to lay out other elements. Most browsers respond to the border attribute by drawing borders around the table and each individual cell.

Using the border attribute
    <meta name="author" content="Adam Freeman"/>
    <meta name="description" content="A simple example"/>
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
    <table border="1">
      <caption>Results of the 2011 Fruit Survey</caption>
      <colgroup id="colgroup1">
        <col id="col1And2" span="2"/>
        <col id="col3"/>
      <colgroup id="colgroup2" span="2"/>
          <th colspan="2">Size & Votes</th>
          <th>2nd Favorite:</th>
          <th>3rd Favorite:</th>
          <td colspan="2" rowspan="2">
            Pomegranates and cherries can both come in a range of colors
                        and sizes.
          <th rowspan="2">Joint 4th:</th>
          <td rowspan="2">75</td>
          <td>Very Large</td>
          <th colspan="5">&copy; 2011 Adam Freeman Fruit Data Enterprises</th>

The value assigned to the border attribute must be 1 or the empty string (“”). This attribute doesn’t control the style of the border. You do that via CSS. You can see how Google Chrome responds to the presence of the border attribute below.