<text>
Core element
Render vector text directly inside an SVG drawing.

SVG’s <text> lets you place real text inside vector graphics. This tutorial covers x and y, baseline behavior, text-anchor, font styling, fill and stroke, multiline labels with <tspan>, five worked examples, and how SVG text compares with HTML text and canvas text.
Core element
Render vector text directly inside an SVG drawing.
Position
Place text horizontally with x and vertically with the text baseline at y.
Alignment
Use start, middle, or end for left, center, or right alignment.
Style
Adjust font-size, font-family, fill, and stroke just like other vector shapes.
Multiline
Split a label into multiple lines or restyle parts of one text block.
Responsive
Keep text sharp and aligned as the SVG scales across screen sizes.
SVG’s <text> places readable words inside a vector drawing. It is useful for labels, badges, chart headings, icons with captions, buttons, diagrams, and any graphic where the text needs to stay sharp when scaled.
Unlike regular HTML text, SVG text lives inside the SVG coordinate system. That means you can line it up exactly with shapes, paths, and viewBox-based layouts while still styling it with fonts, fills, and strokes.
Many SVG graphics need labels that scale with the artwork. Learning <text> helps you build crisp chart labels, callouts, logos, badges, and UI illustrations without switching to bitmap images.
Text stays crisp and can still be selected or styled as SVG content.
y controls the baseline, which is the most important beginner detail.
text-anchor makes left, centered, and right-aligned labels easy.
Break lines or highlight parts of a sentence without leaving SVG.
In short: place the text with x and y, align it with text-anchor, then style it with fonts, fill, and stroke.
Basic form of the SVG text element:
<svg width="240" height="120">
<text x="40" y="70">Hello SVG</text>
</svg> | Attribute | Type | Description |
|---|---|---|
x | Length / number | Horizontal starting position of the text. |
y | Length / number | Vertical baseline position of the text. |
text-anchor | Keyword | start, middle, or end horizontal alignment. |
font-size | Length / number | Controls the rendered text size. |
font-family | Font list | Chooses which font face the browser should use. |
fill | Paint | Text fill color, gradient, pattern, or none. |
stroke | Paint | Outline color around the glyphs. |
stroke-width | Length / number | Thickness of the text outline. |
| Result | Details |
|---|---|
| vector text label | Renders scalable text positioned inside the SVG coordinate system. |
<svg width="240" height="120" viewBox="0 0 240 120">
<text x="120" y="68" text-anchor="middle"
font-family="system-ui, Arial, sans-serif"
font-size="24" fill="#0f172a">
Centered label
</text>
</svg> | Idea | Detail | Notes |
|---|---|---|
| Baseline | y sets the baseline | Not the top edge of the letters |
| Centering | text-anchor="middle" | Put x at the center point |
| Multiline | Use <tspan> | Great for stacked labels and captions |
| Goal | Code |
|---|---|
| Basic text | <text x="40" y="70">Hello</text> |
| Centered text | text-anchor="middle" x="120" |
| Styled text | font-size="24" font-family="Verdana" fill="#2563eb" |
| Outlined text | fill="white" stroke="#0f172a" stroke-width="1.5" |
| Multiline text | <tspan x="120" dy="0">Line 1</tspan> + dy="24" |
| Responsive SVG | <svg viewBox="0 0 240 120">... + CSS width |
textPathThey all render words, but each one fits a different job.
graphic labelsBest when text belongs inside a vector graphic and must scale with shapes.
document contentBest for normal paragraphs, headings, forms, and accessibility-first page content.
pixel drawingGood for dynamic drawing or games, but not as easy to inspect or align declaratively.
text on curvesUse when the text needs to follow a curved or custom path instead of a straight baseline.
<text>Reach for SVG text when the label is part of the graphic, not just the page layout.
Axis labels, values, legends, and annotation callouts.
Text centered inside SVG rectangles, pills, or icon buttons.
Useful when a graphic combines a symbol and a short caption in one SVG.
Place descriptive text exactly next to arrows, boxes, and connectors.
If the content is normal page copy, regular HTML text is usually the better choice.
Key benefit: SVG text scales with the drawing and stays perfectly aligned with the shapes around it.
Five starter snippets using <text>. Click View Output for a preview, or Try It Yourself to edit live.
Place one label, then center it inside the canvas.
Place a simple text label at a chosen x and y coordinate.
<svg width="260" height="120">
<text x="30" y="70" font-size="24" fill="#2563eb">
Hello, SVG!
</text>
</svg> The browser begins drawing the text at x="30" and uses y="70" as the text baseline. That baseline detail is why the letters sit a little above the y guide, not directly on top of it.
text-anchor="middle"Center a label by placing x at the middle of the canvas and using text-anchor="middle".
<svg width="280" height="120" viewBox="0 0 280 120">
<line x1="140" y1="16" x2="140" y2="104"
stroke="#cbd5e1" stroke-dasharray="6 6" />
<text x="140" y="68" text-anchor="middle"
font-size="26" fill="#0f172a">
Centered
</text>
</svg> With text-anchor="middle", the midpoint of the text is aligned to the given x coordinate. This is the simplest way to center a button label or chart title.
Text styling, outlining, and multiline labels.
font-size, font-family, and fillChange the font and color to make the text feel like a headline or badge label.
<svg width="320" height="130" viewBox="0 0 320 130">
<text x="24" y="78"
font-size="32"
font-family="Georgia, serif"
fill="#7c3aed">
Styled SVG Text
</text>
</svg> SVG text accepts familiar font properties. Because it is still SVG content, the text remains sharp and can sit next to paths, rectangles, gradients, or icons inside the same artwork.
strokeUse stroke and stroke-width to give text a bold outlined look.
<svg width="320" height="130" viewBox="0 0 320 130">
<rect x="20" y="24" width="280" height="82"
rx="16" fill="#111827" />
<text x="160" y="76" text-anchor="middle"
font-size="30"
font-family="system-ui, Arial, sans-serif"
fill="#f8fafc"
stroke="#38bdf8"
stroke-width="1.5"
paint-order="stroke">
OUTLINED
</text>
</svg> SVG applies the same paint model to text that it uses for shapes. paint-order="stroke" keeps the outline visually behind the fill so the letters stay readable.
tspanUse <tspan> to create stacked lines for badges, labels, or compact captions.
<svg width="300" height="150" viewBox="0 0 300 150">
<rect x="30" y="24" width="240" height="102"
rx="18" fill="#eff6ff" stroke="#60a5fa" />
<text x="150" y="68" text-anchor="middle"
font-family="system-ui, Arial, sans-serif"
fill="#1e3a8a">
<tspan x="150" dy="0" font-size="24" font-weight="700">SVG</tspan>
<tspan x="150" dy="26" font-size="18">Multiline Label</tspan>
</text>
</svg> Each <tspan> can reset x and shift downward with dy. This is the standard SVG way to create multiline labels when one line is not enough.
Real-world places where SVG text shows up every day.
Axes, values, legends, and annotations inside data graphics.
Example: value labels above bars in a chart.
Centered text inside capsules, CTA buttons, or alert badges.
Example: a "Start" button label in an SVG banner.
Name steps, arrows, nodes, and highlighted callouts.
Example: a process box labeled "Validate Input".
Short brand words or initials rendered as scalable vector text.
Example: a decorative heading inside an SVG hero image.
Compact notes near shapes, arrows, or highlighted regions.
Example: a two-line caption below an illustrated icon.
Geometry, flowcharts, and educational diagrams often need labels inside the SVG itself.
Example: naming points and lines in a math diagram.
Pro Tip: if the label must stay locked to the graphic while scaling, SVG text is usually a better fit than placing separate HTML text on top.
Why use SVG text inside graphics instead of converting text to images.
Text stays crisp on high-density screens and when the SVG scales up or down.
Position labels exactly relative to shapes, guides, and coordinates.
Use fill, stroke, gradients, and CSS-driven colors just like other SVG elements.
Simple labels often need only one <text> element instead of exported image assets.
Combine text with paths, rectangles, filters, and responsive viewBox layouts in one graphic.
Pro Tip: SVG text is especially useful when a label must scale with the surrounding shapes instead of floating separately in the page layout.
Follow these practices for clean, readable SVG text.
y is the baselineThis is the main positioning rule that explains why text may look lower than expected.
text-anchor="middle" for centered labelsIt is the easiest way to center button text or chart titles horizontally.
Fonts that exist on more devices give more predictable rendering.
Outlines can improve contrast, but heavy strokes can also reduce readability on small text.
tspan for multiline labelsThat keeps related text together while still allowing line-by-line control.
Pro Tip: when text sits on a shape, draw a light guide or temporary center line while building the SVG, then remove it after alignment looks right.
Avoid these mistakes when your SVG text does not appear or align correctly.
y like the top edgeText often looks too low because y sets the baseline, not the top.
→ Adjust the baseline thoughtfully or use alignment helpers.
fill="none" without a strokeThat makes the text invisible because nothing is painted.
→ Add a visible fill or use stroke and stroke-width.
If the coordinates are outside the visible area, the label will be clipped or disappear.
→ Keep the text anchor point and line spacing inside the canvas bounds.
An unavailable font can change the final size and spacing.
→ Use a sensible fallback stack such as system-ui, Arial, sans-serif.
SVG text is best for labels and short content, not large blocks of flowing article text.
→ Use HTML text for long-form content and SVG text for graphic labels.
Pro Tip: if text looks off, first check baseline placement, text-anchor, fill/stroke visibility, and whether the font size is large enough to read.
<text> Is DrawnThe characters inside <text>...</text> are the label the browser will render.
x and the baseline ySVG positions the text inside its coordinate system. y marks the baseline where the characters sit.
Use text-anchor, font-size, font-family, fill, and optional stroke.
tspan if you need more controlExtra lines or mixed styles usually come from nested <tspan> elements.
The browser renders the glyphs as vector content, so the label stays sharp and aligned inside the artwork.
<text> is real SVG content, not a bitmap label.y sets the text baseline, not the top of the letters.text-anchor values are start, middle, and end.fill and stroke like other SVG shapes.<tspan> instead of expecting HTML-style wrapping.Quick Takeaway: text content + baseline placement + alignment + font styling. Those four ideas cover most beginner SVG text work.
The SVG <text> element is supported in all modern browsers and has long been part of SVG 1.1. Core positioning, font styling, fill, and stroke are widely reliable.
Use
Bottom line: Safe for production sites. Basic SVG text is widely supported; test advanced typography and special fonts if your design depends on exact visual metrics.
SVG <text> gives you a clean way to place sharp, scalable labels directly inside vector graphics. Once you understand baseline positioning, text-anchor, and basic font styling, most common SVG text tasks become straightforward.
Practice the five examples above, then continue to SVG Stroke to learn how outlines, joins, caps, and paint behavior affect SVG graphics in more detail.
Remember the baseline, use text-anchor for alignment, and reach for tspan whenever one line is not enough.
y sets the baseline, not the toptext-anchor="middle" for centered labelstspan for multiline or mixed-style text blocksfill="none" without adding a visible stroke<text>Place and style vector text with confidence.
Core SVG text element
APIx + baseline y
Geometrytext-anchor matters
LayoutFonts, fill, and stroke
PaintHandles multiline text
StructureSVG text stays vector-sharp at any size and can use fill and stroke just like other SVG shapes. That is why SVG text is often used for badges, chart labels, and wordmarks that must stay clean on both small mobile screens and large retina displays.
Now learn how stroke width, caps, joins, and paint behavior affect text outlines and every other SVG shape.
8 people found this page helpful