👀 Live Preview
Three cells in one tall row with different vertical alignment:
| Top | Middle | Bottom |

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.
Common values.
Foot of cell.
Text baseline.
Cell targets.
vertical-align.
Still in wild.
valignThe 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.
Browsers continue to support valign for compatibility. For new pages, use vertical-align in CSS rather than HTML presentation attributes.
Add valign with a keyword on a table cell or column element:
<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><td>, <th>, <tr>, <col>, and <colgroup>.top, middle, bottom, baseline.middle for cells.vertical-align: top | middle | bottom | baseline on the cell.border on tables for layout in new code; use CSS borders instead.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.<td valign="top">Top</td>
<td valign="middle">Middle</td>
<td valign="bottom">Bottom</td>
<td valign="baseline">Baseline</td>| valign value | Effect | CSS equivalent |
|---|---|---|
top | Content at top of cell | vertical-align: top |
middle (default) | Content centered vertically | vertical-align: middle |
bottom | Content at bottom of cell | vertical-align: bottom |
baseline | Align to text baseline | vertical-align: baseline |
| Status | Obsolete in HTML5 | Prefer CSS for new work |
| JavaScript | cell.setAttribute("valign","bottom") | cell.style.verticalAlign = "bottom" |
| Element | Supported? | Typical use |
|---|---|---|
<td> | Yes | Data cell vertical alignment |
<th> | Yes | Header cell vertical alignment |
<tr> | Yes | Default for all cells in the row |
<col>, <colgroup> | Yes | Column-wide default alignment |
<div>, <p> | No | Use CSS vertical-align or flexbox/grid |
valign vs CSS vertical-align vs flexbox| Method | Where it works | Recommendation |
|---|---|---|
valign attribute | Table cells (legacy HTML) | Read/maintain old code only |
vertical-align CSS | td, th, inline/table-cell elements | Preferred for tables today |
Flexbox (align-items) | Non-table layouts | Modern page layout |
align attribute | Horizontal alignment (also obsolete) | Use CSS text-align instead |
Compare top, middle, and bottom alignment, change valign with JavaScript, and see the modern CSS equivalent.
Three cells in one tall row with different vertical alignment:
| Top | Middle | Bottom |
A simple table demonstrating three valign values:
<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>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.
Update alignment at runtime for dynamically generated tables:
<td id="dynamicCell">Adjustable alignment</td>
<script>
document.getElementById("dynamicCell").setAttribute("valign", "bottom");
</script>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.
The recommended approach for new projects:
<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>CSS vertical-align on table cells produces the same visual result as valign but follows modern separation of content and presentation.
<th> for headers, scope where helpful; alignment does not replace structure.valign; meaning must come from content and headings.Row or CSS size.
top, middle, etc.
Inside cell box.
Visual layout.
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.
Safe to interpret in old HTML; avoid in new markup in favor of vertical-align.
Bottom line: Browsers support it, but HTML5 recommends CSS vertical-align for new development.
vertical-align in new projectsvalign when reading legacy HTMLth, captions)valign to new production markupwidth, bgcolor, etc.)valign can help with quick legacy adjustments, HTML5 and CSS practices recommend vertical-align for better control and maintainability.valign may still appear; migrate to CSS when you refactor.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.
valignBookmark these before your next valign implementation.
valign controls vertical alignment in table cells (td, th, etc.).
Values: top, middle (default), bottom, baseline.
The attribute is obsolete in HTML5 but still works in browsers.
UsageUse CSS vertical-align instead when writing new HTML.
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).valign is for table-related elements. For <div>, use flexbox, grid, or other CSS layout techniques.setAttribute("valign", "bottom"). Prefer element.style.verticalAlign in modern code.Try top, middle, and bottom in tall table cells, then see the CSS version.
5 people found this page helpful