HTML border Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The border attribute set a border width in pixels on legacy elements — mainly <table>, <img>, and <object>. On a table it defined the size of the outer frame; 0 meant no frame.

Do not use it in new pages. MDN recommends the CSS border property (and related properties like border-collapse) instead. For images, the HTML living standard says authors should not specify border; if it is present, its value must be "0".

Deprecated / legacy.

Presentational HTML. Documented so you can read old markup and migrate tables and images to CSS — not for new designs.

Browsers may still draw it.

Compatibility rendering is common, which is why old border="1" tables still look bordered. Prefer CSS so width, style, and color stay under your control.

HTML Syntax

syntax.html
<table|img|object border=" pixels">

pixels is a non-negative integer (no unit). Historical form only.

Attribute Values

Common legacy values and the modern CSS approach:

ValueDescriptionTry it
1, 2, …Border width in pixels (table frame / image border)Try it
0No border; on img, the only value the living standard still allows if presentTry it
OmittedNo HTML border attribute (preferred for new img)Try it
CSS borderModern replacement — set width, style, and color togetherTry it

Live Preview

Change the deprecated border width on a sample table. Use CSS in real projects.

Legacy attribute demo on <table>.

Table
ItemQty
Apples3
Pears2

border="1"

HTML Examples

Example 1 is historical. Examples 2–3 show CSS (and the special img rule).

Example 1 — Legacy Table border (Do Not Ship)

Older pages set a pixel frame on the table element.

HTML
<table border="1">
  <tr>
    <th>Name</th>
    <th>Score</th>
  </tr>
  <tr>
    <td>Ada</td>
    <td>12</td>
  </tr>
</table>
Try It Yourself

How It Works

  1. border="1" asks for a 1-pixel outer frame on the table.
  2. Integer only — no px unit in the attribute value.
  3. border="0" turns the HTML frame off.
  4. Deprecated. Learn it for old pages; do not copy into new templates.

Example 2 — Modern CSS Table Borders

Control outer and cell borders with CSS.

HTML
<style>
  table.scores {
    border-collapse: collapse;
    border: 1px solid #888;
  }
  table.scores th,
  table.scores td {
    border: 1px solid #888;
    padding: 0.35rem 0.6rem;
  }
</style>

<table class="scores">
  <tr>
    <th>Name</th>
    <th>Score</th>
  </tr>
  <tr>
    <td>Ada</td>
    <td>12</td>
  </tr>
</table>
Try It Yourself

How It Works

  1. Drop the HTML attribute and style with border.
  2. border-collapse: collapse merges adjacent cell borders cleanly.
  3. Style th and td when you want a full grid, not only an outer frame.
  4. You control color and style (solid, dashed, and more) — the attribute could not.

Example 3 — Images: Prefer No HTML border

Use CSS for image frames. Avoid non-zero border on <img>.

HTML
<!-- Avoid: <img border="2" …> -->

<style>
  img.framed {
    border: 2px solid #333;
  }
</style>

<img
  class="framed"
  src="/images/logo.png"
  alt="CodeToFun logo"
  width="120"
  height="120">
Try It Yourself

How It Works

  1. Spec guidance: do not put border on <img>; if you must for old tools, only border="0" is conforming.
  2. Draw a frame with CSS — width, style, and color in one place.
  3. Always keep alt for accessibility (unrelated to border, required for images).
  4. Same idea for <object> — use CSS, not the HTML attribute.

Edge Cases & Pitfalls

Most issues come from expecting the attribute to style a full CSS grid.

deprecated

Not for new HTML

Replace with CSS when you edit a page. Keep presentational attributes out of components and templates.

img

Non-zero img border is non-conforming

If border appears on an image, the living standard requires the value 0. Use CSS for visible frames.

tables

Outer frame ≠ full grid

For lines around every cell, style th/td in CSS. Related legacy attributes rules and frame are also obsolete.

units

No px in the attribute

Write border="2", not border="2px". CSS uses units; the HTML attribute does not.

cascade

CSS can override legacy borders

A stylesheet may hide or restyle an old HTML border. Pick one approach — CSS — so behavior is predictable.

Browser Support

border is a deprecated HTML attribute on table, img, and object. Many browsers still render it for compatibility.

✓ Deprecated · Legacy only

border

Still drawn in modern browsers for old pages. Not recommended for new work — use the CSS border property.

0% Recommended for new work
Google Chrome Still paints · legacy
Legacy only
Mozilla Firefox Still paints · legacy
Legacy only
Apple Safari Still paints · legacy
Legacy only
Microsoft Edge Still paints · legacy
Legacy only
Opera Still paints · legacy
Legacy only
Internet Explorer Legacy support
Legacy only
border Deprecated — use CSS

Bottom line: Expect old tables and images to keep their HTML borders. Write new borders with CSS.

Key Takeaways

  • Was: pixel border width on table, img, and object.
  • Now: deprecated — use CSS border (and border-collapse for tables).
  • Images: omit the attribute; only 0 is allowed if it must appear.
  • Value: non-negative integer pixels — no units in the attribute.

One line: learn HTML border to read old pages — ship CSS border instead.

Frequently Asked Questions

On table, img, and object it set a border width in pixels. On tables it controlled the outer frame size. On images it drew a border around the picture.
Yes. MDN lists it as a legacy/deprecated attribute. Use the CSS border property instead for new pages.
It requests no border. The HTML living standard says authors should not put border on img; if it is present, its value must be the string 0. Prefer CSS (for example border: none).
The attribute mainly set the table’s outer frame. Inner cell lines were often affected by browser defaults or related attributes like rules. Today, style table, th, and td with CSS and usually border-collapse: collapse.
Historically table, img, and object. Do not invent border on arbitrary elements — use CSS on any element you need.
Many browsers still draw them for compatibility. That does not make them good practice for new HTML.

Next: cellpadding

Legacy cell padding — replaced by CSS padding on th and td.

cellpadding tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful