Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Put text-align: center on the image’s containing <td> (or <th>) to center it horizontally. Add vertical-align: middle to that same cell when the cell is taller than the image and you want vertical centering too.

<table>
  <tr>
    <td class="image-cell">
      <img src="image.jpg" alt="Description">
    </td>
  </tr>
</table>
.image-cell {
  text-align: center;
  vertical-align: middle;
}

This works because an image is normally inline-level content inside the table cell. The cell controls the horizontal placement of its contents, while the cell’s vertical alignment controls how content sits within the row’s height.

The minimal markup

For a browser-rendered HTML table, the smallest reliable pattern is:

<table>
  <tr>
    <td style="text-align: center; vertical-align: middle;">
      <img src="image.jpg" alt="Description">
    </td>
  </tr>
</table>

text-align: center centers the image horizontally in the cell. vertical-align: middle centers the cell’s content vertically when the row or cell has additional height. If the cell is only as tall as the image, vertical centering has no visible effect.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Use a class instead of repeating inline styles

Inline CSS is useful for a one-off test, but a stylesheet is easier to maintain when several cells use the same layout.

<table class="product-table">
  <tr>
    <td class="product-table__image">
      <img src="product.jpg" alt="Blue travel mug">
    </td>
    <td>Blue travel mug</td>
  </tr>
</table>
.product-table {
  border-collapse: collapse;
}

.product-table__image {
  text-align: center;
  vertical-align: middle;
  width: 180px;
}

.product-table__image img {
  display: inline-block;
  max-width: 100%;
  height: auto;
}

The width on the cell is optional; it simply gives the image a predictable area in which to center. max-width: 100% prevents a wide image from overflowing a narrow cell, and height: auto preserves its proportions.

Horizontal versus vertical centering

Horizontal only

Use this when the row height is determined by the image or when vertical placement is irrelevant:

.image-cell {
  text-align: center;
}

On a table cell, text-align sets the horizontal alignment of inline-level content inside that cell. The rule affects the image without requiring a special property on the image itself.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Both axes

Use both declarations when another cell makes the row taller, for example when text wraps over several lines:

.image-cell {
  text-align: center;
  vertical-align: middle;
}

On a table cell, vertical-align: middle aligns the cell’s content within the row. It is different from applying vertical-align to the image: on an image, that property affects the image’s position relative to the line box and neighboring inline content.

Top or bottom alignment

If centered vertical placement is not appropriate, choose an explicit alternative:

.image-cell--top {
  vertical-align: top;
}

.image-cell--bottom {
  vertical-align: bottom;
}

Keep text-align: center on either class if the image should remain horizontally centered.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A complete responsive example

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Centered table image</title>
  <style>
    .comparison {
      width: 100%;
      border-collapse: collapse;
    }

    .comparison th,
    .comparison td {
      border: 1px solid #c8c8c8;
      padding: 1rem;
    }

    .comparison__image {
      width: 12rem;
      text-align: center;
      vertical-align: middle;
    }

    .comparison__image img {
      display: inline-block;
      max-width: 100%;
      height: auto;
    }
  </style>
</head>
<body>
  <table class="comparison">
    <tr>
      <th scope="row" class="comparison__image">
        <img src="camera.jpg" alt="Compact digital camera">
      </th>
      <td>
        A compact camera with a larger sensor and optical zoom.
      </td>
    </tr>
  </table>
</body>
</html>

The image remains centered if the description becomes taller. The scope attribute is shown because a header cell can improve table navigation for assistive-technology users; use a normal <td> when the image is data rather than a row or column heading.

Why the rule belongs on the cell

An image participates in the inline formatting context by default. The table cell is the containing table-cell box, so its text-align property governs the horizontal alignment of that inline content. This is why putting text-align: center on the <img> itself often does not center it: the image is not a block that fills the cell.

vertical-align is context-sensitive. On a table cell it aligns the cell’s contents relative to the row. On an inline or inline-block image it aligns the image within its line box, which is useful for lining an icon up with text but is not a substitute for vertically centering content in a tall table cell.

Common approaches that fail or cause surprises

Applying text-align to the image

This usually has no useful effect:

<img class="wrong" src="image.jpg" alt="Description">
.wrong {
  text-align: center;
}

Move the declaration to the parent cell. If you intentionally make the image a block, you can center it with auto margins, but that is a different layout:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.image-cell img {
  display: block;
  margin-inline: auto;
}

For ordinary inline images, cell-level text-align is simpler and directly expresses the layout relationship.

Using the deprecated align attribute

Older examples often show <td align="center">. The align attribute on <td> is deprecated. Use CSS instead so presentation remains separate from structure and can be changed centrally.

Expecting vertical centering without extra height

There is no visible space to distribute when the row is exactly the image’s height. Test with a deliberately tall neighboring cell, padding, or a fixed/minimum row height before deciding that the rule is not working.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Forgetting whitespace and image dimensions

Inline images can leave a small descender gap because they align on a text baseline. If that gap matters, set display: block and use margin-inline: auto, or control the line-height of the cell. Also provide intrinsic width and height attributes when known to reduce layout movement while the image loads:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<img src="image.jpg" width="320" height="200" alt="Description">

Images spanning multiple columns or rows

The same cell rule applies when a cell spans columns or rows:

<td colspan="2" rowspan="2" class="image-cell">
  <img src="map.png" alt="Campus map">
</td>
.image-cell {
  text-align: center;
  vertical-align: middle;
}

colspan and rowspan change the cell’s geometry; they do not change how its inline contents are aligned.

Debugging checklist

  • Inspect the actual <td> containing the image and confirm that text-align: center is not overridden by a more specific rule.
  • Check that the image is inside the intended cell, not in a neighboring cell or outside the table row.
  • Temporarily add a background color and a minimum height to the cell so its boundaries are visible.
  • For vertical alignment, verify that the row is taller than the image; otherwise every value can look identical.
  • Look for a global rule such as td { text-align: left; } loaded after your component stylesheet.
  • Check image dimensions, intrinsic whitespace in the file, and transparent padding; CSS cannot remove empty pixels baked into the bitmap.
  • On narrow screens, confirm that responsive rules are not changing the cell to display: block or altering the table layout.

Browser HTML versus email HTML

The CSS pattern above is intended for normal browser-rendered HTML. HTML email clients can apply their own rendering rules, so do not assume that browser behavior guarantees identical results in every mail application. If the table is for email, test the exact clients and email framework you support, and keep the alignment declaration on the cell in the version you deliver.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Capturing a rendered result without browser setup

Or skip the browser setup

If you need a screenshot of the finished page rather than a local visual check, ScreenshotNeo can render a URL with one request. It accepts cookie or consent banners before capture and removes more than 60 known consent platforms, newsletter popups and chat widgets. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers. Its MCP server also provides take_screenshot, get_page_info and capture_pdf tools for Claude, Cursor and other MCP clients.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

See the ScreenshotNeo API documentation for authentication and options. This call captures a rendered page as WebP:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
const body = Buffer.from(await res.arrayBuffer());

ScreenshotNeo includes full-page capture, lazy-image loading, element capture by CSS selector, custom CSS and JavaScript, viewport and device presets, retina scale, PDF output, waits, request blocking, cookies, headers, geolocation, caching, signed links, asynchronous jobs and bulk capture. Every feature is on every plan. The Free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

Performance and maintainability notes

  • Prefer a reusable class when many cells share alignment; it reduces duplicated markup and makes later design changes safer.
  • Set image dimensions or CSS aspect constraints when layout stability matters, especially for large tables.
  • Use max-width: 100% for responsive images, but remember that a very wide table can still overflow its container.
  • Use border-collapse: collapse only when you want adjacent borders merged; it does not control image alignment.
  • Do not use JavaScript to center a static table image. CSS performs the layout during normal rendering and is easier to debug.

Frequently Asked Questions

Can I center an image in a table header cell?

Yes. Apply the same text-align: center and, when needed, vertical-align: middle declarations to the <th>. Preserve the header semantics only when that cell is actually a row or column heading.

What if the image is still not centered after adding the CSS?

Inspect the cell’s computed styles, add a temporary background to reveal its bounds, and check for overridden rules, transparent padding inside the image, or responsive CSS that changes the table or cell display.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Should I use a table for general page layout?

Use tables for genuinely tabular data. For general page composition, modern CSS layout tools such as flexbox or grid are usually more appropriate; this technique addresses alignment inside an existing HTML table.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.