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 1035118 of <text>

  • Revision slug: Web/SVG/Element/text
  • Revision title: <text>
  • Revision id: 1035118
  • Created:
  • Creator: Tigt
  • Is current revision? No
  • Comment

Revision Content

{{SVGRefElem}}

The SVG text element defines a graphics element consisting of text. It's possible to apply a gradient, pattern, clipping path, mask, or filter to <text>, just like any other SVG graphics element.

If text is included within SVG not inside of a <text> element, it is not rendered. This is different from being hidden by default, as setting the display property will not show the text.

Usage context

{{svginfo}}

Example

<svg xmlns="https://www.w3.org/2000/svg"
     width="100" height="30" viewBox="0 0 1000 300">

  <text x="250" y="150" 
        font-family="Verdana" 
        font-size="55">
    Hello, out there
  </text>

  <!-- Show outline of canvas with a 'rect' element -->
  <rect x="1" y="1" width="998" height="298"
        fill="none" stroke-width="2" />
</svg>

SVG text can be rotated, like so:

<svg xmlns="https://www.w3.org/2000/svg" width="100" height="50">
  <text x="10" y="20" 
        transform="rotate(30 20,40)">
    SVG Text Rotation example
  </text>
</svg>

SVG text can be styled like HTML text:

<svg xmlns="https://www.w3.org/2000/svg" width="100" height="50">
  <text x="10" y="20"
        style="font-family: Times New Roman;
               font-size: 24;
               stroke: #00ff00;
               fill: #0000ff;">
    SVG text styling
  </text>
</svg>

Attributes

Global attributes

Specific attributes

  • {{SVGAttr("x")}}
  • {{SVGAttr("y")}}
  • {{SVGAttr("dx")}}
  • {{SVGAttr("dy")}}
  • {{SVGAttr("text-anchor")}}
  • {{SVGAttr("rotate")}}
  • {{SVGAttr("textLength")}}
  • {{SVGAttr("lengthAdjust")}}

DOM Interface

This element implements the SVGTextElement interface.

Specifications

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

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) IE Opera Safari
Basic support {{CompatChrome('1.0')}} {{CompatGeckoDesktop('1.8')}} {{CompatIE('9.0')}} {{CompatOpera('8.0')}} {{CompatSafari('3.0.4')}}
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{CompatAndroid('3.0')}} {{CompatGeckoMobile('1.8')}} {{CompatNo}} {{CompatVersionUnknown}} {{CompatSafari('3.0.4')}}

The chart is based on these sources.

  • {{SVGElement("tspan")}}
  • {{SVGElement("tref")}}
  • {{SVGElement("altGlyph")}}

{{SVGRef}}

Revision Source

<p>{{SVGRefElem}}</p>

<p><span class="seoSummary">The SVG <strong><code>text</code></strong> element defines a graphics element consisting of text. It's possible to apply a gradient, pattern, clipping path, mask, or filter to <code>&lt;text&gt;</code>, just like any other SVG graphics element.</span></p>

<p>If text is included within SVG not inside of a <code>&lt;text&gt;</code> element, it is not rendered. This is different from being hidden by default, as setting <a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/display">the display property</a> will not show the text.</p>

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

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

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

<pre class="brush: xml">
&lt;svg xmlns="https://www.w3.org/2000/svg"
     width="100" height="30" viewBox="0 0 1000 300"&gt;

  &lt;text x="250" y="150" 
        font-family="Verdana" 
        font-size="55"&gt;
    Hello, out there
  &lt;/text&gt;

  &lt;!-- Show outline of canvas with a 'rect' element --&gt;
  &lt;rect x="1" y="1" width="998" height="298"
        fill="none" stroke-width="2" /&gt;
&lt;/svg&gt;
</pre>

<p>SVG text can be rotated, like so:</p>

<pre class="brush: xml">
&lt;svg xmlns="https://www.w3.org/2000/svg" width="100" height="50"&gt;
  &lt;text x="10" y="20" 
        transform="rotate(30 20,40)"&gt;
    SVG Text Rotation example
  &lt;/text&gt;
&lt;/svg&gt;
</pre>

<p>SVG text can be styled like HTML text:</p>

<pre class="brush: xml">
&lt;svg xmlns="https://www.w3.org/2000/svg" width="100" height="50"&gt;
  &lt;text x="10" y="20"
        style="font-family: Times New Roman;
               font-size: 24;
               stroke: #00ff00;
               fill: #0000ff;"&gt;
    SVG text styling
  &lt;/text&gt;
&lt;/svg&gt;
</pre>

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

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

<ul>
 <li><a href="/en-US/docs/Web/SVG/Attribute#ConditionalProccessing">Conditional processing attributes</a> »</li>
 <li><a href="/en-US/docs/Web/SVG/Attribute#Core">Core attributes</a> »</li>
 <li><a href="/en-US/docs/Web/SVG/Attribute#GraphicalEvent">Graphical event attributes</a> »</li>
 <li><a href="/en-US/docs/Web/SVG/Attribute#Presentation">Presentation attributes</a> »</li>
 <li>{{SVGAttr("class")}}</li>
 <li>{{SVGAttr("style")}}</li>
 <li>{{SVGAttr("externalResourcesRequired")}}</li>
 <li>{{SVGAttr("transform")}}</li>
</ul>

<h3 id="Specific_attributes">Specific attributes</h3>

<ul>
 <li>{{SVGAttr("x")}}</li>
 <li>{{SVGAttr("y")}}</li>
 <li>{{SVGAttr("dx")}}</li>
 <li>{{SVGAttr("dy")}}</li>
 <li>{{SVGAttr("text-anchor")}}</li>
 <li>{{SVGAttr("rotate")}}</li>
 <li>{{SVGAttr("textLength")}}</li>
 <li>{{SVGAttr("lengthAdjust")}}</li>
</ul>

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

<p>This element implements the <code><a href="/en-US/docs/Web/API/SVGTextElement">SVGTextElement</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#TextElement', '&lt;text&gt;')}}</td>
   <td>{{Spec2('SVG2')}}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('SVG1.1', 'text.html#TextElement', '&lt;text&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>IE</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatChrome('1.0')}}</td>
   <td>{{CompatGeckoDesktop('1.8')}}</td>
   <td>{{CompatIE('9.0')}}</td>
   <td>{{CompatOpera('8.0')}}</td>
   <td>{{CompatSafari('3.0.4')}}</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>{{CompatAndroid('3.0')}}</td>
   <td>{{CompatGeckoMobile('1.8')}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatSafari('3.0.4')}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>The chart is based on <a href="/en-US/docs/Web/SVG/Compatibility_sources">these sources</a>.</p>

<h2 id="Related">Related</h2>

<ul>
 <li>{{SVGElement("tspan")}}</li>
 <li>{{SVGElement("tref")}}</li>
 <li>{{SVGElement("altGlyph")}}</li>
</ul>

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