What is the use of border attribute of the table tag?

Last Update: Apr 27 2024 | BY: Pooja Kohli

S

Shwati Rana

border attribute in html


Border Attribute in HTML Table

The border attribute of the <table> tag in HTML is used to specify the width of the border around a table and its cells. However, the border attribute is deprecated in HTML5 and is no longer recommended for use. Instead, you should use CSS to control the appearance of the table borders.


Use of Border Attribute in Table

Now you can set borders to HTML tables by using CSS, even you can use the border property in your CSS stylesheet or inline styles, for more understanding check out the below-mentioned example of borders in Table.

<style>

    table {border-collapse: collapse;}

    table, th, td {border: 1px solid black;}

</style>


<table>

    <tr>

        <th>Header 1</th>

    </tr>

    <tr>

        <td>Cell 1</td>

    </tr>

</table>

According to the above example, the CSS rules are applied to the <table>, <th>, and <td> elements to set a 1-pixel solid black border around the table and its cells. The "border-collapse: collapse" rule ensures that adjacent cell borders merge into a single line, that considered the best practice to separate the presentation of your HTML using CSS.

1 votes

Your Answer

Email Us: advertise@gdatamart.com

Donate Us: Support to GDATAMART

LifeStyle & Fun

© 2024 GDATAMART.COM (All Rights Reserved)