Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

text-anchor — anchoring SVG text

The text-anchor property determines whether the start, middle, or end of an SVG text chunk aligns with its anchor point.

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

Syntax

text-anchor: start | middle | end;

text-anchor aligns each SVG text chunk relative to its initial position, usually established by x and y. Its initial value is start, and it is inherited.

For horizontal text with direction: ltr, start anchors the left-hand start, middle anchors the midpoint, and end anchors the right-hand end. With direction: rtl, the sides for start and end reverse. In vertical writing modes, alignment follows the text axis.

This is not a general replacement for text-align on HTML blocks. In the example, three rows share x="180"; the red line makes comparison easier. Anchoring uses text layout positions rather than the exact bounds of the visible letter shapes.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>text-anchor</title>
<style>
  text { font: 20px monospace; direction: ltr; }
  .start { text-anchor: start; }
  .middle { text-anchor: middle; }
  .end { text-anchor: end; }
</style>
<svg xmlns="http://www.w3.org/2000/svg" width="360" height="150" viewBox="0 0 360 150" role="img" aria-label="SVG text-anchor: start, middle, end">
  <path d="M180 10V140" stroke="red" />
  <text class="start" x="180" y="35">ABC</text>
  <text class="middle" x="180" y="80">ABC</text>
  <text class="end" x="180" y="125">ABC</text>
</svg>
</html>

Result

Three rows of ABC share the anchor x=180: the first extends right, the second is centered, and the third extends left. A red vertical line marks the anchor.

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