hashnode-blogs

Tables in HTML 🧱

Tables on a webpage can be used to display data in an organized format.

In HTML, the fundamental unit of a table is a cell.

And cells are grouped into rows.

A table can have head body and foot .

⚡ In this blog, live preview of every code is given. Make sure to download the codes used in this blog and try to tweak them by your own. You can also use W3Schools Tryit Playground.

The code for a typical table in HTML <table> </table>

<table>
    <thead>
        <tr>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Marks</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>John</td>
            <td>Doe</td>
            <td>34</td>
        </tr>
        <tr>
            <td>Jane</td>
            <td>Doe</td>
            <td>24</td>

        </tr>
        <tr>
            <td>John</td>
            <td>Smith</td>
            <td>20</td>
        </tr>
        <tr>
            <td>Jane</td>
            <td>Smith</td>
            <td>25</td>
        </tr>

    </tbody>
    <tfoot>
        <tr>
            <td colspan="2">Total</td>
            <td>113</td>
        </tr>
    </tfoot>
</table>

The output:

The breakdown of the above code 🔯

All the code to create a table is wrapped inside <table> </table> tag.

This parent table tag can have three children <thead> </thead>, <tbody> </tbody> and <tfoot> </tfoot>.

Basically, these children tags of the table are rows or groups of rows.

And a row is created using <tr> </tr> tag.

And a row consists of cells.

A cell can be created using


Useful attributes


Colspan and Rowspan

They are the attributes given to cells <td> </td> and <th> </th> .

Check the source code and live preview for more experiments I have done on tables.

Read more about tables - Official Docs


Exercises 🏌️

Here are some easy and worth practicing exercises on w3Schools.


Source Codes 💠

In the next blog, I will be writing about anchor tags <a href="https://google.com"> Click here </a> .