#341·wtfjs

Character data interpreted in XHTML

Author: Patrick-ring-motiveCreated Aug 13, 2025Updated Feb 3, 2026
Labelsnew-example

script tags are interpreted as CDATA in typical html but in xhtml characters are interpreted using the standard syntax so for example, < and & are represented by &lt; and &amp;. You may think this is irrelevant in modern web because nobody uses xhtml but they do. Any time a script tag is nested inside an svg tag, it is interpreted as xhtml. See this example:

xml

<script type="module">
    const gt = 5;
    const test = 5 &gt; + 7;
    console.log(+test); // > 5
</script>
<svg>
  <script type="module">
    const gt = 5;
    const test = 5 &gt; + 7;
    console.log(+test); // > 0
  </script>
</svg>

In the first script test is set to 5 & gt which is 5 & 5 resulting in 5. In the second script &gt; is converted to > so test is set to 5 > +7 which is false. Then +test is coerced into 0.