Reputation: 75
I am currently drawing SVGs and I want to have a text element that contains a less than symbol. When I try:
<svg xmlns="http://www.w3.org/2000/svg">
<text x="40" y="40" fill="Black" font-size="25" font-weight="bold" font-family="courier new" ><</text>
</svg>
I get the following error: "StartTag: invalid element name"
Upvotes: 1
Views: 1581
Reputation: 4379
I usually refer to this page and you can also use the hex equivalent, eg <
translates to <
, which is Unicode U+003C.
Upvotes: 1
Reputation: 616
The <
and >
characters are special characters in HTML and SVG, used to denote tags, like <svg>
and <text>
. The renderer thinks you are trying to start a new tag when you use the <
in your code. This is why you're getting the error "StartTag: invalid element name"
To tell the renderer you want to print the <
character and not start a tag, you need to use an "escape code." In this case, the escape code you want is <
<svg xmlns="http://www.w3.org/2000/svg">
<text x="40" y="40" fill="Black" font-size="25" font-weight="bold" font-family="courier new" ><</text>
</svg>
Here's a jsFiddle demonstrating the use of that escape code.
There are many other escape codes you can use, too. They can be useful if your keyboard lacks a certain special character, like the British pound, or if you want to output special characters without affecting how your HTML or SVG is parsed by the renderer.
Upvotes: 7