Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

baseline-shift — post-alignment displacement

baseline-shift moves content after baseline alignment or relative to its line box. The example demonstrates shifted SVG text.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

baseline-shift: <length-percentage> | sub | super | top | center | bottom;

baseline-shift applies to inline-level boxes and SVG text content elements. Its initial value is 0; it is not inherited. It does not select the alignment baseline — alignment-baseline does.

Positive lengths raise; negative lengths lower. Percentages use the used line-height. sub and super shift to index positions without shrinking the font. top, center, bottom align the subtree relative to the line box, not a baseline.

The specification recommends vertical-align outside SVG. Draft syntax does not guarantee browser support. Legacy baseline may be supported in SVG as equivalent to 0, but it is outside the core grammar of baseline-shift. The vertical-align shorthand accepts baseline through its alignment-baseline component, not through baseline-shift.

Examples

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Baseline shift on SVG text</title>
  <style>
    .raised { baseline-shift: 12px; }
  </style>
</head>
<body>
  <h1>Baseline shift on SVG text</h1>
  <svg width="280" height="100" viewBox="0 0 280 100" role="img" aria-labelledby="sample-title">
    <title id="sample-title">Two ABC samples with a shared reference line and a baseline shift on the second sample</title>
    <path d="M10 60H270" stroke="gray" />
    <g font-family="sans-serif" font-size="24">
      <text x="20" y="60"><tspan>ABC</tspan></text>
      <text x="150" y="60"><tspan id="raised" class="raised">ABC</tspan></text>
    </g>
  </svg>
  <script>
    if (CSS.supports('baseline-shift', '12px')) {
      const shift = getComputedStyle(document.getElementById('raised')).getPropertyValue('baseline-shift');
      console.log('baseline-shift supported; computed on tspan: ' + shift);
    } else {
      console.log('baseline-shift unsupported');
    }
  </script>
</body>
</html>

Result

baseline-shift supported; computed on tspan: 12px

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