Table Border: The Old (HTML) And New (CSS) Code Compared
Disclosure: Your support helps keep the site running! We earn a referral fee for some of the services we recommend on this page. Learn more
- Attribute of
- Create An HTML Table Quickly & Easily With Our Code Example
- What does
Table Border: The Old (HTML) And New (CSS) Code Compared
do? - Was used to specify whether or not borders should be applied to all table cells. This attribute has been deprecated in favor of CSS.
Code Example
<table border="0">
<tr><td>First column</td><td>Second column</td><td>Third column</td></tr>
<tr><td>First column</td><td>Second column</td><td>Third column</td></tr>
<tr><td>First column</td><td>Second column</td><td>Third column</td></tr>
</table>
First column | Second column | Third column |
First column | Second column | Third column |
First column | Second column | Third column |
Formatting Table Borders
The table border
attribute could accept two values: 0 for no borders and 1 to display borders around table cells. Simple as that. However, the attribute has been deprecated in favor of table borders styled with CSS. Here’s an example of how borders can be added to a table with CSS.
<style> table.example-table, .example-table td { border: 1px solid green; border-collapse: collapse; } </style> <table class="example-table"> <tr><td>First column</td><td>Second column</td><td>Third column</td></tr> <tr><td>First column</td><td>Second column</td><td>Third column</td></tr> <tr><td>First column</td><td>Second column</td><td>Third column</td></tr> </table>
And here’s how that simple bit of code is rendered in the browser:
table.example-table, .example-table td{border: 1px solid green; border-collapse: collapse;}
First column | Second column | Third column |
First column | Second column | Third column |
First column | Second column | Third column |