This page is In Progress

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

tspan

Overview Table

DOM Interface
SVGElement

Examples

In the following code example, text is modified with tSpan. Each letter has a specified x,y position. Copy this sample to a text file and save it with the .html file extension. Run it in Internet Explorer 9 to see the modified text.

The text will look like this:



<!DOCTYPE HTML>
<html>
  <head></head>
  <body>
    <svg width="400" height="400">
      <text fill="limegreen" font-size="20">
        <tSpan x="50" y="50 55 60 60 60 55 50 45 40 35 30 25 " >
                    SVG forever!</tSpan>
      </text>
    </svg>
  </body>
</html>

Notes

Remarks

Note: In addition to the attributes, properties, events, methods, and styles listed above, SVG elements also inherent core HTML attributes, properties, events, methods, and styles.

You can use the x, y, dx, dy, and rotate attributes on the tspan element in high-end typography scenarios where individual glyphs require exact placement. You can also use these attributes for minor positioning adjustments between characters or for major positioning adjustments, such as moving the current text position to a new location to achieve the visual effect of a new line of text.

You can create multi-line text elements by defining different tspan elements for each line of text, with x, y, dx, or dy attributes that define the position of each tspan element. This setup enables users to select multi-line text selection.

Standards information

Members

The SVGTSpanElement object has these events:

  • onload: Occurs when the browser has fully parsed the element and all of its descendants.

The SVGTSpanElement object has these methods:

  • getCharNumAtPosition: Gets the index of the character that the glyph cell bounding box contains at the specified point.
  • getComputedTextLength: Returns the total sum of all advance values from rendering all characters within the given text element.
  • getEndPositionOfChar: Gets the current text position of the specified character after the character is rendered in the user coordinate system where the glyphs that correspond to the specified character are rendered.
  • getExtentOfChar: Gets a rectangle that defines the minimum and maximum x-coordinate and y-coordinate values in the user coordinate system where the glyphs that correspond to the specified character are rendered.
  • getNumberOfChars: Gets the total number of characters that are available for rendering within the current element.
  • getRotationOfChar: Gets the rotation value of the specified character, relative to the current user coordinate system where the glyphs that corresponding to the specified character are rendered.
  • getStartPositionOfChar: Gets the current text position of the specified character before the character is rendered in the user coordinate system where the glyphs that correspond to the specified character are rendered.
  • getSubStringLength: Calculates the total sum of all advance values from rendering the specified substring of the characters.
  • hasExtension: Determines if the specified extension is supported.
  • selectSubString: Selects the specified substring, just as if a user selected the substring interactively.

The SVGTSpanElement object has these properties:

  • baselineShift: Sets or retrieves a value that indicates how the dominant baseline should be repositioned relative to the dominant baseline of the parent text content element.
  • className: Gets the names of the classes that are assigned to this object.
  • dominantBaseline: Sets or retrieves a value that determines or redetermines a scaled-baseline table.
  • dx: Gets the dx attribute on the given element.
  • dy: Gets the dy attribute on the given element.
  • externalResourcesRequired: Gets a value that indicates whether referenced resources that are not in the current document are required to correctly render a given element.
  • fill: Sets or retrieves a value that indicates the color to paint the interior of the given graphical element.
  • fillOpacity: Sets or retrieves a value that specifies the opacity of the painting operation that is used to paint the interior of the current object.
  • fillRule: Sets or retrieves a value that indicates the algorithm that is to be used to determine what parts of the canvas are included inside the shape.
  • focusable: Determines if an element can acquire keyboard focus (that is, receive keyboard events) and be a target for field-to-field navigation actions (such as when a user presses the Tab key).
  • glyphOrientationHorizontal: Sets or retrieves a value that alters the orientation of a sequence of characters relative to an inline-progression-direction of horizontal.
  • glyphOrientationVertical: Sets or retrieves a value that alters the orientation of a sequence of characters relative to an inline-progression-direction of vertical.
  • kerning: Gets or sets a value that indicates whether Internet Explorer should adjust inter-glyph spacing based on kerning tables that are included in the relevant font (that is, enable auto-kerning) or instead disable auto-kerning and set inter-character spacing to a specific length (typically zero).

Gets or sets a value that indicates whether Metro style app using JavaScript should adjust inter-glyph spacing based on kerning tables that are included in the relevant font (that is, enable auto-kerning) or instead disable auto-kerning and set inter-character spacing to a specific length (typically zero).

  • lengthAdjust: Gets or sets the lengthAdjust attribute on the given element.
  • ownerSVGElement: Gets the nearest ancestor svg element.
  • requiredExtensions: Gets a white space-delimited list of required language extensions.
  • requiredFeatures: Gets or sets a white space-delimited list of feature strings.
  • rotate: Gets or sets the supplemental character rotation about the current text position.
  • stroke: Sets or retrieves a value that indicates the color to paint along the outline of a given graphical element.
  • strokeDasharray: Sets or retrieves one or more values that indicate the pattern of dashes and gaps used to stroke paths.
  • strokeDashoffset: Sets or retrieves a value that specifies the distance into the dash pattern to start the dash.
  • strokeLinecap: Sets or retrieves a value that specifies the shape to be used at the end of open subpaths when they are stroked.
  • strokeLinejoin: Sets or retrieves a value that specifies the shape to be used at the corners of paths or basic shapes when they are stroked.
  • strokeMiterlimit: Sets or retrieves a value that indicates the limit on the ratio of the length of miter joins (as specified in the strokeLinejoin property).
  • strokeOpacity: Sets or retrieves a value that specifies the opacity of the painting operation that is used to stroke the current object.
  • strokeWidth: Sets or retrieves a value that specifies the width of the stroke on the current object.
  • style: Gets a style object.
  • systemLanguage: Gets or sets a comma-separated list of language names.
  • textLength: Gets or sets the textLength attribute on the given element.
  • viewportElement: Gets the element that established the current viewport.
  • x: Gets or sets the x-coordinate value.
  • xmlbase: Gets or sets the base attribute on the element.
  • xmllang: Gets or sets a value that specifies the language that is used in the contents and attribute values of an element.
  • xmlspace: Gets or sets a value that indicates whether white space is preserved in character data.
  • y: Gets or sets the y-coordinate value.

Attributions