How to create a table with HTML

To create a table with HTML, we will use the ‘<table> </table>‘, ‘<tr> </tr>‘, ‘<th> </th>‘ and ‘<td> </td>‘ tags. The ‘<table>‘ tag defines a table. The ‘<tr>‘ tag defines a row. The ‘<td>‘ tag defines each cell in the table, while the ‘<th>‘ tag defines the header cells of a table. Let’s explain this with an example. Let’s create an HTML table with 2 rows and 2 columns containing country and city pairings.

A simple HTML table codes:

<table>
<tr>
<th>Country</th>
<th>City</th>
</tr>
<tr>
<td>England</td>
<td>London</td>
</tr>
<tr>
<td>France</td>
<td>Paris</td>
</tr>
</table>

The image will look like this:

Country City
England London
France Paris

When we add some css codes between the <style></style> tags, it will look better. For example,

<style>
table, th, td { border:1px solid black;}
</style>

when you add this code between the style tags, the table will look like this.

Country City
England London
France Paris