HTML Table border Attribute: A Comprehensive Guide

Introduction: Why Table Borders Matter

Tables are used to display structured data such as marksheets, reports, price lists, and records.
Without borders, table data can look confusing and hard to read.

In early HTML, the border attribute was used to add borders to tables.
As a beginner, it’s important to understand:

  • What the border attribute does

  • How it works

  • Why it is now considered outdated

  • What modern alternatives you should use

This guide explains everything in a clear, teacher-style, beginner-friendly way.

What Is the HTML Table border Attribute?

The border attribute is used inside the <table> tag to specify the thickness of the table border.

👉 In simple words:
It tells the browser to draw a border around the table and its cells.

Basic Syntax of border Attribute

The border attribute is used inside the <table> tag to specify the thickness of the table border.

👉 In simple words:
It tells the browser to draw a border around the table and its cells.

Basic Syntax of border Attribute
  • border="1" → Adds a visible border

  • Value represents border thickness (in pixels)

Example 1: Simple Table with Border

 
<table border="1">
  <tr>
    <th>Name</th>
    <th>Marks</th>
  </tr>
  <tr>
    <td>Ravi</td>
    <td>85</td>
  </tr>
</table>

Output Explanation

  • A border appears around the table

  • Borders also appear between rows and columns

  • Default border color is usually black

Changing Border Thickness

You can increase the border thickness by changing the value.

<table border=”3″>
Example
<table border="3">
  <tr>
    <td>HTML</td>
    <td>CSS</td>
  </tr>
</table>

👉 Thicker borders are created, but styling control is limited.

Where the border Attribute Applies

When you use:

 
<table border="1">

It automatically applies borders to:

  • <table>

  • <tr>

  • <th>

  • <td>

You cannot control them separately using only HTML.

Limitations of the border Attribute

  • No control over border color
  •  No control over individual cell borders
  • No control over spacing or style
  • Not responsive-friendly
  • Deprecated in HTML5

👉 Because of these limitations, modern web development avoids using border attribute.

HTML5 Status: Is border Deprecated?

⚠️ Yes, the border attribute is deprecated in HTML5.

  • It still works in browsers

  • But it is not recommended

  • It should only be used for learning or quick demos

Modern & Recommended Way: CSS Borders

CSS gives full control and is industry standard

HTML

<table class="my-table">
  <tr>
    <th>Subject</th>
    <th>Marks</th>
  </tr>
  <tr>
    <td>Math</td>
    <td>90</td>
  </tr>
</table>

CSS

.my-table {
  border-collapse: collapse;
}

.my-table th,
.my-table td {
  border: 1px solid #333;
  padding: 10px;
  text-align: center;
}

Benefits of CSS

  • Control border color

  • Control thickness

  • Control spacing

  • Cleaner HTML

  • SEO & accessibility friendly

HTML border Attribute vs CSS Border

Featureborder AttributeCSS Border
HTML5 support❌ Deprecated✅ Supported
Border color❌ No✅ Yes
Styling flexibility❌ Limited✅ Full
Professional use❌ No✅ Yes
Recommended❌ No✅ Yes

When Can Beginners Use border Attribute?

  •  For learning basics
  • For exams and theory questions
  •  For quick testing

❌ Not for real projects
❌ Not for production websites

Common Beginner Mistakes

  • Using border in HTML5 projects
  • Trying to change color using HTML
  •  Forgetting border-collapse
  •  Mixing HTML borders with CSS borders
  • Using tables for page layout

Best Practices (Industry Standard)

  • Use CSS for all table styling
  •  Use border-collapse: collapse
  • Keep HTML clean and semantic
  • Use tables only for data
    ❌ Avoid deprecated attributes

FAQs: HTML Table Border Attribute

What does border="1" do?

It adds a visible border around the table and its cells.

Is the border attribute still supported?

Browsers support it, but it is deprecated and not recommended.

Can I change border color using HTML?

No, you need CSS for that.

Should I use border attribute in real projects?

No, always use CSS instead.

Why do beginners still learn it?

For understanding legacy HTML and exam purposes.