1.

Explain table in HTML.

Answer»

Html table tag helps us to arrange our item in rows and columns of cells. To create HTML table we use <table> tag and along with this, we need to use <tr> tag which creates rows in the table and <td>  tag through which we can input data inside our table. To put heading inside the table we can use <th> tag which helps to give heading to the table.

There are also two optional tags called <thead> and <tbody>, which are used to group header and body respectively.

We can also combine any row, with the colspan attribute. One more thing to note is that earlier there were many more attributes to style the table. But with HTML5 specifications, we need to style a table through CSS.

In the below example, we can see a simple table and other tables with all tags.

<!DOCTYPE html> <html> <head>    <title>Table tutorials</title>    <style>        table,        td {            border: 1px SOLID #333;        }        thead,        tfoot {            background-color:lightslategray;            color: #fff;        }    </style> </head> <body>    <h1>Simple table</h1>    <table>        <tr>            <th>FIRST name</th>            <th>LAST name</th>        </tr>        <tr>            <td>John</td>            <td>Wayne</td>        </tr>        <tr>            <td>Tommy</td>            <td>Lee</td>        </tr>    </table>    <h1>Table with thead, tfoot, and tbody</h2>        <table>            <thead>                <tr>                    <th>Countries</th>                    <th>Population</th>                </tr>            </thead>            <tbody>                <tr>                    <td>India</td>                    <td>1.32 Billion</td>                </tr>                <tr>                    <td>CHINA</td>                    <td>1.38 Billion</td>                </tr>            </tbody>            <tfoot>                <tr>                    <td colspan="2">Largest Population</td>                </tr>            </tfoot>        </table> </body> </html>



Discussion

No Comment Found