mozilla

Revision 57704 of text

  • Revision slug: SVG/Element/text
  • Revision title: text
  • Revision id: 57704
  • Created:
  • Creator: rshetty
  • Is current revision? No
  • Comment one or more formatting changes

Revision Content

{{ SVGRefElem() }}

The text element defines a graphics element consisting of text. Note that it is possible to apply a gradient, pattern, clipping path, mask or filter to text

Usage context

Categories Graphics element, text content element
Permitted content Character data and any number of the following elements, in any order:
Animation elements »
Descriptive elements »
Text content child elements »
{{ SVGElement("a") }}
Normative document SVG 1.1 (2nd Edition)

Example

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="10cm" height="3cm" viewBox="0 0 1000 300"
     xmlns="http://www.w3.org/2000/svg" version="1.1">

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

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

The <text> element is used to draw text . The following code example is used for drawing a text with co-ordinates.

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <text x="10" y="20">SVG Text Example</text>
</svg>

SVG text can be rotated. The following code example illustrates it.

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <text x="10"  y="20" 
     transform="rotate(30 20,40)" 
     style="stroke:none; fill:#000000;">
       SVG Text Rotation example </text>
</svg>

SVG text can be styled

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
      <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("rotate") }}
  • {{ SVGAttr("textLength") }}
  • {{ SVGAttr("lengthAdjust") }}

DOM Interface

This element implements the SVGTextElement interface.

Browser compatibility

{{ CompatibilityTable() }}

{{ CompatTableHeader() }}
Basic support 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.

Related

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

Revision Source

<p>{{ SVGRefElem() }}</p>
<p>The <code>text</code> element defines a graphics element consisting of text. Note that it is possible to apply a gradient, pattern, clipping path, mask or filter to text</p>
<h2>Usage context</h2>
<table class="standard-table"> <tbody> <tr> <th scope="row">Categories</th> <td>Graphics element, text content 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#Animation" title="en/SVG/Attribute#Animation">Animation elements</a> »<br> <a href="/en/SVG/Element#Descriptive" title="en/SVG/Attribute#Descriptive">Descriptive elements</a> »<br> <a href="/en/SVG/Element#TextContentChild" title="en/SVG/Attribute#TextContentChild">Text content child elements</a> »<br> {{ SVGElement("a") }}</td> </tr> <tr> <th scope="row">Normative document</th> <td><a class="external" href="http://www.w3.org/TR/SVG/text.html#TextElement" title="http://www.w3.org/TR/SVG/text.html#TextElement">SVG 1.1 (2nd Edition)</a></td> </tr> </tbody>
</table>
<h2>Example</h2>
<pre class="brush: xml">&lt;?xml version="1.0" standalone="no"?&gt;
&lt;!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"&gt;
&lt;svg width="10cm" height="3cm" viewBox="0 0 1000 300"
     xmlns="http://www.w3.org/2000/svg" version="1.1"&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 using 'rect' element --&gt;
  &lt;rect x="1" y="1" width="998" height="298"
        fill="none" stroke-width="2" /&gt;
&lt;/svg&gt;
</pre>
<p>The &lt;text&gt; element is used to draw text . The following code example is used for drawing a text with co-ordinates.</p>
<pre class="script-jem"><code>&lt;svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"&gt;
  &lt;text x="10" y="20"&gt;SVG Text Example&lt;/text&gt;
&lt;/svg&gt;</code>
</pre>
<p>SVG text can be rotated. The following code example illustrates it.</p>
<pre class="script-jem"><code>&lt;svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"&gt;
  &lt;text x="10"  y="20" 
     transform="rotate(30 20,40)" 
     style="stroke:none; fill:#000000;"&gt;
       SVG Text Rotation example &lt;/text&gt;
&lt;/svg&gt;</code>
</pre>
<p>SVG text can be styled</p>
<pre class="script-jem"><code>&lt;svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"&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;</code>
</pre>
<h2>Attributes</h2>
<h3>Global attributes</h3>
<ul> <li><a href="/en/SVG/Attribute#ConditionalProccessing" title="en/SVG/Attribute#ConditionalProccessing">Conditional processing attributes</a> »</li> <li><a href="/en/SVG/Attribute#Core" title="en/SVG/Attribute#Core">Core attributes</a> »</li> <li><a href="/en/SVG/Attribute#GraphicalEvent" title="en/SVG/Attribute#GraphicalEvent">Graphical event attributes</a> »</li> <li><a href="/en/SVG/Attribute#Presentation" title="en/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>Specific attributes</h3>
<ul> <li>{{ SVGAttr("x") }}</li> <li>{{ SVGAttr("y") }}</li> <li>{{ SVGAttr("dx") }}</li> <li>{{ SVGAttr("dy") }}</li> <li>{{ SVGAttr("rotate") }}</li> <li>{{ SVGAttr("textLength") }}</li> <li>{{ SVGAttr("lengthAdjust") }}</li>
</ul>
<h2>DOM Interface</h2>
<p>This element implements the <code><a href="/en/DOM/SVGTextElement" title="en/DOM/SVGTextElement">SVGTextElement</a></code> interface.</p>
<h2>Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">{{ CompatTableHeader() }} <table class="compat-table"> <tbody> <tr> <td>Basic support</td> <td>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 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/SVG/Compatibility_sources" title="en/SVG/Compatibility sources">these sources</a>.</p>
<h2>Related</h2>
<ul> <li>{{ SVGElement("tspan") }}</li> <li>{{ SVGElement("tref") }}</li> <li>{{ SVGElement("altGlyph") }}</li>
</ul>
Revert to this revision