Creating Tables in HTML

Tables are created with the table tag ( <table></table> ). When creating tables, you will often use a number of tags and attributes.

The Border Attribute

The border attribute is used to specify the thickness of the lines around a table.

<table border="2">
<tr>
<td> New2HTML.com </td>
</tr>
</table>

Output:

New2HTML.com

The table row tag ( <tr> ), is used to add a new row to a table. After you have added a table row you may add data to that row by using the table data ( <td> ) tag.

<table border="2">
    <tr>
        <td> Apple </td>
        <td> Chicken </td>
    </tr>
</table>

The first <td> tag enters data in the first column, the second td tag enters data in the same row but second column.

What it looks like:

Apple Chicken

The table header tag ( <th> ) is used to set the column headings of a table.

<table border="2">
    <tr>
        <th> Fruit </th>
        <th> Not A Fruit </th>
    </tr>
    <tr>
        <td> Apple </td>
        <td> Chicken </td>
    </tr>
</table>

Result:

Fruit Not A Fruit
Apple Chicken

The Width Attribute

The width attribute can also be applied to tables. By using the attribute you can determine how wide a table is on your web page.

<table border="2" width="70%">
    <tr>
        <td> New2HTML.com </td>
    </tr>
</table>
New2HTML.com

Note: The value of the width attribute can be set using a percentage value or by a pixel value.