Favorites

CSS baseline-shift Property

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
baseline-shift
CSS PropertyThis property is supported by all modern browsers.
Updated 22nd November 2026

Description

The baseline-shift property moves text up or down relative to the dominant baseline of its parent, for example to create superscripts and subscripts in SVG text. Positive values raise the text and negative values lower it. It applies to SVG text content such as <tspan> and <textPath>, and in CSS Inline Layout to inline boxes as well, where it is one of the longhands of vertical-align.

The keywords sub and super use the font's recommended subscript and superscript offsets. Percentages refer to the line-height of the element.

Definition

Initial value
0
Applies to
inline-level boxes and SVG text content elements
Inherited
no
Computed value
the specified keyword or an absolute length
Animatable
by computed value type
JavaScript syntax
object.style.baselineShift

Interactive Demo

E = mc2 and H2O
Demo Code
HTML Code
<svg class="demo-svg" viewBox="0 0 200 120" width="260" xmlns="http://www.w3.org/2000/svg">
<line x1="10" y1="70" x2="190" y2="70" stroke="#f72585" stroke-dasharray="4"/>
<text x="12" y="70" font-size="20" fill="#1b1f3b">E = mc<tspan class="demo-element" fill="#4361ee">2</tspan> and H<tspan class="demo-element" fill="#4361ee">2</tspan>O</text>
</svg>
CSS Code
.demo-element {
	baseline-shift: 0;
}

Syntax

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

Values

  • <length>Raises (positive) or lowers (negative) the element by the given length.
  • <percentage>Raises or lowers the element by a percentage of its line-height.
  • subLowers the baseline to the font's subscript position.
  • superRaises the baseline to the font's superscript position.
  • top, center, bottomAligns the element relative to the line box (CSS Inline Layout values, not supported for SVG text in all browsers).
  • initialSets the property to its initial value.
  • inheritTakes the computed value of the parent element.

Example

<svg viewBox="0 0 300 160">
<text x="20" y="70">E = mc<tspan class="sup">2</tspan></text>
<text x="20" y="130">H<tspan class="sub">2</tspan>O</text>
</svg>
svg {
  width: 300px;
  height: 160px;
  border: 1px solid #ddd;
  background: #fafbff;
}

text {
  font: 32px Georgia, serif;
  fill: #222;
}

.sup {
  baseline-shift: super;
  font-size: 18px;
  fill: #f72585;
}

.sub {
  baseline-shift: sub;
  font-size: 18px;
  fill: #4361ee;
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS baseline-shift property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee