22

So I'm trying to make a simple textpath .svg that would be a vertical line with some text. The problem I am getting is that the <defs> tags seem to throw everything off. I think it has something to do with my xlink:href but I can't seem to pin down what exactly.

<svg version="1.1"
     baseProfile="full"
     width="20" height="600"
     xmlns="http://www.w3.org/2000/svg">
     
   <defs>
          <path id="testPath" d="M 10 10 L 10 600 z"
         stroke="black" stroke-width="3" />
   </defs>
   
   <text>
      <textpath xlink:href="#testPath">
         teeeest
      </textpath>
   </text>
   
</svg>

Any help would be appreciated.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Athlos
  • 231
  • 1
  • 2
  • 3
  • And for some reason it works absolutely fine in the code editor here and not actually out in a web browser. =( – Athlos Apr 26 '15 at 23:39
  • "the tags seem to throw everything off" is vague. I see the text in a vertical path in your demo. What is the desired behavior? What have you tried? – jmargolisvt Apr 27 '15 at 02:04

2 Answers2

27

Your sample will work fine inlined in a browser, because the browser knows about the xlink namespace.

If your SVG is an external file, then more strict XML parsing is performed and all namespaces used have to be defined.

All you need to do is add a definition for the xlink namespace to your outermost <svg> element.

<svg version="1.1"
    baseProfile="full"
    width="20" height="600"
    xmlns="http://www.w3.org/2000/svg"
    xmlns:xlink="http://www.w3.org/1999/xlink">
Paul LeBeau
  • 97,474
  • 9
  • 154
  • 181
27

SVG is a case sensitive language so textpath actually needs to be written as textPath.

If you embed the SVG in html then you don't need namespaces as html doesn't support them (unlike xhtml). If you have your SVG standalone you'll also need xmlns:xlink="http://www.w3.org/1999/xlink" on the root <svg> element.

Robert Longson
  • 118,664
  • 26
  • 252
  • 242