Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

vertical-align — alignment within lines and table cells

The vertical-align property controls an inline-level element’s alignment relative to a baseline or line box. It also has a separate meaning for table cells. It is not a general way to center content inside an arbitrary block.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD. The verified example uses an established length value and does not test the CSS Inline Layout Level 3 draft shorthand.

Syntax

vertical-align: baseline | sub | super | text-top | text-bottom | middle | top | bottom | <length-percentage>;
/* CSS Inline Layout Level 3 draft: */
vertical-align: [ first | last ] || <'alignment-baseline'> || <'baseline-shift'>;

vertical-align sets an inline-level element’s alignment, including inline-block, along the line’s block axis. Its initial value is baseline; it is not inherited. In ordinary horizontal text, this alignment is vertical. Apply it to the element being aligned, not its container.

baseline matches baselines. middle aligns the element’s midpoint with the parent’s baseline plus half its font’s x-height—not with the container’s center. text-top and text-bottom refer to the parent’s text area, whereas top and bottom refer to the line box edges. sub and super shift to subscript or superscript positions without changing font size.

A positive length raises the element; a negative length lowers it. Percentages use the element’s own line-height: with line-height: 40px, 25% raises it by 10px. A shifted element can increase the height of the whole line.

For table cells, top, middle, and bottom position content within the available cell height; baseline aligns the baselines of cells in a row. Do not treat vertical-align as a general tool for centering an ordinary block’s contents.

The CSS Inline Layout Level 3 draft defines this property as a shorthand for alignment-baseline, baseline-source, and baseline-shift. The second syntax line describes that draft, not verified browser support. The example uses a basic length value and does not test the draft syntax.

Examples

<!doctype html>
<meta charset="utf-8">
<title>vertical-align</title>
<style>
  p { font: 20px/40px monospace; }
  .box {
    display: inline-block;
    width: 20px;
    height: 20px;
    background: navy;
    vertical-align: baseline;
  }
  .raised { vertical-align: 10px; }
</style>
<p>A <span class="box"></span> <span class="box raised"></span> A</p>

Result

The second navy square is 10 CSS pixels higher than the first.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources