SVGBasics

Decorating Text with SVG - Italic, Subscript and Superscript

To get italic text in a tspan or text element, set the font-style to "italic" ( and back to "normal" when you're done). The "oblique" value is also available, but as far as I know, this is a synonym for italic.

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg viewBox = "0 0 500 300" version = "1.1">
    <desc>
        Text example
    </desc>
    <g fill = "navy">
        <text x = "10" y = "25" font-size = "20">
            <tspan x = "10" y = "20" font-style = "italic">
                Italic font-style.
            </tspan>
            <tspan x = "10" y = "80" font-style = "normal">
                Normal (not italic and not oblique) font-style.
            </tspan>
            <tspan x = "10" y = "140" font-style = "oblique">
                Oblique font-style.
            </tspan>
        </text>
    </g>
</svg>

Superscript and subscript are written by using the 'baseline-shift' attribute. Just set baseline-shift="super" or baseline-shift="sub" respectively.

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg viewBox = "0 0 500 300" version = "1.1">
    <desc>
        Text example
    </desc>
    <g fill = "navy">
        <text x = "10" y = "25" font-size = "20">
            <tspan>
                e = mc
                <tspan baseline-shift = "super">
                    2
                </tspan>
            </tspan>
            <tspan x = "10" y = "60">
                T
                <tspan baseline-shift = "sub">
                    i+2
                </tspan>
                =T
                <tspan baseline-shift = "sub">
                    i
                </tspan>
                + T
                <tspan baseline-shift = "sub">
                    i+1
                </tspan>
            </tspan>
        </text>
    </g>
</svg>
©2004 Late Night PC Service | About Us | Site Map | Contact Us