Course contentsShow
← Web Development
Lesson 178 of 2,9823. CSS FundamentalsFree lesson

Vertical Alignment of Inline Text

Control vertical positioning of inline and inline-block elements with vertical-align.

Vertical Alignment of Inline Text

What you'll learn: How to control the vertical positioning of inline and inline-block elements using the vertical-align property.

The Core Idea

When you have inline elements (like <span>, <img>, or <a>) sitting next to each other on the same line, they don't always line up the way you'd expect. The vertical-align property lets you control how these elements align vertically relative to their surrounding text line.

Think of it like arranging items on a shelf: by default, everything sits on the "baseline" (imagine the bottom line of handwritten text). But sometimes you want to shift things up, down, or align them differently.

How It Works

The vertical-align property only affects inline and inline-block elements—it has no effect on block-level elements.

Common values include:

  • baseline (default) – aligns with the parent's baseline
  • top – aligns with the top of the line
  • middle – centers vertically within the line
  • bottom – aligns with the bottom of the line
  • text-top – aligns with the top of the parent's font
  • text-bottom – aligns with the bottom of the parent's font
  • sub – lowers text for subscript
  • super – raises text for superscript
  • Length values like 5px or -3px for precise adjustments
img {
  vertical-align: middle; /* centers image with text line */
}

.superscript {
  vertical-align: super; /* raises text */
  font-size: 0.8em;
}

Key Takeaway: Use vertical-align to control how inline and inline-block elements position themselves vertically within their text line—it's essential for aligning images with text or creating subscripts and superscripts.