The SVG <text> element draws a text label inside an <svg>. Position it with x and y, align with text-anchor, and style with font-size, fill, and optional stroke.
Use nested <tspan> for a second line or mixed styles. SVG text stays sharp at any scale — ideal for chart labels and icons.
Baseline · Widely available.
<text> is a stable SVG text-content element across modern browsers since about July 2015.
Paint with fill, not color.
In SVG, text colour comes from fill (and stroke). The HTML/CSS color property does not paint SVG text the same way.
No wrap by default.
Long strings stay on one line unless you use <tspan> lines or CSS white-space wrapping. Text not inside <text> is not rendered.
Most missing-text bugs are baseline position, paint, or missing <text>.
baseline
y is the baseline
Letters hang mostly above y. A small y can clip the top of the glyphs.
wrap
No automatic wrapping
Long strings stay on one line. Use <tspan> lines or CSS wrapping when you need breaks.
paint
Use fill, not color
SVG text is painted with fill/stroke. Setting only CSS color often leaves text looking wrong or invisible.
a11y
Label meaningful graphics
Visible <text> can help, but decorative SVGs still need role="img" and an accessible name when appropriate.
Compatibility
Browser Support
The SVG <text> element is supported in every modern browser.
✓ Baseline · Widely available
SVG <text>
Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support text, tspan, text-anchor, and fill/stroke styling. Internet Explorer 9+ supports basic SVG text.
98%Global support (approx.)
Google ChromeAll modern
Full support
Mozilla FirefoxAll modern
Full support
Apple SafariAll modern
Full support
Microsoft EdgeAll modern
Full support
OperaAll modern
Full support
Samsung InternetAll modern
Full support
Internet Explorer9+
Supported
<text>Widely supported
Bottom line: Safe for production chart labels, badges, and icon captions. Prefer SVG text for graphic labels; use HTML for long readable page copy.
Remember
Key Takeaways
Position:x, baseline y.
Align:text-anchor (start / middle / end).
Paint:fill (and optional stroke).
Lines / style: nest <tspan>.
One line:<text x y> + fill / font-size inside an <svg>.
UA style
Default CSS Settings
Conceptual defaults for SVG text:
defaults.css
/* Conceptual SVG text defaults */
text {
fill: black; /* not CSS color */
stroke: none;
font-size: medium;
text-anchor: start;
white-space: nowrap; /* no wrap by default */
}
Set font-family, font-size, and fill explicitly in examples so results stay predictable.
Frequently Asked Questions
Use a <text> element inside <svg>. Set x and y for position, then style with font-size, font-family, and fill.
x is the horizontal position. y is the text baseline (not the top of the letters), so text can look a bit lower than beginners expect.
Set text-anchor="middle" and place x at the center point. For vertical centering, also use a suitable y or dominant-baseline.
Yes. Use stroke and stroke-width like shapes. You can combine fill and stroke, or use fill="none" for outline-only text.
Common causes: text outside a <text> element, coordinates outside the viewBox, fill none with no stroke, or a tiny font-size.
Use <tspan> for a second line (with dy) or differently styled words inside one <text>. Use HTML text for long page copy.