CSS alignment-baseline Property

The alignment-baseline property specifies which baseline of an element is used when aligning it with other content.

It is primarily used with SVG text and inline-level elements. Different baseline values help position text and graphics relative to a shared alignment reference, especially when working with different fonts, writing systems, or text sizes.

alignment-baseline Syntax

selector {
  alignment-baseline: baseline;
}

Replace baseline with a supported value such as alphabetic, ideographic, middle, central, or mathematical.

The property also accepts the global CSS values inherit, initial, revert, revert-layer, and unset.

Property Values

Value Description
baseline Uses the dominant baseline of the parent element. This is the initial value.
text-bottom Aligns the element using the bottom of the font's text content area.
alphabetic Uses the alphabetic baseline, commonly associated with Latin text.
ideographic Uses the ideographic baseline, which is relevant to certain East Asian writing systems.
hanging Uses the hanging baseline, commonly associated with certain scripts whose characters hang below a top alignment reference.
middle Aligns the element using a baseline positioned near the middle of the text, based on the font's x-height.
central Uses the central baseline, located between the text's over and under edges.
mathematical Uses the mathematical baseline, intended for aligning mathematical expressions and symbols.
text-top Aligns the element using the top of the font's text content area.

The property is not inherited. Its initial value is baseline, which uses the parent's dominant baseline as the alignment reference.

Older SVG implementations also recognize legacy values such as before-edge, after-edge, text-before-edge, and text-after-edge. These values are deprecated and should be avoided in new code.

How alignment-baseline Works

Text is positioned using invisible reference lines called baselines. Different writing systems and fonts can use different baselines to determine how characters and other inline content line up.

The alignment-baseline property selects which baseline of an element should align with the corresponding reference baseline of its parent.

svg text {
  alignment-baseline: middle;
}

This rule requests middle-baseline alignment for SVG text elements. The exact position depends on the font metrics and the baseline information used by the browser.

Unlike properties that move an element by a fixed distance, alignment-baseline works with font and layout metrics. Its visual effect may therefore vary between fonts and writing systems.

SVG Text Alignment

SVG provides a useful environment for demonstrating baseline alignment because text elements can share the same reference coordinates while using different baseline values.

<svg viewBox="0 0 360 140" xmlns="http://www.w3.org/2000/svg">
  <line x1="20" y1="70" x2="340" y2="70"
        stroke="#999" stroke-dasharray="4 4" />
  <text x="30" y="70" class="alphabetic-text">Alphabetic</text>
  <text x="190" y="70" class="middle-text">Middle</text>
</svg>
.alphabetic-text {
  alignment-baseline: alphabetic;
  font-size: 22px;
  fill: #1769aa;
}
.middle-text {
  alignment-baseline: middle;
  font-size: 22px;
  fill: #198754;
}

Both text elements use the same y coordinate, but their baseline settings produce different vertical positions relative to the dashed reference line.

The fill property controls the SVG text color, while alignment-baseline determines the alignment reference.

Inline-Level Alignment

The alignment-baseline property is also defined for inline-level elements, including inline text and inline-block content.

.inline-label {
  alignment-baseline: alphabetic;
}
.inline-icon {
  display: inline-block;
  alignment-baseline: middle;
}

In theory, these values select different baselines for aligning the elements within a line of text. However, browser support for alignment-baseline in HTML inline layout is less consistent than its SVG support.

For ordinary HTML inline elements, the vertical-align property is generally a more established choice when adjusting alignment relative to surrounding text.

alignment-baseline Example

The following example compares three SVG text elements using the same vertical coordinate but different baseline values.

<svg viewBox="0 0 480 160" xmlns="http://www.w3.org/2000/svg">
  <line x1="15" y1="80" x2="465" y2="80"
        stroke="#999" stroke-dasharray="5 5" />
  <text x="20" y="80" class="baseline-demo">Baseline</text>
  <text x="175" y="80" class="middle-demo">Middle</text>
  <text x="315" y="80" class="hanging-demo">Hanging</text>
</svg>
.baseline-demo {
  alignment-baseline: baseline;
  font-size: 24px;
  fill: #1769aa;
}
.middle-demo {
  alignment-baseline: middle;
  font-size: 24px;
  fill: #198754;
}
.hanging-demo {
  alignment-baseline: hanging;
  font-size: 24px;
  fill: #7952b3;
}

The dashed line marks the shared y coordinate. Each text element is positioned according to its selected baseline, allowing you to compare the resulting vertical alignment.

Browser Result
Baseline Middle Hanging

The baseline value uses the parent's dominant baseline, middle aligns using the font's middle reference, and hanging uses the hanging baseline. The exact offsets depend on the font and browser.

alignment-baseline vs. dominant-baseline

Both properties are used in baseline alignment, but they serve different purposes.

Property Purpose
alignment-baseline Selects the baseline of an element used to align it with its parent.
dominant-baseline Establishes the dominant baseline used by an element and its text content.

Use alignment-baseline when choosing which baseline of an element participates in alignment. Use dominant-baseline when establishing the baseline reference for text layout.

The two properties can interact, so changing the dominant baseline may affect how other baseline alignment values are interpreted.

Browser Support

The alignment-baseline property has limited availability across browsers and layout contexts. Support is more established for SVG text than for ordinary HTML inline elements, and individual values may behave differently between browsers.

Visit Can I Use? to check current compatibility. Test the specific values and layout contexts required by your project.

Specifications

The alignment-baseline property is defined in the CSS Inline Layout Module Level 3 specification.

CSS Inline Layout Module Level 3