HTML valign Attribute

Beginner
⏱️ 5 min read
📚 Updated: Jun 2026
🎯 3 Examples
Tables & Layout

Introduction

The valign attribute specifies the vertical alignment of content within a table cell. It lets you pin text or other elements to the top, middle, or bottom of a <td> or <th> when the cell is taller than its content.

Although valign is obsolete in HTML5, you will still encounter it in legacy markup. Modern projects should use the CSS vertical-align property instead. Learning both helps you read old code and write new code correctly.

What You’ll Learn

01

top / middle

Common values.

02

bottom

Foot of cell.

03

baseline

Text baseline.

04

td & th

Cell targets.

05

CSS replace

vertical-align.

06

Legacy code

Still in wild.

Purpose of valign

The valign attribute provides a way to vertically align content inside table cells. This is useful when rows have extra height (from padding, images, or neighboring cells) and you need text positioned at the top, center, or bottom of the cell area.

In early HTML, presentation attributes like valign were the primary way to style tables. HTML5 moved presentation to CSS for separation of structure and style.

💡
Obsolete but still recognized

Browsers continue to support valign for compatibility. For new pages, use vertical-align in CSS rather than HTML presentation attributes.

📝 Syntax

Add valign with a keyword on a table cell or column element:

index.html
<table>
  <tr>
    <td valign="top">Top aligned text</td>
    <td valign="middle">Middle aligned text</td>
    <td valign="bottom">Bottom aligned text</td>
  </tr>
</table>

Syntax Rules

  • Valid on <td>, <th>, <tr>, <col>, and <colgroup>.
  • Values: top, middle, bottom, baseline.
  • Default when omitted: middle for cells.
  • Effect is most visible when the cell has extra vertical space.
  • CSS equivalent: vertical-align: top | middle | bottom | baseline on the cell.
  • Do not use border on tables for layout in new code; use CSS borders instead.

💎 Values

The valign attribute accepts these keywords:

  • top — Aligns content to the top of the cell.
  • middle — Centers content vertically (default).
  • bottom — Aligns content to the bottom of the cell.
  • baseline — Aligns content to the text baseline of the row.
valign-values.html
<td valign="top">Top</td>
<td valign="middle">Middle</td>
<td valign="bottom">Bottom</td>
<td valign="baseline">Baseline</td>

⚡ Quick Reference

valign valueEffectCSS equivalent
topContent at top of cellvertical-align: top
middle (default)Content centered verticallyvertical-align: middle
bottomContent at bottom of cellvertical-align: bottom
baselineAlign to text baselinevertical-align: baseline
StatusObsolete in HTML5Prefer CSS for new work
JavaScriptcell.setAttribute("valign","bottom")cell.style.verticalAlign = "bottom"

Applicable Elements

ElementSupported?Typical use
<td>YesData cell vertical alignment
<th>YesHeader cell vertical alignment
<tr>YesDefault for all cells in the row
<col>, <colgroup>YesColumn-wide default alignment
<div>, <p>NoUse CSS vertical-align or flexbox/grid

valign vs CSS vertical-align vs flexbox

MethodWhere it worksRecommendation
valign attributeTable cells (legacy HTML)Read/maintain old code only
vertical-align CSStd, th, inline/table-cell elementsPreferred for tables today
Flexbox (align-items)Non-table layoutsModern page layout
align attributeHorizontal alignment (also obsolete)Use CSS text-align instead

Examples Gallery

Compare top, middle, and bottom alignment, change valign with JavaScript, and see the modern CSS equivalent.

👀 Live Preview

Three cells in one tall row with different vertical alignment:

TopMiddleBottom

Implementation Example

A simple table demonstrating three valign values:

index.html
<table>
  <tr>
    <td valign="top">Top aligned text</td>
    <td valign="middle">Middle aligned text</td>
    <td valign="bottom">Bottom aligned text</td>
  </tr>
</table>

How It Works

Each <td> sets a different valign keyword. When cells are taller than one line of text, content shifts to the top, center, or bottom of the cell box.

Dynamic Values with JavaScript

Update alignment at runtime for dynamically generated tables:

dynamic-valign.html
<td id="dynamicCell">Adjustable alignment</td>

<script>
  document.getElementById("dynamicCell").setAttribute("valign", "bottom");
</script>

How It Works

The script sets valign="bottom" on the cell with id dynamicCell. For new code, setting style.verticalAlign is usually clearer and aligns with CSS best practices.

Example — modern CSS replacement

The recommended approach for new projects:

css-vertical-align.html
<style>
  .cell-top { vertical-align: top; }
  .cell-middle { vertical-align: middle; }
  .cell-bottom { vertical-align: bottom; }
</style>

<td class="cell-top">Top (CSS)</td>
<td class="cell-middle">Middle (CSS)</td>
<td class="cell-bottom">Bottom (CSS)</td>

How It Works

CSS vertical-align on table cells produces the same visual result as valign but follows modern separation of content and presentation.

♿ Accessibility

  • Use semantic tables<th> for headers, scope where helpful; alignment does not replace structure.
  • Do not rely on alignment alone — Screen readers do not announce valign; meaning must come from content and headings.
  • Keep readable line length — Vertical alignment affects layout, not whether text is understandable.
  • Prefer CSS for maintainability — Centralized styles are easier to audit for contrast and spacing.
  • Test with zoom and reflow — Ensure table content remains usable when users enlarge text.

🧠 How valign Works

1

Cell gets height

Row or CSS size.

Layout
2

valign keyword set

top, middle, etc.

HTML
3

Browser positions content

Inside cell box.

Render
=

Aligned table cell

Visual layout.

Browser Support

Browsers still honor valign on table elements for backward compatibility. It remains widely supported in practice, but HTML5 marks it obsolete — new code should use CSS instead.

Supported · Legacy attribute

Works in all browsers, deprecated in spec

Safe to interpret in old HTML; avoid in new markup in favor of vertical-align.

100% Browser support
Google Chrome Supported
Supported
Mozilla Firefox Supported
Supported
Apple Safari Supported
Supported
Microsoft Edge Supported
Supported
valign attribute Legacy / supported

Bottom line: Browsers support it, but HTML5 recommends CSS vertical-align for new development.

💡 Best Practices

✅ Do

  • Use CSS vertical-align in new projects
  • Recognize valign when reading legacy HTML
  • Give cells enough height to see alignment differences
  • Combine with proper table semantics (th, captions)
  • Migrate presentation attributes to stylesheets gradually

❌ Don’t

  • Add valign to new production markup
  • Mix many inline presentation attributes (width, bgcolor, etc.)
  • Use tables purely for page layout
  • Assume valign affects non-table elements
  • Claim it “does not work” — it does, but is obsolete
  • While valign can help with quick legacy adjustments, HTML5 and CSS practices recommend vertical-align for better control and maintainability.
  • When maintaining older code, valign may still appear; migrate to CSS when you refactor.

🎉 Conclusion

The valign attribute provides a straightforward way to control vertical alignment within table cells. While obsolete in modern HTML, understanding it helps when working with older codebases and table-based layouts.

For current projects, use CSS vertical-align on table cells to follow modern web standards and keep styling in stylesheets.

Key Takeaways

Knowledge Unlocked

4 truths every developer should know about valign

Bookmark these before your next valign implementation.

4
Core concepts
📝 02

Values: top, middle (default),

Values: top, middle (default), bottom, baseline.

Syntax
⚙️ 03

The attribute is obsolete

The attribute is obsolete in HTML5 but still works in browsers.

Usage
🔒 04

Use CSS vertical-align instead

Use CSS vertical-align instead when writing new HTML.

Dynamic

❓ Frequently Asked Questions

Yes. HTML5 lists valign as obsolete. Browsers still support it for compatibility, but you should use CSS for new pages.
vertical-align: top; on the td or th element (via class or inline style).
No. valign is for table-related elements. For <div>, use flexbox, grid, or other CSS layout techniques.
If the cell is only as tall as its content, all alignments look the same. Add row height or padding to make the effect visible.
Yes, with setAttribute("valign", "bottom"). Prefer element.style.verticalAlign in modern code.

Compare vertical alignment

Try top, middle, and bottom in tall table cells, then see the CSS version.

Try the table example →

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.

5 people found this page helpful