HTML cellpadding Attribute

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

Definition and Usage

The cellpadding attribute belonged on <table>. It set the space between each cell’s border and its content — padding inside every <th> and <td> in that table.

Do not use it in new pages. MDN marks it obsolete. Apply the CSS padding property to th and td instead. Do not confuse it with cellspacing (space between cells).

Obsolete.

Presentational HTML. Kept for reading legacy tables — not for new markup. Prefer CSS padding on cells.

Still honored in many browsers.

Old pages may still look padded because engines keep compatibility. That is not a reason to write new cellpadding.

HTML Syntax

syntax.html
<table cellpadding=" length">

Historical form only. length was pixels (integer) or a percentage.

Attribute Values

What authors used, and the modern CSS mapping:

Value / approachDescriptionTry it
Pixel integere.g. cellpadding="8" — 8px inside every cellTry it
PercentageRelative padding (less common; prefer CSS units today)Try it
CSS padding on cellsModern replacement for th / tdTry it
vs cellspacingBetween-cell gap → CSS border-spacingTry it

Live Preview

Change the obsolete cellpadding value on a sample table. Prefer CSS in real projects.

Legacy attribute demo on <table>.

Table
ItemQty
Apples3
Pears2

cellpadding="8"

HTML Examples

Example 1 is historical. Examples 2–3 show CSS (and how padding differs from spacing).

Example 1 — Legacy cellpadding (Do Not Ship)

Older pages padded every cell from the table element.

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

How It Works

  1. Put cellpadding on <table>, not on each td.
  2. One value pads every header and data cell the same way.
  3. Pixels are the usual form (e.g. 10 means 10px).
  4. Obsolete. Keep for reading old HTML only.

Example 2 — Modern CSS padding on Cells

Same breathing room without the HTML attribute.

HTML
<style>
  table.scores {
    border-collapse: collapse;
  }
  table.scores th,
  table.scores td {
    border: 1px solid #888;
    padding: 10px;
  }
</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. Target th and td with padding in CSS.
  2. Use any CSS length — px, rem, or different sides (padding: 8px 12px).
  3. border-collapse: collapse keeps a clean grid with CSS borders.
  4. No cellpadding on the table element.

Example 3 — Padding Inside vs Space Between

CSS equivalents of cellpadding and cellspacing side by side.

HTML
<style>
  table.pad th,
  table.pad td {
    border: 1px solid #888;
    padding: 12px; /* was cellpadding */
  }
  table.space {
    border-spacing: 8px; /* was cellspacing */
    border-collapse: separate;
  }
  table.space th,
  table.space td {
    border: 1px solid #888;
    padding: 4px;
  }
</style>

<p>Inside cells (padding):</p>
<table class="pad">
  <tr><td>A</td><td>B</td></tr>
</table>

<p>Between cells (border-spacing):</p>
<table class="space">
  <tr><td>A</td><td>B</td></tr>
</table>
Try It Yourself

How It Works

  1. Padding = room around the text inside a cell (old cellpadding).
  2. Border-spacing = gap between neighboring cells (old cellspacing).
  3. border-collapse: separate is required for border-spacing to show.
  4. Collapse mode hides between-cell gaps — common for modern grids.

Edge Cases & Pitfalls

Most confusion is mixing padding with spacing.

obsolete

Not for new HTML

Validators flag it. Move spacing into CSS when you touch the table.

naming

Not the same as cellspacing

Inside vs between. Wrong attribute = wrong gap. See the comparison example.

scope

Table-only attribute

It applied from <table> to all cells. Per-cell or per-side padding needs CSS.

cascade

CSS padding can override legacy

A stylesheet may replace the look of an old cellpadding. Prefer one clear CSS source of truth.

units

Attribute had limited units

Pixels or percent. CSS unlocks rem, logical properties, and different padding per side.

Browser Support

cellpadding is an obsolete HTML attribute on tables. Many browsers still honor it for compatibility.

✓ Obsolete · Legacy only

cellpadding

Still applied in modern browsers for old pages. Not recommended for new work — use CSS padding on th and td.

0% Recommended for new work
Google Chrome Still applies · legacy
Legacy only
Mozilla Firefox Still applies · legacy
Legacy only
Apple Safari Still applies · legacy
Legacy only
Microsoft Edge Still applies · legacy
Legacy only
Opera Still applies · legacy
Legacy only
Internet Explorer Legacy support
Legacy only
cellpadding Obsolete — use CSS padding

Bottom line: Expect old tables to keep their HTML padding. Write new cell spacing with CSS padding.

Key Takeaways

  • Was: padding inside all cells, set on <table>.
  • Now: obsolete — use CSS padding on th / td.
  • Not cellspacing: that is the gap between cells.
  • CSS wins: per-side padding and modern units.

One line: learn cellpadding to read old tables — ship padding on cells instead.

Frequently Asked Questions

On a table element it set the space between a cell’s border and its content — padding inside every th and td in that table.
Yes. MDN marks it obsolete. Apply the CSS padding property to th and td instead.
cellpadding is space inside cells (content to border). cellspacing is space between cells. In CSS those map roughly to padding on cells vs border-spacing on the table.
No. It belonged on the table element and applied to all cells. Per-cell control always belonged in CSS (or style on individual cells).
A length in pixels (integer) or a percentage. Modern CSS padding supports rem, em, and more flexible units.
Many browsers still honor it for compatibility. New pages should use CSS so spacing stays maintainable.

Next: cellspacing

Legacy space between cells — replaced by CSS border-spacing.

cellspacing 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