HTML table border Attribute
Last Updated :
14 Apr, 2025
The HTML <table> border Attribute is used to specify the border of a table. It sets the border around the table cells. This attribute defines the visual presentation of the table by setting the thickness of the borders. A higher value results in a thicker border. Alternatively, setting the border
attribute to "0" removes the borders entirely.
Syntax:
<table border="value">
In this code:
The value represents the thickness of the border in pixels.
- border="1": This means the table will have a border of 1 pixel.
- border="0": This will remove the borders from the table, leaving it borderless.
Now, let us understand with the help of the example:
HTML
<html>
<head>
<style>
body {
text-align: center;
}
table {
margin: 0 auto;
height: 20vh;
width: 40vh;
}
h1 {
color: green;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>HTML table border Attribute</h2>
<table border="1">
<caption>
Author Details
</caption>
<tr>
<th>NAME</th>
<th>AGE</th>
<th>BRANCH</th>
</tr>
<tr>
<td>BITTU</td>
<td>22</td>
<td>CSE</td>
</tr>
<tr>
<td>RAM</td>
<td>21</td>
<td>ECE</td>
</tr>
</table>
</body>
</html>
Output:

In this example:
- The body of the page uses flexbox to center all content horizontally and vertically on the screen, including the table and headings.
- The table is given a 1-pixel border using the border="1" attribute, and it contains 3 columns: NAME, AGE, and BRANCH.
- The table's dimensions are set using height and width as percentages of the viewport, making it responsive. The table is also centered with margin: 0 auto;.
- The main heading (<h1>) is colored green using CSS, and the subheading (<h2>) describes the content, both of which are centered.
- The table contains two rows of data, with names, ages, and branches of individuals, displayed in table cells (<td>), with each row created using <tr>.
Note: The border attribute is not supported by HTML5.
Collapsed Table Borders
To prevent the appearance of double borders in a table, you can use the CSS property 'border-collapse' and set it to "collapse." By doing so, the borders within the table will merge into a single border, providing a cleaner and more unified visual presentation.
Syntax:
table, th, td {
border-collapse: collapse;
}
Now, let us understand with the help of the example:
HTML
<html>
<head>
<style>
body {
text-align: center;
}
table {
margin: 0 auto;
height: 20vh;
width: 40vh;
}
table,
th,
td {
border-collapse: collapse;
}
h1 {
color: green;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>HTML table border Attribute</h2>
<table border="1">
<caption>
Author Details
</caption>
<tr>
<th>NAME</th>
<th>AGE</th>
<th>BRANCH</th>
</tr>
<tr>
<td>BITTU</td>
<td>22</td>
<td>CSE</td>
</tr>
<tr>
<td>RAM</td>
<td>21</td>
<td>ECE</td>
</tr>
</table>
</body>
</html>
Output:

In this example:
- The body is styled to center-align all the content on the page.
- The table is centered horizontally with margin: 0 auto;, and its size is set as a percentage of the viewport (height: 20vh; and width: 40vh;).
- collapse; style removes the space between borders of table cells, making them appear as a single solid line.
- The <h1> heading is colored green using CSS, while the subheading (<h2>) provides the context of the table content.
- The table has a caption "Author Details" and displays a simple data table with three columns: NAME, AGE, and BRANCH, with two rows of data.
Round Table Borders
For rounded table borders, apply the CSS 'border-radius' property to the table element with a specified radius value, creating a visually appealing circular border effect.
Syntax:
table, th, td {
border-radius: 10px;
}
Now, let us understand with the help of the example:
HTML
<html>
<head>
<title>
HTML table border Attribute
</title>
<style>
body {
text-align: center;
}
table {
margin: 0 auto;
height: 20vh;
width: 40vh;
}
table,
th,
td {
border-radius: 15px;
}
h1 {
color: green;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>HTML table border Attribute</h2>
<table border="1">
<caption>
Author Details
</caption>
<tr>
<th>NAME</th>
<th>AGE</th>
<th>BRANCH</th>
</tr>
<tr>
<td>BITTU</td>
<td>22</td>
<td>CSE</td>
</tr>
<tr>
<td>RAM</td>
<td>21</td>
<td>ECE</td>
</tr>
</table>
</body>
</html>
Output:

In this example:
- The content of the page, including headings and the table, is centered using text-align: center; in the CSS.
- The table is horizontally centered using margin: 0 auto; and its size is set as a percentage of the viewport (height: 20vh; and width: 40vh;).
- Rounded Borders: The border-radius: 15px; applied to the table, table headers (th), and table data cells (td) creates rounded corners for the table and its cells.
- The <h1> heading is styled with a green color, which makes the "GeeksforGeeks" title stand out on the page.
- The table contains a caption "Author Details" and displays three columns (NAME, AGE, BRANCH) with two rows of data (BITTU, RAM, etc.), and it has a 1-pixel border around the table and its cells.
Dashed Table Borders
To use dashed table borders, use the CSS 'border-style' property and set it to "dashed" for the desired table cells. You can also use dotted
, dashed
, solid
, double
, groove
, ridge
, hidden , none
etc.
Syntax:
table, th, td {
border-style: dashed;
}
Now, let us understand with the help of the example:
HTML
<html>
<head>
<title>
HTML table border Attribute
</title>
<style>
body {
text-align: center;
}
table {
margin: 0 auto;
height: 20vh;
width: 40vh;
}
table,
th,
td {
border-style: dashed;
}
h1 {
color: green;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>HTML table border Attribute</h2>
<table border="1">
<caption>
Author Details
</caption>
<tr>
<th>NAME</th>
<th>AGE</th>
<th>BRANCH</th>
</tr>
<tr>
<td>BITTU</td>
<td>22</td>
<td>CSE</td>
</tr>
<tr>
<td>RAM</td>
<td>21</td>
<td>ECE</td>
</tr>
</table>
</body>
</html>
Output:

In this example:
- The body of the page is centered using text-align: center; to align the heading and table in the middle of the page.
- The table is centered horizontally using margin: 0 auto;, and its height and width are set as a percentage of the viewport (height: 20vh; and width: 40vh;).
- Dashed Borders: The border-style: dashed; applied to the table, <th>, and <td> creates dashed borders for the table cells and the table itself.
- The main heading (<h1>) is colored green using CSS for styling, making the title "GeeksforGeeks" stand out.
- The table has a caption "Author Details" and contains a header row with three columns (NAME, AGE, BRANCH) and two rows of data.
Limitations of the border Attribute
Although the border attribute is quick and easy to use, it has limitations:
- Lack of Customization: You cannot control individual borders of cells (top, bottom, left, or right) using the border attribute.
- No Style Flexibility: You cannot specify different border styles (solid, dashed, dotted, etc.) using the border attribute. It only affects the width.
- Outdated in Modern Development: The border attribute is no longer commonly used in modern web development because it doesn't offer much control over the table's styling.
Supported Browsers:
- Google Chrome 1
- Microsoft Edge 12
- Firefox 1
- Opera 12.1
- Safari 1
Conclusion
The border attribute in HTML tables offers a simple and quick way to add borders, but it comes with limitations in terms of flexibility and customization. In modern web development, CSS should be used to style table borders because it provides much more control over appearance, such as adjusting border width, color, and style. Additionally, CSS is more versatile and future-proof for styling web pages.
Similar Reads
HTML border attribute
The HTML border attribute is used to set the visible border width to most HTML elements within the body.Note: The HTML border attribute is not supported in HTML5.Syntax:Â Â <tag border="value">Supported tags:Â Â TableImageObjectExample 1: In this example, we will see code for the table border attr
2 min read
HTML | <object> border Attribute
The HTML <object> border attribute is used to define the width of the border around the object element. Note: This attribute is not supported by HTML5. Syntax: <object border="pixels"> Attribute Values: pixels: It is used to specify the width of the border in terms of pixel. Example: Thi
1 min read
HTML | <img> border Attribute
The <img> border attribute is used to specify the border width around the image. The default value of <img> border attribute is 0. It is not supported by HTML 5. Use CSS instead of this attribute. Syntax: <img border="pixels"> Attribute Values: It contains single value pixels which
1 min read
HTML <table> frame Attribute
The HTML <table> element's frame attribute specifies which sides of the tableâs border should be displayed. It can take values like a void, above, below, hsides, vsides, lhs, rhs, or box, controlling how the table's edges are framed.Syntax<table frame="value">Attribute ValuesValueDescrip
2 min read
HTML style attribute
In this article, we will see the HTML style attribute, along with understanding its implementation through examples. Styles in HTML are rules that describe how a document will be presented in a browser. Style information can be either attached as a separate document or embedded in the HTML document.
3 min read
HTML Table Borders
HTML Table Borders define the visible lines around cells and the overall table. They help in creating clear distinctions between various sections of the table, making it easier to understand and show information clearly. This attribute allows you to control the border's style, color, and width, for
5 min read
HTML5 MathML frame Attribute
This attribute holds the border value for the entire table. Possible values are none, solid and dashed. This attribute is accepted by <mtable> tag only. Syntax: <element frame="none|solid|dashed"> Attribute Values: none: This attribute sets the column lines of the table none.solid: This
1 min read
HTML | <Iframe> frameborder Attribute
The HTML Iframe frameborder Attribute is used to specify whether or not to display the border around the content of an <Iframe> Element. Syntax: <iframe frameborder="1 | 0"> Attribute Values: 0: It has a Default value. It sets the border on one state. 1: It sets the border on-off state.
1 min read
HTML bgcolor Attribute
HTML bgcolor attribute is used to set the background color of an HTML element. Bgcolor is one of those attributes that has become deprecated with the implementation of Cascading Style Sheets (see CSS Backgrounds). It accepts color names, hexadecimal color codes, or RGB values to customize the backgr
3 min read
HTML | <frame> frameborder Attribute
The HTML <frame> frameborder attribute is used to specify whether or not a border should be displayed between the frames. For this, we use two values 0 and 1, where 0 defines no border and 1 defines the border. Syntax <frame frameborder="1|0"> Note: This attribute is depreciated from HTM
1 min read