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 1089621 of <textPath>

  • Revision slug: Web/SVG/Element/textPath
  • Revision title: <textPath>
  • Revision id: 1089621
  • Created:
  • Creator: Tigt
  • Is current revision? No
  • Comment remove redundant attributes

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

{{svginfo}}

Example

<svg 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.

Specifications

Specification Status Comment
{{SpecName('SVG2', 'text.html#TextPathElement', '<textPath>')}} {{Spec2('SVG2')}}  
{{SpecName('SVG1.1', 'text.html#TextPathElement', '<textPath>')}} {{Spec2('SVG1.1')}} Initial definition

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

{{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>

<p>{{svginfo}}</p>

<h2 id="Example">Example</h2>

<pre class="brush: html">
&lt;svg 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_Interface">DOM&nbsp;Interface</h2>

<p>This element implements the <code><a href="/en/DOM/SVGTextPathElement" title="en/DOM/SVGTextPathElement">SVGTextPathElement</a></code> interface.</p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('SVG2', 'text.html#TextPathElement', '&lt;textPath&gt;')}}</td>
   <td>{{Spec2('SVG2')}}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('SVG1.1', 'text.html#TextPathElement', '&lt;textPath&gt;')}}</td>
   <td>{{Spec2('SVG1.1')}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE&nbsp;Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>{{SVGRef}}</p>
Revert to this revision