Home > other >  Why are svg tagNames lowercase and non-svg uppercase?
Why are svg tagNames lowercase and non-svg uppercase?

Time:01-27

Why is one lowercase and the other uppercase ?

console.log("standard :", document.getElementById('link').tagName)  // A

console.log("svg : ", document.getElementById('SvgLink').tagName)  // a
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100" style="background: peachpuff;">
    <a id="SvgLink" href="http://perdu.com">
        <circle  cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red"></circle>
    </a>
</svg>

<a id="link" href="http://perdu.com">Link</a>

CodePudding user response:

SVG's original format was XML only. XML is case sensitive. Some of that case sensitivity remains for compatibility reasons when SVG is embedded within HTML documents.

See DOM level 2 core description of tagName

...Note that this is case-preserving in XML, as are all of the operations of the DOM...

  • Related