Tables are a powerful way to organize data on a webpage, especially when dealing with rows and columns of structured content. While styling with CSS is the modern and preferred approach, there are still valid reasons—such as simplicity or email templates—for adding a table border using only HTML.
So, how can you add a border to an HTML table without using CSS?
The Answer: Use the border
Attribute in HTML
HTML provides a straightforward way to add borders to a table using the border
attribute directly in the <table>
tag.
Basic Syntax:
<table border="1">
<tr>
<th>Product</th>
<th>Price</th>
</tr>
<tr>
<td>Apples</td>
<td>$1.00</td>
</tr>
<tr>
<td>Bananas</td>
<td>$0.50</td>
</tr>
</table>
Output:
This will render a table with visible borders around each cell.
About the border
Attribute
border="1"
means a 1-pixel-wide border.- You can increase the number to make the border thicker, e.g.,
border="2"
orborder="5"
. - The border will apply to the entire table and its cells.
⚠️ Note: The
border
attribute is considered obsolete in modern HTML5 and is primarily used for legacy support or quick prototyping. Use CSS for modern projects.
Additional Table Attributes (Optional)
You can combine the border
attribute with other basic HTML attributes for better formatting:
<table border="1" cellpadding="5" cellspacing="0">
<tr>
<th>Name</th>
<th>Email</th>
</tr>
<tr>
<td>John Doe</td>
<td>jo**@ex*****.com</td>
</tr>
</table>
cellpadding
adds space inside the cells.cellspacing
controls the space between table cells.
When to Use HTML Table Borders Without CSS
✅ Suitable for:
- Email templates that don’t support CSS
- Simple demo pages
- Legacy projects
- Quick tests or prototypes
❌ Not ideal for:
- Modern responsive layouts
- Styled or dynamic data tables
- Long-term production use
Conclusion
To create a table border in HTML without using CSS, simply use the border
attribute in the <table>
tag. Although it’s outdated in modern standards, it remains a quick and simple way to visualize tables—especially when working in environments where CSS is limited or unavailable.
For best practices and full styling control, consider switching to CSS in production environments.