CSS vertical-align Property

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

Definition and Usage

The vertical-align property sets the vertical alignment of an inline, inline-block, or table-cell box. Use it to sit an icon next to text, or to place content inside a table cell.

It does not align ordinary block boxes (such as a plain div). For flex or grid, prefer align-items. The initial value is baseline. It is not inherited.

Baseline · Widely available.

Not deprecated. Supported everywhere modern browsers run. Do not use it to vertically center a block page section — use flex or grid instead.

CSS Syntax

syntax.css
vertical-align: baseline | middle | top | bottom | <length> | <percentage>;

Also: sub, super, text-top, text-bottom. Example: vertical-align: middle;

Property Values

ValueDescriptionTry it
baselineAlign baselines (initial value)Try it
middleAlign middle with parent baseline + half x-heightTry it
top / bottomAlign to the top or bottom of the line (or table row)Try it
sub / superSubscript or superscript baselineTry it
Length / %Raise or lower from the baseline (% of line-height)Try it

How to Use vertical-align

Apply it to an inline-level or table-cell element, then pick a keyword that matches the look you want.

  1. Confirm the element is inline, inline-block, or a table cell (display).
  2. Set vertical-align on that element (not on a wrapping block alone).
  3. For icons beside text, start with middle.
  4. For table cells, use top, middle, or bottom on the cell.
PieceRequired?Role
Inline / table-cell boxYesBlock boxes ignore this property
Keyword or offsetYesbaseline, middle, top, length, etc.
Line of text or table rowUsuallyGives something to align against

Live Preview

The blue box is inline-block. Change vertical-align and watch it move relative to the text.

Works here because the box is inline-block inside a line of text.

Line

Text box more text

vertical-align: middle

CSS Examples

Each snippet focuses on vertical-align. Extra styles stay minimal for study. Use Try It Yourself for a live editor.

Example 1 — Align an Inline Box with Text

Sit a small box on the middle of the text line.

CSS
<style>
  span {
    display: inline-block;
    width: 24px;
    height: 24px;
    background: #2563eb;
    vertical-align: middle;
  }
</style>

<p>Label <span></span> text</p>
Try It Yourself

How It Works

  1. Make it inline-level. display: inline-block lets vertical-align apply.
  2. Set middle. The box centers against the parent text metrics.
  3. Keep it in the line. The span sits inside the paragraph with the words.
  4. Common pattern. Same idea for icons and small images beside labels.

Example 2 — Default Baseline

Compare the default baseline alignment with taller inline content.

CSS
<style>
  span {
    display: inline-block;
    width: 24px;
    height: 40px;
    background: #2563eb;
    vertical-align: baseline;
  }
</style>

<p>Label <span></span> text</p>
Try It Yourself

How It Works

  1. Baseline is the default. The box lines up on the text baseline.
  2. Tall boxes stick up. Extra height grows above the baseline.
  3. Try middle next. Switch to middle in Try It Yourself for a cleaner icon look.
  4. Images vary. Some replaced elements treat baseline differently across browsers.

Example 3 — Table Cell Alignment

Center content vertically inside a table cell.

CSS
<style>
  td {
    height: 80px;
    vertical-align: middle;
    border: 1px solid #ccc;
  }
</style>

<table>
  <tr>
    <td>Centered</td>
  </tr>
</table>
Try It Yourself

How It Works

  1. Cells accept it. td / th are table-cell boxes.
  2. Give the cell height. Extra vertical space makes middle visible.
  3. middle centers. Content sits in the vertical middle of the row.
  4. Also try top/bottom. Those pin content to the row edges.

Edge Cases & Pitfalls

If nothing moves, one of these is usually why.

block

Ignored on block boxes

A normal div will not respond. Use inline-block/table-cell, or flex/grid align-items.

flex

Not for flex/grid centering

Vertical centering of flex items is align-items / align-self, not vertical-align.

%

Percentages use line-height

A percentage is relative to the element’s line-height, not the parent height.

img

Images and baseline

Default image alignment is often baseline, which can leave a gap under the image. Try middle or bottom.

inherit

Not inherited

Children do not pick up a parent’s vertical-align unless you set inherit.

Browser Support

vertical-align is a browser CSS property for inline and table-cell layout. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

vertical-align

Supported in all major browsers for many years (Chrome 1+, Firefox 1+, Safari 1+, Edge 12+, IE 4+).

97% Global support
Google Chrome 1+
Full support
Mozilla Firefox 1+
Full support
Apple Safari 1+
Full support
Microsoft Edge 12+
Full support
Opera 4+
Full support
Samsung Internet 1+
Full support
Internet Explorer 4+
Full support
vertical-align Widely supported

Bottom line: Safe everywhere for inline and table-cell use. Remember it is not a flex/grid centering tool. This is not a JavaScript runtime API.

Key Takeaways

  • Role: align inline / inline-block / table-cell boxes vertically.
  • Initial: baseline. middle is the usual pick for icons beside text.
  • Not for blocks. Use flex/grid align-items to center block layout.
  • Table cells: top, middle, and bottom align within the row.

One line: vertical-align is for inline and table-cell alignment — not for centering block pages.

Frequently Asked Questions

It sets the vertical alignment of an inline, inline-block, or table-cell box. For inline content it aligns inside the line box. For table cells it aligns the cell’s content within the row.
The initial value is baseline, which lines up the element’s baseline with the parent’s baseline.
It does not apply to block-level boxes. Change display to inline-block or table-cell, or use flex/grid with align-items for block layout.
No. Set it on each inline or table-cell element that needs a different alignment.
middle is a common choice to sit an icon or image beside text so their middles line up with the parent’s x-height.
It is Baseline Widely available and supported in all major browsers, including Internet Explorer. It is a browser CSS property, not a Node.js feature.

Next: visibility

Show or hide an element while keeping or dropping its layout space.

visibility 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