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

  • Revision slug: Web/SVG/Element/textPath
  • Revision title: <textPath>
  • Revision id: 1120957
  • Created:
  • Creator: Sebastianz
  • Is current revision? No
  • Comment Updated browser compatibility information a bit

Revision Content

{{SVGRef}}

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 {{SVGAttr("href")}} attribute with a reference to a {{SVGElement("path")}} element.

Usage context

{{svginfo}}

Attributes

Global attributes

Specific attributes

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

DOM Interface

This element implements the {{domxref("SVGTextPathElement")}} interface.

Example

SVG

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

Result

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

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 Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatUnknown}}
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

Revision Source

<div>{{SVGRef}}</div>

<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 {{SVGAttr("href")}} attribute with a reference to a {{SVGElement("path")}} element.</p>

<h2 id="Usage_context">Usage context</h2>

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

<h2 id="Attributes">Attributes</h2>

<h3 id="Global_attributes">Global attributes</h3>

<ul>
 <li><a href="/en-US/docs/Web/SVG/Attribute#Conditional_processing_attributes" title="en/SVG/Attribute#ConditionalProccessing">Conditional processing attributes</a>&nbsp;»</li>
 <li><a href="/en-US/docs/Web/SVG/Attribute#Core_attributes" title="en/SVG/Attribute#Core">Core attributes</a>&nbsp;»</li>
 <li><a href="/en-US/docs/Web/SVG/Attribute#Graphical_event_attributes" title="en/SVG/Attribute#GraphicalEvent">Graphical event attributes</a>&nbsp;»</li>
 <li><a href="/en-US/docs/Web/SVG/Attribute#Presentation_attributes" title="en/SVG/Attribute#Presentation">Presentation attributes</a>&nbsp;»</li>
 <li><a href="/en-US/docs/Web/SVG/Attribute#Xlink_attributes" 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("href")}}</li>
</ul>

<h2 id="DOM_Interface">DOM&nbsp;Interface</h2>

<p>This element implements the {{domxref("SVGTextPathElement")}} interface.</p>

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

<h3>SVG</h3>

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

<h3>Result</h3>

<p>{{EmbedLiveSample("Example", 500, 175)}}</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>Edge</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</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>
Revert to this revision