The Wayback Machine - https://web.archive.org/web/20250121135911/https://www.geeksforgeeks.org/html-border-attribute/
Open In App

HTML border attribute

Last Updated : 28 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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:  

Example 1: In this example, we will see code for the table border attribute in an HTML document. 

HTML
<!DOCTYPE html>
<html>

<head>
    <title>
        HTML table border Attribute
    </title>
</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: 


Example 2: In this example, we will see code for Image border attribute in an HTML document. 

HTML
<!DOCTYPE html>
<html>

<head>
    <title>
        HTML img border Attribute
    </title>
</head>

<body>
    <h1>GeeksforGeeks</h1>

    <h2>HTML img border Attribute</h2>

    <img src=
"https://media.geeksforgeeks.org/wp-content/uploads/20190506164011/logo3.png" 
         alt="GeeksforGeeks logo"
         border="5">
</body>

</html>

Output: 


Example 3: In this example, we will see code for Object border attribute in an HTML document. .  

HTML
<!DOCTYPE html>
<html>

<head>
    <title>
        HTML object border Attribute
    </title>
</head>

<body>
    <center>
        <h1>GeeksForGeeks</h1>

        <h1>
            HTML <object> border Attribute
        </h1>
        <br>

        <object data=
"https://www.geeksforgeeks.org/wp-content/uploads/Geek_logi_-low_res.png" width="550px"
            height="150px" border="4">
            GeeksforGeeks
        </object>
    </center>
</body>

</html>

Output: 
 

Supported Browsers:

  • Google Chrome 1
  • Edge 12
  • Firefox 1
  • Apple Safari 3.5
  • Opera 1

HTML border attribute – FAQs

Can I set the border color using the border attribute?

No, the border attribute alone does not allow you to set the border color. To specify the border color, you need to use CSS, like style=”border: 1px solid #000000;”.

What is the default value of the border attribute?

The default value of the border attribute is 0, meaning no border is displayed unless a value is explicitly specified.

How do I remove a border set by the border attribute?

To remove a border, you can set the border attribute to 0, like <table border=”0″>, or simply omit the attribute.

How do I create a border with a specific style using the border attribute?

The border attribute alone only sets the width of the border. To apply different styles (like dashed or dotted), use CSS with the border-style property: style=”border: 1px dashed #000;”.

What is the difference between the border attribute and the border CSS property?

The border attribute is an older method of adding a border, limited to specifying only the width. The border CSS property is more powerful, allowing you to set the width, style, and color in a single declaration, like style=”border: 1px solid red;”.



Next Article

Similar Reads

three90RightbarBannerImg