CSS vertical-align Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Typography

What You’ll Learn

The vertical-align property controls how inline elements sit next to text — perfect for icons, badges, subscripts, and table cells.

01

Inline align

Icons beside text.

02

Syntax

Keywords and lengths.

03

baseline

Default value.

04

middle

Center with text.

05

Tables

Cell alignment.

06

Limits

Not for block boxes.

Introduction

The vertical-align property in CSS controls how inline elements are aligned vertically relative to their parent element or to the line box.

This property is particularly useful for aligning text and other inline elements within a line of text or within a table cell.

Definition and Usage

Apply vertical-align to inline-level elements (such as span, img, and input), inline-block elements, or table cells (td, th). It adjusts position along the vertical axis within a line or cell — not the whole block on the page.

💡
Beginner Tip

vertical-align does not center a block-level div inside its parent. For that, use flexbox (align-items: center) or grid. Use vertical-align when something sits inline next to text or inside a table cell.

📝 Syntax

The syntax for the vertical-align property is straightforward. It can be applied to inline or table-cell elements, and you can specify various alignment values.

syntax.css
element {
  vertical-align: baseline | sub | super | text-top | text-bottom | middle | top | bottom | <length> | <percentage>;
}

Basic Example

vertical-align.css
.inline-img {
  vertical-align: middle;
}

Syntax Rules

  • Works on inline, inline-block, and table-cell elements.
  • One keyword, length, or percentage value at a time.
  • Length and percentage values shift the element relative to the baseline.
  • For table cells, top, middle, and bottom refer to the cell box.
  • The property is not inherited.

Related Properties

  • line-height — controls line box height around inline content
  • text-align — horizontal alignment (often paired in tables)
  • display — change to inline-block or table-cell when needed
  • align-items — flexbox alternative for block-level vertical centering

🎯 Default Value

The default value of vertical-align is baseline, which aligns the baseline of the element with the baseline of its parent.

⚡ Quick Reference

QuestionAnswer
Default valuebaseline
Icon beside textvertical-align: middle;
Subscript / superscriptvertical-align: sub; or super;
Table cell centervertical-align: middle; on td
Applies toInline, inline-block, table-cell
InheritedNo

💎 Property Values

The vertical-align property accepts keyword values, lengths, and percentages.

ValueExampleDescription
baselinevertical-align: baseline;Aligns the baseline of the element with the baseline of its parent.
topvertical-align: top;Aligns the top of the element with the tallest element on the line (or top of the cell in tables).
middlevertical-align: middle;Aligns the middle of the element with the middle of the parent element’s font (or center of the cell in tables).
bottomvertical-align: bottom;Aligns the bottom of the element with the lowest element on the line (or bottom of the cell in tables).
subvertical-align: sub;Aligns the element as subscript relative to the baseline.
supervertical-align: super;Aligns the element as superscript relative to the baseline.
text-topvertical-align: text-top;Aligns the top of the element with the top of the parent element’s font.
text-bottomvertical-align: text-bottom;Aligns the bottom of the element with the bottom of the parent element’s font.
<length>vertical-align: 4px;Raises or lowers the element by a fixed distance from the baseline.
<percentage>vertical-align: 10%;Raises or lowers the element as a percentage of the line-height.
baseline middle top bottom sub super text-top text-bottom

When to Use vertical-align

vertical-align is helpful whenever inline content needs fine vertical tuning:

  • Icons beside labels — Align small images or SVGs with button or link text.
  • Subscripts and superscripts — Format formulas (H2O) or footnote markers without semantic tags.
  • Inline badges — Position status chips next to headings or sentences.
  • Table cells — Vertically center or pin content to the top or bottom of a cell.
  • Form controls — Nudge checkboxes or inputs to line up with adjacent text.

👀 Live Preview

Same icon beside text with default baseline vs vertical-align: middle:

Product updates weekly
baseline (default)
Product updates weekly
vertical-align: middle

Examples Gallery

In this example, we’ll use the vertical-align property to align text and images vertically within a line of text.

📜 Core Patterns

Align inline images, badges, and text on the same line.

Example 1 — Vertical align text and image

In this example, we’ll use the vertical-align property to align text and images vertically within a line of text.

index.html
<style>
  .inline-img {
    vertical-align: middle;
  }
</style>

<p>
  <img src="image.png" alt="Example Image" class="inline-img">
  Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
Try It Yourself

How It Works

middle centers the image with the middle of the lowercase letters in the line, which usually looks balanced beside body text.

Example 2 — Subscript and superscript

Use sub and super for formulas and footnote markers without extra markup tags.

sub-super.css
.sub { vertical-align: sub; font-size: 0.75em; }
.super { vertical-align: super; font-size: 0.75em; }
Try It Yourself

How It Works

sub and super shift characters relative to the baseline. Smaller font-size keeps them visually proportional.

📄 Layout Patterns

Compare alignment keywords and use vertical-align in tables.

Example 3 — Compare baseline, middle, and top

See how different keywords change the position of an inline badge beside larger text.

compare.css
.baseline { vertical-align: baseline; }
.middle { vertical-align: middle; }
.top { vertical-align: top; }
Try It Yourself

How It Works

Each keyword uses a different reference point: the text baseline, the font middle, or the top of the line box.

Example 4 — Table cell vertical alignment

Inside table cells, vertical-align positions content relative to the cell height — the modern replacement for the obsolete HTML valign attribute.

table.css
.cell-top { vertical-align: top; }
.cell-middle { vertical-align: middle; }
.cell-bottom { vertical-align: bottom; }
Try It Yourself

How It Works

On table cells, keywords refer to the cell box rather than the text line, giving predictable top, center, and bottom placement.

♿ Accessibility

  • Prefer semantic tags — Use <sub> and <sup> for meaningful subscripts and superscripts when appropriate.
  • Keep readable line height — Extreme vertical-align offsets can make text harder to read for low-vision users.
  • Alt text on inline images — Decorative icons should use empty alt (alt=""); meaningful icons need descriptive alt text.
  • Do not rely on alignment alone — Ensure meaning is clear from text content, not just visual position.

vertical-align + display

If an element is block-level by default, change its display before vertical-align can take effect inline. For whole-component centering, flexbox is usually the better tool.

inline-block.css
.badge {
  display: inline-block;
  vertical-align: middle;
  padding: 0.2rem 0.5rem;
}

🧠 How vertical-align Works

1

Inline content shares a line box

Text, images, and badges flow on the same line.

Context
2

vertical-align picks a reference

Keywords like baseline, middle, or top define the alignment point.

Rule
3

Browser shifts the element

The inline box moves up or down relative to siblings in the line.

Render
=

Balanced inline layout

Icons, text, and badges sit neatly on one line.

Browser Compatibility

The vertical-align property is well-supported across all major browsers, including Chrome, Firefox, Safari, Edge, and Opera. It behaves consistently across different platforms.

Modern browsers · Widely supported

Inline and table alignment

All major browsers support vertical-align for inline content and table cells.

99% Browser support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions
Full support
Opera All versions
Full support

Testing tip

Test icon + text pairs at different font sizes and zoom levels to confirm alignment still looks correct.

vertical-align property 99% supported

Bottom line: vertical-align is a reliable choice for inline and table-cell alignment on the modern web.

Conclusion

The vertical-align property is a versatile tool for aligning inline elements vertically within their container.

Whether you’re aligning text alongside images, adjusting the positioning of subscripts or superscripts, or fine-tuning the vertical alignment of table cells, understanding and using vertical-align can significantly enhance the layout and presentation of your web content.

💡 Best Practices

✅ Do

  • Use middle for icons beside body text
  • Use vertical-align on table cells instead of HTML valign
  • Combine with display: inline-block for badges and chips
  • Prefer <sub> and <sup> for semantic formulas when possible
  • Test at multiple font sizes and zoom levels

❌ Don’t

  • Expect vertical-align to center block-level containers
  • Overuse pixel offsets when a keyword value works
  • Forget that table and inline contexts interpret some keywords differently
  • Sacrifice readability for tiny vertical tweaks

Key Takeaways

Knowledge Unlocked

Five things to remember about vertical-align

Use these points when aligning inline content.

5
Core concepts
🕐 02

baseline

Default value.

Default
🔀 03

middle

Icons + text.

Pattern
🔒 04

Tables

Cell alignment.

Layout
🌐 05

99% support

All browsers.

Compat

❓ Frequently Asked Questions

vertical-align controls how inline-level and table-cell elements are positioned vertically relative to their line box or table cell.
The default value is baseline, which aligns the element's baseline with the parent line's baseline.
vertical-align applies to inline-level and table-cell elements. Block elements like div do not respond to it unless you change display to inline-block or table-cell.
middle aligns with the middle of the parent font. text-bottom aligns with the bottom of the parent font, not the bottom of the line box.
No, vertical-align is not inherited. You must set it on each element that needs a different alignment.

Practice in the Live Editor

Open the HTML editor and test vertical-align with icons, badges, and table cells.

HTML Editor →

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