Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 800919 of <textPath>

  • Revision slug: Web/SVG/Element/textPath
  • Revision title: textPath
  • Revision id: 800919
  • Created:
  • Creator: jswisher
  • Is current revision? No
  • Comment Revert to revision of 2013-12-06 05:59:19 by kscarfone: "sandbox"

Revision Content

{{ SVGRefElem() }}

In addition to text drawn in a straight line, SVG also includes the ability to place text along the shape of a {{ SVGElement("path") }} element. To specify that a block of text is to be rendered along the shape of a {{ SVGElement("path") }}, include the given text within a textPath element which includes an xlink:href attribute with a reference to a {{ SVGElement("path") }} element.

Usage context

Categories Text content element, Text content child element
Permitted content Character data and any number of the following elements, in any order:
Descriptive elements »
{{ SVGElement("a") }}, {{ SVGElement("altGlyph") }}, {{ SVGElement("animate") }}, {{ SVGElement("animateColor") }}, {{ SVGElement("set") }}, {{ SVGElement("tref") }}, {{ SVGElement("tspan") }}
Normative document SVG 1.1 (2nd Edition)

Example

<svg width="100%" height="100%" viewBox="0 0 1000 300"
     xmlns="https://www.w3.org/2000/svg" 
     xmlns:xlink="https://www.w3.org/1999/xlink">
  <defs>
    <path id="MyPath"
          d="M 100 200 
             C 200 100 300   0 400 100
             C 500 200 600 300 700 200
             C 800 100 900 100 900 100" />
  </defs>

  <use xlink:href="#MyPath" fill="none" stroke="red"  />

  <text font-family="Verdana" font-size="42.5">
    <textPath xlink:href="#MyPath">
      We go up, then we go down, then up again
    </textPath>
  </text>

  <!-- Show outline of the viewport using 'rect' element -->
  <rect x="1" y="1" width="998" height="298"
        fill="none" stroke="black" stroke-width="2" />
</svg>

Live result:

{{EmbedLiveSample("Example",500,175)}}

Attributes

Global attributes

Specific attributes

  • {{ SVGAttr("startOffset") }}
  • {{ SVGAttr("method") }}
  • {{ SVGAttr("spacing") }}
  • {{ SVGAttr("xlink:href") }}

DOM Interface

This element implements the SVGTextPathElement interface.

{{SVGRef}}

Revision Source

<p>{{ SVGRefElem() }}</p>
<p>In addition to text drawn in a straight line, SVG also includes the ability to place text along the shape of a {{ SVGElement("path") }} element. To specify that a block of text is to be rendered along the shape of a {{ SVGElement("path") }}, include the given text within a <code>textPath</code> element which includes an <code>xlink:href</code> attribute with a reference to a {{ SVGElement("path") }} element.</p>
<h2 id="Usage_context">Usage context</h2>
<table class="standard-table">
 <tbody>
  <tr>
   <th scope="row">Categories</th>
   <td>Text content element, Text content child element</td>
  </tr>
  <tr>
   <th scope="row">Permitted content</th>
   <td>Character data and any number of the following elements, in any order:<br />
    <a href="/en/SVG/Element#Descriptive" title="en/SVG/Attribute#Descriptive">Descriptive elements</a>&nbsp;»<br />
    {{ SVGElement("a") }}, {{ SVGElement("altGlyph") }}, {{ SVGElement("animate") }}, {{ SVGElement("animateColor") }}, {{ SVGElement("set") }}, {{ SVGElement("tref") }}, {{ SVGElement("tspan") }}</td>
  </tr>
  <tr>
   <th scope="row">Normative document</th>
   <td><a class="external" href="https://www.w3.org/TR/SVG/text.html#TextOnAPath" title="https://www.w3.org/TR/SVG/text.html#TextOnAPath">SVG 1.1 (2nd Edition)</a></td>
  </tr>
 </tbody>
</table>
<h2 id="Example">Example</h2>
<pre class="brush: html">
&lt;svg width="100%" height="100%" viewBox="0 0 1000 300"
     xmlns="https://www.w3.org/2000/svg" 
     xmlns:xlink="https://www.w3.org/1999/xlink"&gt;
  &lt;defs&gt;
    &lt;path id="MyPath"
          d="M 100 200 
             C 200 100 300   0 400 100
             C 500 200 600 300 700 200
             C 800 100 900 100 900 100" /&gt;
  &lt;/defs&gt;

  &lt;use xlink:href="#MyPath" fill="none" stroke="red"  /&gt;

 &nbsp;&lt;text font-family="Verdana" font-size="42.5"&gt;
    &lt;textPath xlink:href="#MyPath"&gt;
      We go up, then we go down, then up again
    &lt;/textPath&gt;
  &lt;/text&gt;

  &lt;!-- Show outline of the viewport using 'rect' element --&gt;
  &lt;rect x="1" y="1" width="998" height="298"
        fill="none" stroke="black" stroke-width="2" /&gt;
&lt;/svg&gt;
</pre>
<p>Live result:</p>
<p>{{EmbedLiveSample("Example",500,175)}}</p>
<h2 id="Attributes">Attributes</h2>
<h3 id="Global_attributes">Global attributes</h3>
<ul>
 <li><a href="/en/SVG/Attribute#ConditionalProccessing" title="en/SVG/Attribute#ConditionalProccessing">Conditional processing attributes</a>&nbsp;»</li>
 <li><a href="/en/SVG/Attribute#Core" title="en/SVG/Attribute#Core">Core attributes</a>&nbsp;»</li>
 <li><a href="/en/SVG/Attribute#GraphicalEvent" title="en/SVG/Attribute#GraphicalEvent">Graphical event attributes</a>&nbsp;»</li>
 <li><a href="/en/SVG/Attribute#Presentation" title="en/SVG/Attribute#Presentation">Presentation attributes</a>&nbsp;»</li>
 <li><a href="/en/SVG/Attribute#XLink" title="en/SVG/Attribute#XLink">Xlink attributes</a>&nbsp;»</li>
 <li>{{ SVGAttr("class") }}</li>
 <li>{{ SVGAttr("style") }}</li>
 <li>{{ SVGAttr("externalResourcesRequired") }}</li>
</ul>
<h3 id="Specific_attributes">Specific attributes</h3>
<ul>
 <li>{{ SVGAttr("startOffset") }}</li>
 <li>{{ SVGAttr("method") }}</li>
 <li>{{ SVGAttr("spacing") }}</li>
 <li>{{ SVGAttr("xlink:href") }}</li>
</ul>
<h2 id="DOM.C2.A0Interface">DOM&nbsp;Interface</h2>
<p>This element implements the <code><a href="/en/DOM/SVGTextPathElement" title="en/DOM/SVGTextPathElement">SVGTextPathElement</a></code> interface.</p>
<p>{{SVGRef}}</p>
Revert to this revision